Implement support for some URL proxies

This commit is contained in:
Les De Ridder 2016-07-11 00:15:26 +02:00
parent 643d5b274c
commit cb9043f36f
1 changed files with 37 additions and 1 deletions

View File

@ -34,7 +34,9 @@ var blacklist = ["pomf.", "mixtape.moe", "catgirlsare.sexy", "p.fuwafuwa.moe", "
chrome.pageAction.onClicked.addListener(function(tab) {
getCurrentTabUrl(function(url) {
getBetterUrl(url, function(betterUrl) {
var filename = betterUrl.substr(betterUrl.lastIndexOf("/"));
filenameUrl = getProxiedUrl(betterUrl) || betterUrl;
var filename = filenameUrl.substr(filenameUrl.lastIndexOf("/"));
filename = cleanExtension(filename);
if(filename.indexOf('.') == -1) {
@ -195,6 +197,35 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
["blocking", "requestHeaders"]
);
function getQueryObject(url) {
var queryString = url.substring(url.indexOf('?') + 1);
var split = queryString.split('&');
var query = {};
for(var pair of split)
{
if(pair.indexOf('=') != -1) {
var keyValue = /(.*)=(.*)/.exec(pair);
query[keyValue[1]] = decodeURIComponent(keyValue[2]);
} else {
query[pair] = null;
}
}
return query;
}
function getProxiedUrl(url) {
var query = getQueryObject(url);
for(var key in query) {
if(query[key] != null && query[key].indexOf('http') != -1) { //HACK: Use a regex
return query[key];
}
}
return null;
}
function cleanExtension(url) {
var trailingStrings = ["?", ":orig", ":large", ":small", ":thumb", ":medium"];
@ -228,6 +259,11 @@ function isGfycatUrl(url) {
}
function isCoolUrl(url, callback) {
var proxiedUrl = getProxiedUrl(url);
if(proxiedUrl != null) {
url = proxiedUrl;
}
url = url.toLowerCase();
var extensionIndex = url.lastIndexOf('.');