📄 gladder.js
字号:
var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var gl_alpha1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var gl_alpha2 = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
var gl_alnum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
var gl_alnumb = new Array();
for (var revTableIdx = 0; revTableIdx < 64; ++revTableIdx) {
gl_alnumb[gl_alnum[revTableIdx]] = revTableIdx;
}
function gl_str_rot13(str) {
var newStr = "";
var curLet, curLetLoc;
for (var i = 0; i < str.length; i++) {
curLet = str.charAt(i);
curLetLoc = gl_alpha1.indexOf(curLet);
newStr += (curLetLoc < 0) ? curLet : gl_alpha2.charAt(curLetLoc);
}
return newStr;
}
function gl_str_rot13_back(str) {
var newStr = "";
var curLet, curLetLoc;
for (var i = 0; i < str.length; i++) {
curLet = str.charAt(i);
curLetLoc = gl_alpha2.indexOf(curLet);
newStr += (curLetLoc < 0) ? curLet : gl_alpha1.charAt(curLetLoc);
}
return newStr;
}
function gl_trim(string) {
return string.replace(/(^\s+)|(\s+$)/g, "");
}
function gl_base64_encode(str) {
var out = "";
var t, x, y, z;
for (var i = 0; i < str.length; i += 3) {
t = Math.min(3, str.length - i);
if (t == 1) {
x = str.charCodeAt(i);
out += gl_alnum.charAt((x >> 2));
out += gl_alnum.charAt(((x & 3) << 4));
out += "--";
} else {
if (t == 2) {
x = str.charCodeAt(i);
y = str.charCodeAt(i + 1);
out += gl_alnum.charAt((x >> 2));
out += gl_alnum.charAt((((x & 3) << 4) | (y >> 4)));
out += gl_alnum.charAt(((y & 15) << 2));
out += "-";
} else {
x = str.charCodeAt(i);
y = str.charCodeAt(i + 1);
z = str.charCodeAt(i + 2);
out += gl_alnum.charAt((x >> 2));
out += gl_alnum.charAt((((x & 3) << 4) | (y >> 4)));
out += gl_alnum.charAt((((y & 15) << 2) | (z >> 6)));
out += gl_alnum.charAt((z & 63));
}
}
}
return out;
}
function gl_base64_decode(str) {
var source = str;
var counter = 0;
if (str == null || str.length == 0) {
return "";
}
// We'll build up the result string in this varable.
var ret = "";
var chunk = gl_getNextChunk(source, counter);
counter += 4;
while (chunk.length > 0) {
// Convert the (up to) four 6 bits-per-byte chunk elements into (up to)
// three 8 bits-per-byte resulting decoded characters.
ret += String.fromCharCode((chunk[0] << 2) & 0xff | (chunk[1] >> 4) & 0x3f);
if (chunk.length > 2) {
ret += String.fromCharCode((chunk[1] << 4) & 0xff | (chunk[2] >> 2) & 0x3f);
if (chunk.length > 3) {
ret += String.fromCharCode((chunk[2] << 6) & 0xff | chunk[3]);
}
}
chunk = gl_getNextChunk(source, counter);
counter += 4;
}
return ret;
}
function gl_getNextChunk(source, counter) {
var chunk = new Array();
for (var x = 0; x < 4; ++x) {
if (counter < source.length) {
var c = source.charAt(counter);
if (c != '-') {
chunk[x] = gl_alnumb[c];
}
++counter;
}
}
return chunk;
}
function gl_parseSite(url){
if (!/^http\:\/\//.test(url)){
return "";
}
return url.replace(/^http\:\/\/([^\/\:]*).*/, "$1");
}
function gl_isErrorPage(url){
if (typeof(url) == "undefined" || url == null){
return [false, null];
}
var errorPage = false;
if (url.substring(0, 14) == "about:neterror") {
var re = new RegExp("&u=([^&]*)");
var arr;
if ((arr = re.exec(url)) !== undefined) {
url = arr[1];
}
url = unescape(url);
errorPage = true;
}
return [errorPage, url];
}
function gl_ddump(str) {
dump(str + "\n");
}
function gl_ddumpObject(obj, name, maxDepth, curDepth) {
if (curDepth == undefined) {
curDepth = 0;
}
if (maxDepth != undefined && curDepth > maxDepth) {
return;
}
var i = 0;
for (prop in obj) {
i++;
if (typeof (obj[prop]) == "object") {
if (obj[prop] && obj[prop].length != undefined) {
gl_ddump(name + "." + prop + "=[probably array, length " + obj[prop].length + "]");
} else {
gl_ddump(name + "." + prop + "=[" + typeof (obj[prop]) + "]");
}
gl_ddumpObject(obj[prop], name + "." + prop, maxDepth, curDepth + 1);
} else {
if (typeof (obj[prop]) == "function") {
gl_ddump(name + "." + prop + "=[function]");
} else {
gl_ddump(name + "." + prop + "=" + obj[prop]);
}
}
}
if (!i) {
gl_ddump(name + " is empty");
}
}
function gl_adapter(str) {
this.init(str);
}
gl_adapter.prototype.init = function (str) {
this._str = str;
this._e = 0;
try{
this._decode = false;
this._type = 0;
if (str.charAt(0) == '#'){
str = str.substr(1);
this._premodify = (str.charAt(0) == '?');
if (this._premodify){
str = str.substr(1);
}
if (str.charAt(0) == "%"){
this._decode = true;
str = str.substr(1);
}
else{
this._type = parseInt(str.substr(0, 2));
if (isNaN(this._type)){
this._err = true;
return;
}
str = str.substr(2);
}
}
var coupe = str.split("\n");
if (coupe.length < 2) {
this._err = true;
return;
}
this._src = coupe[0];
this._dst = coupe[1];
this._default = false;
this._name = (coupe.length > 2)?coupe[2]:"";
this._toDefault = /^>\=/.test(this._name);
if (this._toDefault){
this._name = this._name.substr(2);
}
if (this._dst.charAt(0) == ">") {
this._dst = this._dst.substr(1);
if (this._dst.charAt(0) == "="){
this._default = true;
this._dst = this._dst.substr(1);
if (this._name.length == 0){
this._name = gl_parseSite(this._dst);
}
}
}
this._err = false;
this._re = new RegExp(this._src, "i");
}
catch(e){
gl_ddump(e.message);
this._err = true;
}
};
gl_adapter.prototype.toString = function () {
return this._str;
};
gl_adapter.prototype.process = function(url ,callback){
if (!this._err && (this._default || this._re.test(url))) {
if (this._toDefault){
var ada = gGladder._defaultAda;
if (this._type != ada._type){
ada = null;
for (var i=0; i<gGladder._defaultAdaList.length; i++){
var adai = gGladder._defaultAdaList[i];
if (this._type == adai._type){
if (ada == null || (adai._s && (!ada._s || adai._s < ada._s))){
ada = adai;
}
}
}
}
if (ada)
ada.process(url, callback);
}
else{
callback(this.processUrl(url));
}
return true;
}
return false;
};
gl_adapter.prototype.processUrl = function(url){
switch(this._type){
case 0:
if (this._decode){
var ret = this._dst;
var res = this._re.exec(url);
// gl_ddump("url:"+url);
// gl_ddumpObject(res, "res", 1);
for (var i=res.length ; i>0; i--){
var re = new RegExp("\\$"+i, "g");
ret = ret.replace(re, decodeURIComponent(res[i]));
}
// gl_ddump("ret:"+ret);
return (ret);
}
else{
return url.replace(this._re, this._dst);
}
case 1:
return this._dst + url;
case 13:
return this._dst+encodeURIComponent(gl_str_rot13(url));
case 64:
return this._dst+gl_base64_encode(url);
}
return url;
}
function gl_progressListener() {
}
gl_progressListener.prototype.QueryInterface = function () {
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
};
function Gladder(observe) {
if (typeof(observe) == "undefined"){
observe = true;
}
this._updateIndex = 0;
this._adapters = new Array;
this._sites = new Array;
this._phproxies = new Array;
this._namePrefEnabled = "gladder.enabled";
this._namePrefAdapters = "gladder.adapters";
this._namePrefUpdateURL = "gladder.updateurl";
this._namePrefUpdateTimeout = "gladder.updatetimeout";
this._namePrefSites = "gladder.sites";
this._namePrefUnproxy = "gladder.unproxy";
this._namePrefPHProxies = "gladder.phproxies";
this._namePrefPHProxiesUrl = "gladder.phproxiesurl";
this._namePrefPHProxiesLastIndex = "gladder.phproxy.last";
this._namePrefProxyUrl = "gladder.proxy.url";
this._namePrefProxyType = "gladder.proxy.type";
this._namePrefWorkWithNetworkProxy = "gladder.workwithnetworkproxy";
this._namePrefUsePHProxy = "gladder.usephproxy";
this._namePrefDefaultAdapterName = "gladder.defaultadaptername";
this._nameStatusImg = "gladderStatusImage";
this._nameStringTooltipTrack = "tooltip.track";
this._nameStringTooltipCurrent = "tooltip.phproxy.current";
this._nameStringStatusEnable = "status.tooltip.enabled";
this._nameStringStatusDisabledByProxy = "status.tooltip.disabledbyproxy";
this._nameStringStatusFindingPHProxy = "status.tooltip.phproxy.finding";
this._nameStringStatusNetworkOffline = "status.tooltip.network.offline";
this._nameStringStatusDisable = "status.tooltip.disabled";
this._nameStringStatusProxy = "menu.label.proxy";
this._nameStringStatusUnproxy = "menu.label.unproxy";
this._pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
this._enabled = true;
this._unproxy = true;
this._workWithNetworkProxy = false;
this._defaultAda = null;
this._defaultAdaList = new Array;
this._timeout = 3600000;
this._usePHProxy = true;
this._beforeURI = [];
this._afterURI = [];
this.NAME_ADA_CUSTOM = "custom proxy";
this._PHProxyManager = Components.classes['@gladder.gneheix.com/phproxymanager;1']
.getService(Components.interfaces.nsIglPHProxyManager);
this._online = Components.
classes["@gladder.gneheix.com/NetworkStatus;1"].getService(Components.interfaces.nsIglNetworkStatus).online;
if (observe){
var observerService = Components.
classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "gl_loadpref", false);
observerService.addObserver(this, "gl-phproxy-mananger-ready", false);
observerService.addObserver(this, "gl-network-status", false);
}
}
Gladder.prototype.observe = function(aSubject, aTopic, aData){
try{
if (aTopic == "gl_loadpref"){
this.loadPref();
}
else if (aTopic == "gl-phproxy-mananger-ready"){
this.updateStatus();
}
else if (aTopic == "gl-network-status"){
this._online = (aData == "true");
this.updateStatus();
}
}catch(e){}
};
Gladder.prototype.QueryInterface = function(aIID){
if (!aIID.equals(Components.interfaces.nsIObserver) &&
!aIID.equals(Components.interfaces.nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
};
Gladder.prototype.notify = function(){
Components.classes['@mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService).notifyObservers(null, 'gl_loadpref', '');
};
//hacked from IeTab
Gladder.prototype.hookCode = function(orgFunc, orgCode, myCode) {
if (orgFunc == "") return;
switch (orgCode) {
case "{":
orgCode = /{/;
myCode = "{"+myCode;
break;
case "}":
orgCode = /}$/;
myCode = myCode+"}";
break;
default:
}
try { eval(orgFunc + "=" + eval(orgFunc).toString().replace(orgCode, myCode)); }catch(e){ gl_ddump("Failed to hook function: "+orgFunc + " :" +e); }
// gl_ddump(orgFunc + "=" + eval(orgFunc).toString().replace(orgCode, myCode))
// gl_ddump(eval(orgFunc).toString());
};
//hacked from IeTab
Gladder.prototype.hookProp = function(parentNode, propName, myGetter, mySetter) {
var oGetter = parentNode.__lookupGetter__(propName);
var oSetter = parentNode.__lookupSetter__(propName);
if (oGetter && myGetter) myGetter = oGetter.toString().replace(/{/, "{"+myGetter.toString().replace(/^.*{/,"").replace(/.*}$/,""));
if (oSetter && mySetter) mySetter = oSetter.toString().replace(/{/, "{"+mySetter.toString().replace(/^.*{/,"").replace(/.*}$/,""));
if (!myGetter) myGetter = oGetter;
if (!mySetter) mySetter = oSetter;
if (myGetter) try { eval('parentNode.__defineGetter__(propName, '+ myGetter.toString() +');'); }catch(e){ gl_ddump("Failed to hook property Getter: "+propName + " :" +e); }
if (mySetter) try { eval('parentNode.__defineSetter__(propName, '+ mySetter.toString() +');'); }catch(e){ gl_ddump("Failed to hook property Setter: "+propName + " :" +e); }
};
Gladder.prototype.hookCodeAll = function() {
// this.hookCode('gBrowser.mTabProgressListener', "function (aWebProgress, aRequest, aLocation) {", "$& gGladder.checkFilter(this.mBrowser, aRequest, aLocation);");
this.hookCode('gBrowser.mTabProgressListener', "function (aWebProgress, aRequest, aStateFlags, aStatus) {", "$& gGladder.stateChange(this.mBrowser, aWebProgress, aRequest, aStateFlags, aStatus);");
for(var i=0 ; i<gBrowser.mTabListeners.length ; i++){
// this.hookCode("gBrowser.mTabListeners["+i+"].onLocationChange", "{", "gGladder.checkFilter(this.mBrowser, aRequest, aLocation);");
this.hookCode("gBrowser.mTabListeners["+i+"].onStateChange", "{", "gGladder.stateChange(this.mBrowser, aWebProgress, aRequest, aStateFlags, aStatus);");
}
this.hookCode("BrowserLoadURL", /\S+\.value/, "gGladder.filterInput($&)");
// this.hookCode("getShortcutOrURI", /return (\S+);/, "return gGladder.filterInput($1);");
gBrowser.mPanelContainer.addEventListener("DOMNodeInserted", this.onTabAdded, false);
this.hookBrowserSetter(gBrowser.mPanelContainer.firstChild);
// this.hookURLBarSetter(gURLBar);
};
//Gladder.prototype.hookURLBarSetter = function(aURLBar) {
// if (!aURLBar) aURLBar = document.getElementById("urlbar");
// if (!aURLBar) return;
// this.hookProp(aURLBar, "value", null, function() {
// gl_ddump(val);
// });
//}
//Gladder.prototype.getCurrentIeTabURI = function(aBrowser) {
// try {
// var docShell = aBrowser.boxObject.QueryInterface(Components.interfaces.nsIBrowserBoxObject).docShell;
// var wNav = docShell.QueryInterface(Components.interfaces.nsIWebNavigation);
// if (wNav.currentURI && wNav.currentURI.spec.indexOf(gIeTabChromeStr) == 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -