aboutsummaryrefslogtreecommitdiff
path: root/chrome/js
diff options
context:
space:
mode:
authorpapush2021-04-29 15:51:10 +0200
committerpapush2021-04-29 15:51:51 +0200
commit372b801329584f92e942139011cdbb2d0c92085c (patch)
treed14ed6c34c07ea240743d54e3f9d0d4ac7650309 /chrome/js
parentff4d941f195f6359ee9715d16832c6af749a9045 (diff)
fix whitespace
Diffstat (limited to 'chrome/js')
-rw-r--r--chrome/js/browserOverlay.js20
-rw-r--r--chrome/js/redirect.js85
-rw-r--r--chrome/js/redirector-ui.js40
-rw-r--r--chrome/js/redirector.js118
4 files changed, 135 insertions, 128 deletions
diff --git a/chrome/js/browserOverlay.js b/chrome/js/browserOverlay.js
index ed1ab73..bfaff90 100644
--- a/chrome/js/browserOverlay.js
+++ b/chrome/js/browserOverlay.js
@@ -3,7 +3,7 @@ Components.utils.import("chrome://redirector/content/js/redirector.js");
var RedirectorOverlay = {
- strings : null,
+ strings : null,
prefs : null,
onLoad : function(event) {
@@ -12,16 +12,16 @@ var RedirectorOverlay = {
// initialization code
document.getElementById('contentAreaContextMenu')
.addEventListener("popupshowing", function(e) { RedirectorOverlay.showContextMenu(e); }, false);
-
+
this.strings = document.getElementById("redirector-strings");
this.prefs = new RedirectorPrefs();
this.changedPrefs(this.prefs);
- this.prefs.addListener(this);
+ this.prefs.addListener(this);
document.addEventListener('keypress', function(event) {
if ((event.charCode == 114) && event.altKey) { //alt+r
RedirectorOverlay.toggleEnabled();
}
- }, true);
+ }, true);
} catch(e) {
if (this.strings) {
alert(this.strings.getString("initError") + "\n\n" + e);
@@ -30,7 +30,7 @@ var RedirectorOverlay = {
}
}
},
-
+
onUnload : function(event) {
this.prefs.dispose();
Redirector.debug("Finished cleanup");
@@ -50,7 +50,7 @@ var RedirectorOverlay = {
document.getElementById('redirector-status').hidden = !prefs.showStatusBarIcon;
document.getElementById('redirector-context').hidden = !prefs.showContextMenu;
},
-
+
showContextMenu : function(event) {
if (gContextMenu.onLink) {
document.getElementById("redirector-context").label = this.strings.getString('addLinkUrl');
@@ -65,9 +65,9 @@ var RedirectorOverlay = {
redirect.redirectUrl = gContextMenu.link.toString();
}
- gBrowser.selectedTab = gBrowser.addTab("chrome://redirector/content/redirector.html");
+ gBrowser.selectedTab = gBrowser.addTab("chrome://redirector/content/redirector.html");
},
-
+
onMenuItemCommand: function(event) {
this.openSettings();
},
@@ -77,9 +77,9 @@ var RedirectorOverlay = {
},
openSettings : function() {
- gBrowser.selectedTab = gBrowser.addTab("chrome://redirector/content/redirector.html");
+ gBrowser.selectedTab = gBrowser.addTab("chrome://redirector/content/redirector.html");
},
-
+
statusBarClick : function(event) {
var LEFT = 0, RIGHT = 2;
diff --git a/chrome/js/redirect.js b/chrome/js/redirect.js
index eab14f8..e1e1c68 100644
--- a/chrome/js/redirect.js
+++ b/chrome/js/redirect.js
@@ -1,4 +1,3 @@
-
var EXPORTED_SYMBOLS = ['Redirect'];
@@ -11,43 +10,43 @@ Redirect.WILDCARD = 'W';
Redirect.REGEX = 'R';
Redirect.prototype = {
-
+
//attributes
exampleUrl : null,
-
+
get includePattern() { return this._includePattern; },
- set includePattern(value) {
+ set includePattern(value) {
this._includePattern = value;
- this._rxInclude = this._compile(value);
+ this._rxInclude = this._compile(value);
},
-
+
get excludePattern() { return this._excludePattern; },
- set excludePattern(value) {
- this._excludePattern = value;
- this._rxExclude = this._compile(value);
+ set excludePattern(value) {
+ this._excludePattern = value;
+ this._rxExclude = this._compile(value);
},
-
+
redirectUrl : null,
-
+
get patternType() { return this._patternType; },
- set patternType(value) {
+ set patternType(value) {
this._patternType = value;
this.compile();
},
unescapeMatches : false,
escapeMatches : false,
-
+
disabled : false,
-
+
//Functions
clone : function() {
return new Redirect().fromObject(this.toObject());
},
-
+
compile : function() {
- this._rxInclude = this._compile(this._includePattern);
- this._rxExclude = this._compile(this._excludePattern);
+ this._rxInclude = this._compile(this._includePattern);
+ this._rxExclude = this._compile(this._excludePattern);
},
toObject : function() {
@@ -69,7 +68,7 @@ Redirect.prototype = {
}
return this;
},
-
+
copyValues : function(other) {
this.exampleUrl = other.exampleUrl;
this.includePattern = other.includePattern;
@@ -91,16 +90,16 @@ Redirect.prototype = {
&& this.escapeMatches == redirect.escapeMatches
;
},
-
+
getMatch: function(url) {
- var result = {
- isMatch : false,
- isExcludeMatch : false,
- isDisabledMatch : false,
+ var result = {
+ isMatch : false,
+ isExcludeMatch : false,
+ isDisabledMatch : false,
redirectTo : '',
- toString : function() { return "{ isMatch : " + this.isMatch +
- ", isExcludeMatch : " + this.isExcludeMatch +
- ", isDisabledMatch : " + this.isDisabledMatch +
+ toString : function() { return "{ isMatch : " + this.isMatch +
+ ", isExcludeMatch : " + this.isExcludeMatch +
+ ", isDisabledMatch : " + this.isDisabledMatch +
", redirectTo : \"" + this.redirectTo + "\"" +
"}"; }
};
@@ -117,33 +116,33 @@ Redirect.prototype = {
result.redirectTo = redirectTo;
}
}
- return result;
+ return result;
},
-
+
isRegex: function() {
return this.patternType == Redirect.REGEX;
},
-
+
isWildcard : function() {
- return this.patternType == Redirect.WILDCARD;
+ return this.patternType == Redirect.WILDCARD;
},
test : function() {
- return this.getMatch(this.exampleUrl);
+ return this.getMatch(this.exampleUrl);
},
-
- //Private functions below
+
+ //Private functions below
_includePattern : null,
_excludePattern : null,
_patternType : null,
_rxInclude : null,
_rxExclude : null,
-
+
_preparePattern : function(pattern) {
if (this.patternType == Redirect.REGEX) {
- return pattern;
+ return pattern;
} else { //Convert wildcard to regex pattern
var converted = '^';
for (var i = 0; i < pattern.length; i++) {
@@ -167,7 +166,7 @@ Redirect.prototype = {
}
return new RegExp(this._preparePattern(pattern),"gi");
},
-
+
_init : function(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled) {
this.exampleUrl = exampleUrl || '';
this.includePattern = includePattern || '';
@@ -178,10 +177,10 @@ Redirect.prototype = {
this.escapeMatches = (escapeMatches === 'true' || escapeMatches === true);
this.disabled = (disabled === 'true' || disabled === true);
},
-
+
toString : function() {
return 'REDIRECT: {'
- + '\n\tExample url : ' + this.exampleUrl
+ + '\n\tExample url : ' + this.exampleUrl
+ '\n\tInclude pattern : ' + this.includePattern
+ '\n\tExclude pattern : ' + this.excludePattern
+ '\n\tRedirect url : ' + this.redirectUrl
@@ -191,11 +190,11 @@ Redirect.prototype = {
+ '\n\tDisabled : ' + this.disabled
+ '\n}\n';
},
-
+
_includeMatch : function(url) {
if (!this._rxInclude) {
return null;
- }
+ }
var matches = this._rxInclude.exec(url);
if (!matches) {
return null;
@@ -214,12 +213,12 @@ Redirect.prototype = {
this._rxInclude.lastIndex = 0;
return resultUrl;
},
-
+
_excludeMatch : function(url) {
if (!this._rxExclude) {
- return false;
+ return false;
}
- var shouldExclude = !!this._rxExclude.exec(url);
+ var shouldExclude = !!this._rxExclude.exec(url);
this._rxExclude.lastIndex = 0;
return shouldExclude;
}
diff --git a/chrome/js/redirector-ui.js b/chrome/js/redirector-ui.js
index 49526e3..78e83e2 100644
--- a/chrome/js/redirector-ui.js
+++ b/chrome/js/redirector-ui.js
@@ -4,10 +4,10 @@ Components.utils.import("chrome://redirector/content/js/redirectorprefs.js");
Components.utils.import("chrome://redirector/content/js/xpcom.js");
jQuery.fn.center = function () {
- this.css("position","absolute");
- this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
- this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
- return this;
+ this.css("position","absolute");
+ this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
+ this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
+ return this;
}
function alert(title, msg) {
@@ -41,15 +41,15 @@ function validateRedirect(redirect) {
if (!result.isMatch) {
title = tr('warningExampleUrlDoesntMatchPatternTitle');
msg = tr('warningExampleUrlDoesntMatchPattern');
- var rv = PromptService.confirmEx(window, title, msg, PromptService.STD_YES_NO_BUTTONS, PromptService.BUTTON_TITLE_YES, PromptService.BUTTON_TITLE_NO, null, null, {});
+ var rv = PromptService.confirmEx(window, title, msg, PromptService.STD_YES_NO_BUTTONS, PromptService.BUTTON_TITLE_YES, PromptService.BUTTON_TITLE_NO, null, null, {});
return rv == 0;
} else {
var resultUrl = result.redirectTo;
if (!resultUrl.match(/https?:/)) {
- var uri = IOService.newURI(redirect.exampleUrl, null, null);
+ var uri = IOService.newURI(redirect.exampleUrl, null, null);
resultUrl = uri.resolve(resultUrl);
- }
-
+ }
+
var secondResult = redirect.getMatch(resultUrl);
if (secondResult.isMatch) {
title = tr('errorExampleUrlMatchesRecursiveTitle');
@@ -76,7 +76,7 @@ function getFile(captionKey, mode) {
picker.displayDirectory = new LocalFile(dir);
}
picker.appendFilter(tr('redirectorFiles'), '*.rjson');
-
+
if (picker.show() == picker.returnCancel) {
return null;
}
@@ -103,13 +103,13 @@ function importRedirects() {
var msg, imported, existed;
imported = result & 0xFFFF;
existed = result >> 16;
-
+
if (imported > 0) {
msg = trPlural('importedMessage', imported);
if (existed > 0) {
- msg += ', ' + trPlural('existedMessage',existed);
+ msg += ', ' + trPlural('existedMessage',existed);
} else {
- msg += '.';
+ msg += '.';
}
} else if (imported == 0 && existed > 0) {
msg = trPlural('allExistedMessage', existed);
@@ -124,7 +124,7 @@ function importRedirects() {
var newlist = [];
for (var i = Redirector.redirectCount-imported; i < Redirector.redirectCount; i++) {
newlist.push(Redirector.getRedirectAt(i));
- }
+ }
databind();
}
}
@@ -167,7 +167,7 @@ function controlsToRedirect(redirect) {
} else {
redirect.patternType = Redirect.WILDCARD;
}
-
+
var inc = $('#include-pattern').val();
var exc = $('#exclude-pattern').val();
if (!validatePattern(inc, redirect.patternType)) {
@@ -178,7 +178,7 @@ function controlsToRedirect(redirect) {
}
redirect.includePattern = inc;
redirect.excludePattern = exc;
-
+
redirect.description = $('#description').val();
redirect.exampleUrl = $('#example-url').val();
redirect.redirectUrl = $('#redirect-to').val();
@@ -244,7 +244,7 @@ function testPattern() {
$(document).ready(function() {
window.template = $('#redirect-list').html().replace(/^\s*|\s$/g, '');
- window.strings = StringBundleService.createBundle('chrome://redirector/locale/redirector.properties', LocaleService.getApplicationLocale());
+ window.strings = StringBundleService.createBundle('chrome://redirector/locale/redirector.properties', LocaleService.getApplicationLocale());
window.prefs = new RedirectorPrefs();
$('link').attr('href',$('link').attr('href')+new Date());
@@ -257,7 +257,7 @@ $(document).ready(function() {
}
ev.preventDefault();
});
-
+
$('#redirect-list li div a.edit').live('click', function(ev) {
var redirect = $(this.parentNode.parentNode).data('redirect');
window.editRedirect = redirect;
@@ -278,9 +278,9 @@ $(document).ready(function() {
$('#config').hide();
});
$('#help').click(function() {
- window.location.href = "chrome://redirector/content/help.html";
+ window.location.href = "chrome://redirector/content/help.html";
});
-
+
bindConfig();
prefs.addListener({ changedPrefs:bindConfig});
@@ -304,7 +304,7 @@ $(document).ready(function() {
}
}
});
-
+
$(document).mouseup(function() {
if (movingElement) {
$(movingElement).css('background', '');
diff --git a/chrome/js/redirector.js b/chrome/js/redirector.js
index 86e07a2..da4904a 100644
--- a/chrome/js/redirector.js
+++ b/chrome/js/redirector.js
@@ -1,15 +1,16 @@
Components.utils.import("chrome://redirector/content/js/xpcom.js");
Components.utils.import("chrome://redirector/content/js/redirect.js");
Components.utils.import("chrome://redirector/content/js/redirectorprefs.js");
+Components.utils.import("resource://gre/modules/Services.jsm");
var EXPORTED_SYMBOLS = ['Redirector'];
Redirector = {
-
+
get enabled() {
- return this._prefs && this._prefs.enabled;
+ return this._prefs && this._prefs.enabled;
},
-
+
set enabled(value) {
if (this._prefs) {
this._prefs.enabled = value;
@@ -19,11 +20,11 @@ Redirector = {
get redirectCount() {
return this._list.length;
},
-
+
toString : function() {
return "Redirector";
},
-
+
addRedirect : function(redirect) {
this._list.push(redirect);
this.save();
@@ -31,17 +32,17 @@ Redirector = {
debug : function(msg) {
if (this._prefs.debugEnabled) {
- ConsoleService.logStringMessage('REDIRECTOR: ' + msg);
+ Services.console.logStringMessage('REDIRECTOR: ' + msg);
}
},
-
+
deleteRedirect : function(redirect) {
this._list.splice(this._list.indexOf(redirect), 1);
this.save();
},
-
+
exportRedirects : function(file) {
- const PR_WRONLY = 0x02;
+ const PR_WRONLY = 0x02;
const PR_CREATE_FILE = 0x08;
const PR_TRUNCATE = 0x20;
@@ -54,16 +55,16 @@ Redirector = {
stream.writeString(JSON.stringify(rjson, null, 4));
stream.close();
},
-
+
getRedirectAt : function(index) {
- return this._list[index];
+ return this._list[index];
},
-
+
//Get the redirect url for the given url. This will not check if we are enabled, and
//not do any verification on the url, just assume that it is a good string url that is for http/s
getRedirectUrl : function(url) {
this.debug("Checking " + url);
-
+
for each (var redirect in this._list) {
var result = redirect.getMatch(url);
if (result.isExcludeMatch) {
@@ -72,7 +73,7 @@ Redirector = {
this.debug(url + ' matched pattern ' + redirect.includePattern + ' but the redirect is disabled');
} else if (result.isMatch) {
redirectUrl = this._makeAbsoluteUrl(url, result.redirectTo);
-
+
//check for loops...
result = redirect.getMatch(redirectUrl);
if (result.isMatch) {
@@ -89,20 +90,20 @@ Redirector = {
}
return null;
},
-
+
QueryInterface: function(iid) {
if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIContentPolicy) || iid.equals(Ci.nsIChannelEventSink)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
},
-
+
_getRedirectsFile : function() {
var file = DirectoryService.get("ProfD", Ci.nsIFile);
file.append('redirector.rjson');
return file;
- },
-
+ },
+
handleUpgrades : function(){
var currentVersion = '2.7.1';
this._list = [];
@@ -111,7 +112,7 @@ Redirector = {
return;
}
//Here update checks are handled
-
+
try {
var branch = PrefService.getBranch("extensions.redirector.");
var data = branch.getCharPref("redirects");
@@ -126,7 +127,7 @@ Redirector = {
if (!redirectString || !redirectString.split) {
continue;
this.debug('Invalid old redirect: ' + redirectString);
- }
+ }
var parts = redirectString.split(',,,');
if (parts.length < 5) {
throw Error("Invalid serialized redirect, too few fields: " + redirectString);
@@ -140,8 +141,8 @@ Redirector = {
}
branch.deleteBranch('redirects');
this._prefs.version = currentVersion;
- },
-
+ },
+
importRedirects : function(file) {
var fileStream = new FileInputStream(file, 0x01, 0444, 0);
var stream = new ConverterInputStream(fileStream, "UTF-8", 16384, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
@@ -171,64 +172,71 @@ Redirector = {
var file = this._getRedirectsFile();
this.exportRedirects(file);
},
-
+
sortRedirects : function(sortFunc) {
this._list.sort(sortFunc);
this.save();
},
-
+
// nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) {
+ this.debug('REDIRECTOR: inside shouldLoad');
if (contentLocation.scheme != "http" && contentLocation.scheme != "https") {
return Ci.nsIContentPolicy.ACCEPT;
} //Immediately, otherwise we will log all sorts of crap
-
+
this.debug('nsIContentPolicy::ShouldLoad ' + contentLocation.spec);
try {
//This is also done in getRedirectUrl, but we want to exit as quickly as possible for performance
if (!this._prefs.enabled) {
+ this.debug('REDIRECTOR: not enabled');
return Ci.nsIContentPolicy.ACCEPT;
}
-
+
if (contentType != Ci.nsIContentPolicy.TYPE_DOCUMENT) {
+ this.debug('REDIRECTOR: TYPE DOCUMENT');
return Ci.nsIContentPolicy.ACCEPT;
}
if (contentLocation.scheme != "http" && contentLocation.scheme != "https") {
+ this.debug('REDIRECTOR: not http or https');
return Ci.nsIContentPolicy.ACCEPT;
}
-
+
if (!aContext || !aContext.loadURI) {
+ this.debug('REDIRECTOR: no context or context.loadURI');
return Ci.nsIContentPolicy.ACCEPT;
}
-
+
var redirectUrl = this.getRedirectUrl(contentLocation.spec);
if (!redirectUrl) {
+ this.debug('REDIRECTOR: invalid redirect url');
return Ci.nsIContentPolicy.ACCEPT;
- }
+ }
+ this.debug('REDIRECTOR: redirecting');
aContext.loadURI(redirectUrl, requestOrigin, null);
return Ci.nsIContentPolicy.REJECT_REQUEST;
} catch(e) {
- this.debug(e);
+ this.debug(e);
}
-
+
},
-
+
shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode, mimeType, extra) {
return Ci.nsIContentPolicy.ACCEPT;
},
//end nsIContentPolicy
//nsIChannelEventSink implementation
-
+
//For FF4.0. Got this from a thread about adblock plus, https://adblockplus.org/forum/viewtopic.php?t=5895
asyncOnChannelRedirect: function(oldChannel, newChannel, flags, redirectCallback) {
this.onChannelRedirect(oldChannel, newChannel, flags);
redirectCallback.onRedirectVerifyCallback(0);
- },
-
+ },
+
onChannelRedirect: function(oldChannel, newChannel, flags)
{
try {
@@ -237,13 +245,13 @@ Redirector = {
if (!(newChannel.loadFlags & Ci.nsIChannel.LOAD_DOCUMENT_URI)) {
//We only redirect documents...
- return;
+ return;
}
if (!this._prefs.enabled) {
return;
}
-
+
if (!newLocation) {
return;
}
@@ -265,24 +273,24 @@ Redirector = {
} catch(e) {}
}
if (!webNav) {
- return;
+ return;
}
var redirectUrl = this.getRedirectUrl(newLocation);
if (redirectUrl) {
webNav.loadURI(redirectUrl,null,null,null,null);
throw Cr.NS_BASE_STREAM_WOULD_BLOCK; //Throw this because the real error we should throw shows up in console...
- }
-
+ }
+
} catch (e if (e != Cr.NS_BASE_STREAM_WOULD_BLOCK)) {
// We shouldn't throw exceptions here - this will prevent the redirect.
this.debug("Redirector: Unexpected error in onChannelRedirect: " + e + "\n");
}
},
//end nsIChannelEventSink
-
+
//Private members and methods
-
+
_prefs : null,
_list : null,
_strings : null,
@@ -304,37 +312,37 @@ Redirector = {
this.importRedirects(redirectsFile);
}
},
-
+
_loadStrings : function() {
var src = 'chrome://redirector/locale/redirector.properties';
- var appLocale = LocaleService.getApplicationLocale();
- this._strings = StringBundleService.createBundle(src, appLocale);
- },
-
+ var appLocale = Services.locale.getApplicationLocale();
+ this._strings = StringBundleService.createBundle(src, appLocale);
+ },
+
_containsRedirect : function(redirect) {
for each (var existing in this._list) {
if (existing.equals(redirect)) {
return true;
- }
+ }
}
return false;
},
-
+
_getString : function(name) {
return this._strings.GetStringFromName(name);
},
-
+
_getFormattedString : function(name, params) {
return this._strings.formatStringFromName(name, params, params.length);
},
-
+
_makeAbsoluteUrl : function(currentUrl, relativeUrl) {
-
+
if (relativeUrl.match(/https?:/)) {
return relativeUrl;
- }
-
- var uri = IOService.newURI(currentUrl, null, null);
+ }
+
+ var uri = IOService.newURI(currentUrl, null, null);
return uri.resolve(relativeUrl);
}
};