Skip to content

Commit

Permalink
Fixed loading translations
Browse files Browse the repository at this point in the history
  • Loading branch information
mozlima committed Dec 10, 2015
1 parent a6002ee commit 4e857f4
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 298 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Useful to avoid frame pages (e.g., Google images, Yahoo, Bing...) , ads, surveys

* Extract links recursively (every URL found are added to a pop-up overlay while hovering the link to let the user choose the best option in a fast way).

* Decode obfuscated links as "reverse", base64 and hex. (tricks used by some sites to prevent direct access to the original web address).
* Decode obfuscated links as "reverse", base64 and hex (tricks used by some sites to prevent direct access to the original web address).

* Extract web addresses within tag's attributes (e.g. onclick, onmouseover...), text contents and JavaScript: protocol (mostly used to open pop-ups or to show overlays).

Expand Down
26 changes: 10 additions & 16 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,20 @@
"openInNewPage2": {
"message": "Open in background tab"
},
"replaceTargetUrl0": {
"message": "0: Use only menu"
"menuEnable": {
"message": "Enable menu"
},
"replaceTargetUrl1": {
"message": "1: Always show menu and replace URL of the link"
"menuHideIfSingleRedir": {
"message": "Hide the menu if the URL has a single redirect"
},
"replaceTargetUrl2": {
"message": "2: Always show menu and replace URL if link has only one redirect"
"replaceUrl": {
"message": "Replace URL of the link"
},
"replaceTargetUrl3": {
"message": "3: Show menu if link has more than one redirect and always replace URL of the link"
"replaceOnlySingleRedir": {
"message": "Only if the URL has a single redirect"
},
"replaceTargetUrl4": {
"message": "4: Show menu if link has more than one redirect and replace URL if link has only one redirect"
},
"useFallbackRule0": {
"message": "Replace URL only by rules"
},
"useFallbackRule1": {
"message": "Replace URL by rules and use an alternate fallback method if no rules is set"
"useFallbackRule": {
"message": "Use an alternate fallback method if no rules is set for the link"
},
"Manage_rules": {
"message": "Manage rules"
Expand Down
26 changes: 10 additions & 16 deletions src/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,20 @@
"openInNewPage2": {
"message": "Abrir em segundo plano"
},
"replaceTargetUrl0": {
"message": "0: Usar somente menu"
"menuEnable": {
"message": "Ativar menu"
},
"replaceTargetUrl1": {
"message": "1: Sempre usar menu e substituir URL do link"
"menuHideIfSingleRedir": {
"message": "Esconder o menu se o link tem apenas uma op\u00E7\u00E3o de redirecionamento"
},
"replaceTargetUrl2": {
"message": "2: Sempre usar menu e substituir URL do link se o link tem apenas uma op\u00E7\u00E3o de redirecionamento"
"replaceUrl": {
"message": "Substituir URL do link"
},
"replaceTargetUrl3": {
"message": "3: Usar menu se precisar e sempre substituir URL do link"
"replaceOnlySingleRedir": {
"message": "Somente se o link tem apenas uma op\u00E7\u00E3o de redirecionamento"
},
"replaceTargetUrl4": {
"message": "4: Usar menu se precisar e substituir URL do link se o link tem apenas uma op\u00E7\u00E3o de redirecionamento"
},
"useFallbackRule0": {
"message": "Somente por regras"
},
"useFallbackRule1": {
"message": "Regras e usar um plano alternativo quando n\u00E3o houver regras para um link"
"useFallbackRule": {
"message": "Usar um plano alternativo quando n\u00E3o houver regras para um link"
},
"Manage_rules": {
"message": "Configurar regras"
Expand Down
19 changes: 12 additions & 7 deletions src/background-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

var OPTS = {
/* background */
version : "2.1",
version : "2.1.1",
allowedProtocols : "http|https|ftp|magnet",
maxCaptureRecursion : 5,
excludedAttr : "href|style|codebase|pluginspage",
language : "auto",
useFallbackRule : 0,
useFallbackRule : true,
extOrder : "webm|mpg|avi|wmv|rm|rmvb|mp4|asf|flv|swf|mp3|wav|wma|mid|ogg|torrent|zip|rar|7z|exe|bat|reg|sh|bin|pdf|jpg|jpe|jpeg|gif|png|bmp|ico|svg|htm|html|asp|php",
/* content */
highlightLink : false,
openInNewPage : 0, /* 0:default, 1:new page, 2:background */
replaceTargetUrl : 0, /* menu|replace 0:force|disable 1:force|force 2:force|auto 3:auto|force 4:auto|auto */
menuEnable : true,
menuHideIfSingleRedir : false,
replaceUrl : false,
replaceOnlySingleRedir : true,
keysShowPopup : "",
keysOpenAsDownload : ((typeof Components == "undefined")? "U+0053" : "S"),
keysPreventReferrer : ((typeof Components == "undefined")? "U+0041" : "A"),
Expand Down Expand Up @@ -112,7 +115,9 @@ var rb = new function() {

[ "highlightLink",
"openInNewPage",
"replaceTargetUrl",
"menuEnable",
"menuHideIfSingleRedir",
"replaceUrl",
"keysShowPopup",
"keysOpenAsDownload",
"keysPreventReferrer",
Expand Down Expand Up @@ -267,13 +272,13 @@ var rb = new function() {
}
}



rb.sitesGetTop = function(links) {
if (!rb.REGEXPS.SITES_RULES_IGNORE.test(links.base.url)) {
var re = rb.REGEXPS.SITES_RULES_INDEX.exec(links.base.url);

if (re) {
var rules = rb.SITES_RULES[re.indexOf(re[0], 1) - 1];

if (rules) {
for (var j = 0, ll = rules[((rules[0].length > rules[1].length)? 0 : 1)].length; j < ll; j++) {
var rGroup = ((rules[0][j])? 0 : 1);
Expand Down Expand Up @@ -409,7 +414,7 @@ var rb = new function() {
links.list[links.base.url] = links.base;

} else if (!isPlugin && links.index.length) {
if (OPTS.replaceTargetUrl && (OPTS.replaceTargetUrl != 2 || OPTS.replaceTargetUrl != 4 || links.index.length == 1)) {
if (OPTS.replaceUrl && (!OPTS.replaceOnlySingleRedir || links.index.length == 1)) {
links.replaceURL = rb.sitesGetTop(links);

if (links.replaceURL) {
Expand Down
42 changes: 11 additions & 31 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"use strict";

//chrome.storage.local.clear();

(function() {
"use strict";
var siteruleFormData = {};

function runtimeOnMessage(msgData, msgSender, sendResponse) {
Expand Down Expand Up @@ -57,11 +54,9 @@ function runtimeOnMessage(msgData, msgSender, sendResponse) {
break;
case "siterules.addform.show":
siteruleFormData = msgData;

chrome.extension.getViews({type: "tab"}).forEach(function(win) {
win.close();
});

chrome.tabs.create({url: chrome.extension.getURL("siterules.html"), openerTabId: msgSender.tab.id, index: msgSender.tab.index + 1});
break;
case "notification.show":
Expand All @@ -75,13 +70,12 @@ function runtimeOnMessage(msgData, msgSender, sendResponse) {

function updateContentScript() {
var code = "if (typeof redirectBypasser != \"undefined\") {redirectBypasser.stop(); redirectBypasser.start({PAGE_DATA: " + JSON.stringify(rb.PAGE_DATA) + "});}";

chrome.tabs.query({url: ["https://*/*", "http://*/*", "file://*/*"]}, function(tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.executeScript(tabs[i].id, {code: code, allFrames: true, runAt: "document_start"}, function() {
tabs.forEach(function(tab) {
chrome.tabs.executeScript(tab.id, {code: code, allFrames: true, runAt: "document_start"}, function() {
if (!chrome.runtime.lastError) {}
});
}
});
});
}

Expand All @@ -96,28 +90,14 @@ function showNotification(scriptEnabled) {

chrome.runtime.onMessage.addListener(runtimeOnMessage);
chrome.storage.local.get(["opts", "sitesrules"], function(storageData) {
if (rb.optsBuild(storageData.opts)) {
chrome.storage.local.set({"opts": OPTS});
//chrome.tabs.create({"url": chrome.runtime.getManifest().homepage_url});
}

var code = "if (typeof redirectBypasser != \"undefined\") {redirectBypasser.stop(true); redirectBypasser = undefined;}";
rb.optsBuild(storageData.opts) && chrome.storage.local.set({"opts": OPTS});
rb.sitesBuildRules(storageData.sitesrules || rb.SITES_RULES_DEFAULT);
chrome.extension.isAllowedIncognitoAccess(function(isAllowedIncognitoAccess) {
chrome.extension.isAllowedFileSchemeAccess(function(isAllowedFileSchemeAccess) {
var code = "if (typeof redirectBypasser != \"undefined\") {redirectBypasser.stop(true); redirectBypasser = null;}";
var urls = ["https://*/*", "http://*/*"];
isAllowedFileSchemeAccess && urls.push("file://*/*");
//FIXME
chrome.tabs.query({url: urls}, function(tabs) {
tabs.forEach(function(tab) {
if (!tab.incognito || isAllowedIncognitoAccess) {
chrome.tabs.executeScript(tab.id, {code: code, allFrames: true, runAt: "document_idle"}, function() {
if (!chrome.runtime.lastError) {
chrome.tabs.executeScript(tab.id, {file: "/content-scripts/content.js", allFrames: true, runAt: "document_idle"});
}
});
}
});
chrome.tabs.query({url: ["https://*/*", "http://*/*", "file://*/*"]}, function(tabs) {
tabs.forEach(function(tab) {
chrome.tabs.executeScript(tab.id, {code: code, allFrames: true, runAt: "document_idle"}, function() {
if (!chrome.runtime.lastError) {}
chrome.tabs.executeScript(tab.id, {file: "/content-scripts/content.js", allFrames: true, runAt: "document_idle"}, function() {if (!chrome.runtime.lastError) {}});
});
});
});
Expand Down
90 changes: 31 additions & 59 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@ function startup(startupData, startupReason) {
var script = "";
var sandboxs = [];
var siteruleFormData = {};
var xhr = function(url, callback, type, responseType) {
var dx = new Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest")();
type && dx.overrideMimeType(type);
dx.open("GET", url, true);
dx.addEventListener("loadend", callback);
dx.responseType = ((responseType)? responseType : "");
dx.send();
};

xhr(URL.createObjectURL(new Blob(["<!DOCTYPE html><html><head><base href=\"http://www.example.com/\" target=\"_blank\"></head><body></body></html>"], {
type: "text/html"
})), function(ev) {
URL.revokeObjectURL(this.responseURL);
document = this.response;

xhr("chrome://redirectbypasser/content/content-scripts/content.js", function() {
script = this.responseText;
rb.optsBuild(storageGet("opts")) && storageSet("opts", OPTS);
rb.sitesBuildRules(storageGet("sitesrules") || rb.SITES_RULES_DEFAULT);
windowList(function(win) {
var i = win.frames.length;
windowProcess(win);

while (i--) {
windowProcess(win.frames[i]);
}
});
CC["@mozilla.org/observer-service;1"].getService(CI.nsIObserverService).addObserver(rb, "document-element-inserted", false);
}, "text/javascript", "");
}, "text/html", "document");

CC["@mozilla.org/moz/jssubscript-loader;1"].getService(CI.mozIJSSubScriptLoader).loadSubScript("chrome://redirectbypasser/content/background-common.js");

Expand All @@ -23,83 +53,30 @@ function startup(startupData, startupReason) {
CC["@mozilla.org/observer-service;1"].getService(CI.nsIObserverService).removeObserver(rb, "document-element-inserted", false);

var i = sandboxs.length;

while (i--) {
sandboxs[i].window.removeEventListener("unload", windowOnUnload, false);
CU.evalInSandbox("if (typeof redirectBypasser != \"undefined\") {redirectBypasser.stop(true);}", sandboxs[i]);
CU.nukeSandbox(sandboxs[i]);
}

script = null;
sandboxs = null;
siteruleFormData = null;
document = null;
OPTS = null;
sandboxs.length = 0;

windowList(function(win) {
(win.location.href.indexOf("chrome://redirectbypasser/content/") === 0) && win.close();
});
};

(function() {
var xhr = function(url, callback, type, responseType) {
var dx = new Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest")();
type && dx.overrideMimeType(type);
dx.open("GET", url, true);
dx.addEventListener("loadend", callback);
dx.responseType = ((responseType)? responseType : "");
dx.send();
};

!document && xhr(URL.createObjectURL(new Blob(["<!DOCTYPE html><html><head><base href=\"http://www.example.com/\" target=\"_blank\"></head><body></body></html>"], {
type: "text/html"
})), function(ev) {
URL.revokeObjectURL(this.responseURL);
document = this.response;
}, "text/html", "document");

xhr("chrome://redirectbypasser/content/content-scripts/content.js", function() {
script = this.responseText;

if (rb.optsBuild(storageGet("opts"))) {
storageSet("opts", OPTS);

/*var timer = CC["@mozilla.org/timer;1"].createInstance(CI.nsITimer);
timer.initWithCallback(function() {
windowOpen({url: "http://moisesplima.blogspot.com.br/redirect-bypasser"});
}, 60000, CI.nsITimer.TYPE_ONE_SHOT);*/
}

rb.sitesBuildRules(storageGet("sitesrules") || rb.SITES_RULES_DEFAULT);
windowList(function(win) {
var i = win.frames.length;
windowProcess(win);

while (i--) {
windowProcess(win.frames[i]);
}
});
CC["@mozilla.org/observer-service;1"].getService(CI.nsIObserverService).addObserver(rb, "document-element-inserted", false);

}, "text/javascript", "");
})();

//FIXME:
function windowList(callback) {
var wins = CC["@mozilla.org/appshell/window-mediator;1"].getService(CI.nsIWindowMediator).getEnumerator("navigator:browser");

while (wins.hasMoreElements()) {
var win = wins.getNext().QueryInterface(CI.nsIDOMWindow);

if ("gBrowser" in win) {
var i = (("browsers" in win.gBrowser)? win.gBrowser.browsers.length : 0);

while (i--) {
callback(win.gBrowser.getBrowserAtIndex(i).contentDocument.defaultView, win);
}
} else if ("BrowserApp" in win) {
var i = (("tabs" in win.BrowserApp)? win.BrowserApp.tabs.length : 0);

while (i--) {
callback(win.BrowserApp.tabs[i].window, win);
}
Expand All @@ -109,10 +86,8 @@ function startup(startupData, startupReason) {

function windowOpen(params) {
var win = CC['@mozilla.org/appshell/window-mediator;1'].getService(CI.nsIWindowMediator).getMostRecentWindow('navigator:browser');

if (win && win.document && (win.document.readyState == "complete")) {
params.inBackground = params.selected = params.active;

if ("gBrowser" in win) {
win.gBrowser.loadOneTab(params.url, params);
} else if ("BrowserApp" in win) {
Expand All @@ -135,7 +110,6 @@ function startup(startupData, startupReason) {

sandboxs.push(sandbox);
win.addEventListener("unload", windowOnUnload, false);

CU.exportFunction(onMessage, sandbox, {defineAs: "sendMessage"});
CU.evalInSandbox(script, sandbox);

Expand All @@ -147,9 +121,7 @@ function startup(startupData, startupReason) {

function windowOnUnload(ev) {
ev.currentTarget.removeEventListener("unload", windowOnUnload, false);

var i = sandboxs.length;

while (i--) {
if (sandboxs[i].window == ev.currentTarget) {
CU.evalInSandbox("if (typeof redirectBypasser != \"undefined\") {redirectBypasser.stop(true);}", sandboxs[i]);
Expand Down

0 comments on commit 4e857f4

Please sign in to comment.