Code:
disablePermissionChecks();
setNotifyOnException(false);
setAdvancedAlert(true);
// Proxylist updates for hosters (e.g. Zippyshare.com)
// Trigger: Interval (e.g. 10000ms)
var refreshtime = "900"; // (e.g. 900s)
var myCountries = ["GB", "DE", "FR"]; //Filterlist for countries
var myPorts = [2333, 10174]; //Proxy port blacklist (Added by mgpai)
var max_response_time = 2; //1.5 or higher (e.g. 2), 1 is too low
var proxy_test = 0; //1=ON,0=OFF (very slow)
var max_proxies = 0; //0=Unlimited
var standard_filter = " \"filter\" : {\"type\" : \"WHITELIST\",\"entries\" : [ \"hoster 1\", \"hoster 2\"]},"; //\"filter\" : null,
var add_proxy = JSON.parse("{\"proxy\" : {\"username\" : null,\"password\" : null,\"port\" : 80,\"address\" : null,\"type\" : \"NONE\",\"preferNativeImplementation\" : false,\"resolveHostName\" : false,\"connectMethodPrefered\" : false},\"rangeRequestsSupported\" : true," + standard_filter + "\"pac\" : false,\"reconnectSupported\" : false,\"enabled\" : true}");
var filter = new Array();
var old_proxylist = [];
var new_proxylist = "";
var settings = "org.jdownloader.updatev2.InternetConnectionSettings";
var storage = "cfg/org.jdownloader.settings.InternetConnectionSettings";
old_proxylist = callAPI("config", "get", settings, storage, "customproxylist");
if (IsValidname() || IsValidinterval() && ((Math.round(Date.now() / 1000) - getProperty("LastProxyUpdate", true)) >= refreshtime) && !getProperty("updatingProxy", true) || getProperty("updatingProxy", true)) {
if (!getProperty("updatingProxy", true)) {
setProperty("LastProxyUpdate", Math.round(Date.now() / 1000), true);
} else {
if (getProperty("updatingProxy", true)) {
setProperty("updatingProxy", false, true);
}
}
var html;
try {
html = getPage("https" + "://raw.githubusercontent.com/fate0/proxylist/master/proxy.list");
var lines = html.split("\n");
for (var key in old_proxylist) {
if (old_proxylist.hasOwnProperty(key)) {
if (old_proxylist[key].proxy.type == "DIRECT" || old_proxylist[key].proxy.type == "NONE" || old_proxylist[key].enabled == false) {
if (new_proxylist == "") {
new_proxylist += JSON.stringify(old_proxylist[key]);
} else {
new_proxylist += "," + JSON.stringify(old_proxylist[key]);
}
}
}
}
var myBr = getBrowser();
for (var i = 0; i < lines.length; ++i) {
if (IsValidJSONString(lines[i])) {
var temp_JSON = JSON.parse(lines[i]);
var add_proxy_new = add_proxy;
add_proxy_new.proxy.type = temp_JSON.type.toUpperCase();
add_proxy_new.proxy.port = temp_JSON.port;
add_proxy_new.proxy.address = temp_JSON.host;
if (myCountries.indexOf(temp_JSON.country) > -1 || temp_JSON.response_time > max_response_time || myPorts.indexOf(temp_JSON.port) > -1) { // myPorts.indexOf(temp_JSON.port) > -1 (added by mgpsi)
continue; //skip proxy
}
var errorcheck = 0;
if (proxy_test == 1) {
myBr.setProxy(temp_JSON.type + "://" + temp_JSON.host + ":" + temp_JSON.port);
try {
myBr.getPage("http://www.google.de/");
} catch (e) {
errorcheck = 1;
}
}
if (errorcheck == 0 && proxy_test == 1 || proxy_test != 1) {
if (add_proxy_new.proxy.address && filter[temp_JSON.host] != true) {
filter[temp_JSON.host] = true;
if (new_proxylist == "") {
new_proxylist += JSON.stringify(add_proxy_new);
} else {
new_proxylist += "," + JSON.stringify(add_proxy_new);
}
}
}
}
if (i >= max_proxies && max_proxies > 0) {
break;
}
}
callAPI("config", "set", settings, storage, "customproxylist", "[" + new_proxylist + "]");
} catch (e) {}
}
function IsValidJSONString(str) {
if (typeof str !== "string") {
return false;
}
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
function IsValidname() {
try {
if (name == "Geoblocking: zippy") {
return true;
}
} catch (e) {
return false;
}
return true;
}
function IsValidinterval() {
try {
if (interval >= 10000) {
return true;
}
} catch (e) {
return false;
}
return true;
}