2006-05-14 23:48:10 +02:00
|
|
|
var resurrect={
|
2006-05-15 00:37:23 +02:00
|
|
|
|
2016-03-14 18:42:00 +01:00
|
|
|
contextUrl:null,
|
2006-05-14 23:48:10 +02:00
|
|
|
|
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
2011-06-26 23:19:47 +02:00
|
|
|
onLoad:function() {
|
|
|
|
window.removeEventListener('load', resurrect.onLoad, false);
|
|
|
|
document.getElementById('contentAreaContextMenu')
|
|
|
|
.addEventListener('popupshowing', resurrect.toggleContextItems, false);
|
2016-03-14 18:42:00 +01:00
|
|
|
addEventListener('DOMContentLoaded', resurrect.contentDomLoad, false);
|
2011-06-26 23:19:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleContextItems:function(event) {
|
2016-03-14 18:42:00 +01:00
|
|
|
resurrect.contextUrl = gContextMenu.linkURL;
|
2011-06-26 23:19:47 +02:00
|
|
|
|
|
|
|
var onDocument=!(
|
|
|
|
gContextMenu.isContentSelected || gContextMenu.onTextInput ||
|
|
|
|
gContextMenu.onLink || gContextMenu.onImage);
|
|
|
|
|
|
|
|
document.getElementById('resurrect-page-context')
|
|
|
|
.setAttribute('hidden', !onDocument);
|
|
|
|
document.getElementById('resurrect-link-context')
|
|
|
|
.setAttribute('hidden', !gContextMenu.onLink);
|
|
|
|
},
|
|
|
|
|
|
|
|
contentDomLoad:function(event) {
|
|
|
|
var contentDoc=event.target;
|
|
|
|
|
2016-03-14 18:42:00 +01:00
|
|
|
if (contentDoc.documentURI.indexOf('about:neterror') != 0) return;
|
|
|
|
|
|
|
|
// Inject our content...
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('GET', 'chrome://resurrect/content/netError.xhtml', true);
|
|
|
|
xhr.onload = function() {
|
|
|
|
var fieldset = xhr.responseXML.getElementById('resurrect');
|
|
|
|
var xhtml = new XMLSerializer().serializeToString(fieldset);
|
2011-06-26 23:19:47 +02:00
|
|
|
var container = contentDoc.getElementById('errorPageContainer');
|
2016-03-14 18:42:00 +01:00
|
|
|
container.innerHTML += xhtml;
|
|
|
|
|
|
|
|
// ...plus the CSS.
|
2011-06-26 23:19:47 +02:00
|
|
|
var link = contentDoc.createElement('link');
|
|
|
|
link.setAttribute('rel', 'stylesheet');
|
|
|
|
link.setAttribute('href', 'chrome://resurrect/skin/netError.css');
|
|
|
|
link.setAttribute('type', 'text/css');
|
|
|
|
link.setAttribute('media', 'all');
|
|
|
|
contentDoc.getElementsByTagName('head')[0].appendChild(link);
|
|
|
|
|
|
|
|
// Add the className that enables it, only when appropriate.
|
|
|
|
contentDoc.location.href =
|
2016-03-14 18:42:00 +01:00
|
|
|
'javascript:if ("nssBadCert" != getErrorCode()) {'
|
2011-06-26 23:19:47 +02:00
|
|
|
+ 'document.body.className += " resurrect";'
|
2016-03-14 18:42:00 +01:00
|
|
|
+ '}; void(0)';
|
2011-06-26 23:19:47 +02:00
|
|
|
|
|
|
|
// Add event listener.
|
|
|
|
contentDoc.getElementById('resurrect').addEventListener(
|
|
|
|
'click', resurrect.clickedHtml, false);
|
2016-03-14 17:38:29 +01:00
|
|
|
contentDoc.getElementById('resurrect').addEventListener(
|
|
|
|
'keypress', resurrect.clickedHtml, false);
|
2016-03-14 18:42:00 +01:00
|
|
|
};
|
|
|
|
xhr.send(null);
|
2011-06-26 23:19:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
disableButtons:function(doc) {
|
|
|
|
var bs=doc.getElementById('resurrect')
|
|
|
|
.getElementsByTagName('xul:button');
|
|
|
|
for (var i=0, b=null; b=bs[i]; i++) {
|
|
|
|
b.setAttribute('disabled', 'true');
|
|
|
|
}
|
|
|
|
},
|
2008-04-30 02:59:23 +02:00
|
|
|
|
2006-05-14 23:48:10 +02:00
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
2011-06-26 23:19:47 +02:00
|
|
|
page:function(event) {
|
|
|
|
var doc=getBrowser().contentWindow.document;
|
|
|
|
resurrect.showDialog(doc.location.href);
|
|
|
|
},
|
2006-05-14 23:48:10 +02:00
|
|
|
|
2011-06-26 23:19:47 +02:00
|
|
|
link:function(event) {
|
2016-03-14 18:42:00 +01:00
|
|
|
resurrect.showDialog(resurrect.contextUrl);
|
2011-06-26 23:19:47 +02:00
|
|
|
},
|
2006-05-14 23:48:10 +02:00
|
|
|
|
2009-04-30 19:11:32 +02:00
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
2011-06-26 23:19:47 +02:00
|
|
|
loadTarget:function() {
|
|
|
|
var pref=Components.classes['@mozilla.org/preferences-service;1']
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
var target=pref.getCharPref('extensions.resurrect.target');
|
2009-04-30 19:11:32 +02:00
|
|
|
|
2011-06-26 23:19:47 +02:00
|
|
|
document.getElementById('targetGroup').selectedItem=
|
|
|
|
document.getElementById(target);
|
|
|
|
},
|
2009-04-30 19:11:32 +02:00
|
|
|
|
2011-06-26 23:19:47 +02:00
|
|
|
saveTarget:function(el) {
|
|
|
|
var target=document.getElementById('targetGroup').selectedItem.id;
|
2009-04-30 19:11:32 +02:00
|
|
|
|
2011-06-26 23:19:47 +02:00
|
|
|
var pref=Components.classes['@mozilla.org/preferences-service;1']
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
pref.setCharPref('extensions.resurrect.target', target);
|
|
|
|
},
|
2009-04-30 19:11:32 +02:00
|
|
|
|
2006-05-14 23:48:10 +02:00
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
2011-06-26 23:19:47 +02:00
|
|
|
showDialog:function(url) {
|
|
|
|
window.openDialog(
|
|
|
|
'chrome://resurrect/content/resurrect-select-mirror.xul',
|
|
|
|
'_blank',
|
|
|
|
'modal,centerscreen,resizable=no,chrome,dependent',
|
|
|
|
getBrowser().contentWindow.document, url);
|
|
|
|
},
|
|
|
|
|
|
|
|
clickedHtml:function(event) {
|
|
|
|
if ('true'==event.target.getAttribute('disabled')) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-14 17:38:29 +01:00
|
|
|
if ('keypress' == event.type) {
|
|
|
|
if (event.target.parentNode.id != 'resurrect') return;
|
|
|
|
if (event.charCode != 32 && event.keyCode != 13) return;
|
|
|
|
}
|
2011-06-26 23:19:47 +02:00
|
|
|
|
|
|
|
return resurrect.clickHandler(
|
|
|
|
event,
|
|
|
|
event.target.ownerDocument,
|
|
|
|
event.target.ownerDocument.location.href);
|
|
|
|
},
|
|
|
|
|
|
|
|
clickedXul:function(event) {
|
|
|
|
resurrect.saveTarget(event.target);
|
|
|
|
|
|
|
|
return resurrect.clickHandler(
|
|
|
|
event,
|
|
|
|
window.arguments[0],
|
|
|
|
window.arguments[1]);
|
|
|
|
},
|
|
|
|
|
|
|
|
clickHandler:function(event, contentDoc, rawUrl) {
|
|
|
|
resurrect.disableButtons(event.target.ownerDocument);
|
|
|
|
|
|
|
|
// Run the actual code. After timeout for UI repaint.
|
|
|
|
setTimeout(
|
|
|
|
resurrect.selectMirror, 1,
|
|
|
|
event.target.getAttribute('value'),
|
|
|
|
event.target.ownerDocument,
|
|
|
|
contentDoc, rawUrl);
|
|
|
|
},
|
|
|
|
|
|
|
|
selectMirror:function(mirror, ownerDoc, contentDoc, rawUrl) {
|
|
|
|
var gotoUrl=null;
|
|
|
|
var encUrl=encodeURIComponent(rawUrl);
|
2015-08-24 18:41:19 +02:00
|
|
|
var stripUrl=rawUrl.replace(/.*?:\/\//g, "");
|
2011-06-26 23:19:47 +02:00
|
|
|
|
|
|
|
switch (mirror) {
|
|
|
|
case 'google':
|
2015-08-24 19:11:02 +02:00
|
|
|
gotoUrl='http://webcache.googleusercontent.com/search?&q=cache:'+encUrl;
|
2011-06-26 23:19:47 +02:00
|
|
|
break;
|
|
|
|
case 'googletext':
|
2015-08-24 19:11:02 +02:00
|
|
|
gotoUrl='http://webcache.googleusercontent.com/search?strip=1&q=cache::'+encUrl;
|
2011-06-26 23:19:47 +02:00
|
|
|
break;
|
|
|
|
case 'archive':
|
2016-03-14 18:26:37 +01:00
|
|
|
gotoUrl='http://wayback.archive.org/web/'+rawUrl;
|
2011-06-26 23:19:47 +02:00
|
|
|
break;
|
|
|
|
case 'bing':
|
|
|
|
var xhr=new XMLHttpRequest();
|
|
|
|
xhr.open('GET',
|
|
|
|
'http://api.search.live.net/xml.aspx'+
|
|
|
|
'?AppId=FD382E93B5ABC456C5E34C238A906CAB1E6F9875'+
|
|
|
|
'&Query=url:'+encUrl+
|
|
|
|
'&Sources=web&Web.Count=1',
|
2015-05-04 23:33:53 +02:00
|
|
|
true);
|
2011-06-26 23:19:47 +02:00
|
|
|
xhr.send(null);
|
|
|
|
|
|
|
|
try {
|
|
|
|
var c=xhr.responseXML.getElementsByTagName('web:CacheUrl');
|
|
|
|
gotoUrl=c[0].textContent;
|
|
|
|
} catch (e) {
|
|
|
|
gotoUrl='http://www.bing.com/search?q=url:'+encUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'webcitation':
|
|
|
|
gotoUrl='http://webcitation.org/query.php?url='+encUrl;
|
|
|
|
break;
|
2015-08-11 15:44:24 +02:00
|
|
|
case 'archiveis':
|
|
|
|
gotoUrl='https://archive.is/'+rawUrl;
|
|
|
|
break;
|
2013-09-19 16:17:55 +02:00
|
|
|
case 'isup':
|
2015-08-24 18:41:19 +02:00
|
|
|
gotoUrl='http://isup.me/'+stripUrl;
|
2013-09-19 16:17:55 +02:00
|
|
|
break;
|
2011-06-26 23:19:47 +02:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gotoUrl) {
|
|
|
|
if (ownerDoc.getElementById('targetTab').getAttribute('selected')) {
|
|
|
|
window.opener.openUILinkIn(gotoUrl, 'tab');
|
|
|
|
} else if (ownerDoc.getElementById('targetWin').getAttribute('selected')) {
|
|
|
|
// the setTimeout keeps focus from returning to the opener
|
|
|
|
setTimeout(function(){
|
|
|
|
window.opener.openNewWindowWith(gotoUrl, null, null);
|
|
|
|
}, 10);
|
|
|
|
} else {
|
|
|
|
contentDoc.location.assign(gotoUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('chrome://resurrect/content/resurrect-select-mirror.xul'==window.document.location) {
|
|
|
|
// setTimeout avoids errors because the window is gone
|
|
|
|
setTimeout(window.close, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-17 05:36:39 +01:00
|
|
|
};
|