2006-05-14 23:48:10 +02:00
|
|
|
var resurrect={
|
2006-05-15 00:37:23 +02:00
|
|
|
|
|
|
|
originalDoc:null,
|
2006-05-14 23:48:10 +02:00
|
|
|
|
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
|
|
|
onLoad:function() {
|
|
|
|
window.removeEventListener('load', resurrect.onLoad, false);
|
|
|
|
|
|
|
|
document.getElementById('contentAreaContextMenu')
|
|
|
|
.addEventListener('popupshowing', resurrect.toggleContextItems, false);
|
2006-05-17 04:30:57 +02:00
|
|
|
|
2008-04-29 02:29:38 +02:00
|
|
|
window.document.getElementById('appcontent').addEventListener(
|
2011-01-17 05:26:58 +01:00
|
|
|
'DOMContentLoaded', resurrect.contentDomLoad, false
|
2006-05-17 04:30:57 +02:00
|
|
|
);
|
2006-05-14 23:48:10 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleContextItems:function(event) {
|
|
|
|
resurrect.clickTarget=event.target;
|
|
|
|
|
2006-05-15 01:09:01 +02:00
|
|
|
var onDocument=!(
|
|
|
|
gContextMenu.isContentSelected || gContextMenu.onTextInput ||
|
|
|
|
gContextMenu.onLink || gContextMenu.onImage
|
2006-05-14 23:48:10 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
document.getElementById('resurrect-page-context')
|
|
|
|
.setAttribute('hidden', !onDocument);
|
|
|
|
document.getElementById('resurrect-link-context')
|
|
|
|
.setAttribute('hidden', !gContextMenu.onLink);
|
|
|
|
},
|
|
|
|
|
2011-01-17 05:26:58 +01:00
|
|
|
contentDomLoad:function(event) {
|
2006-07-18 21:02:10 +02:00
|
|
|
var contentDoc=event.target;
|
2008-04-30 02:59:23 +02:00
|
|
|
var contentWin=contentDoc.defaultView;
|
|
|
|
|
2006-07-18 21:02:10 +02:00
|
|
|
if (contentDoc.documentURI.match(/^about:neterror/)) {
|
2011-01-17 05:26:58 +01:00
|
|
|
// Inject our content...
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('GET', 'chrome://resurrect/content/netError.xhtml', false);
|
|
|
|
xhr.send(null);
|
|
|
|
var resurrectFieldset = xhr.responseXML.getElementById('resurrect');
|
|
|
|
var newFieldset = contentDoc.adoptNode(resurrectFieldset);
|
|
|
|
var container = contentDoc.getElementById('errorPageContainer');
|
|
|
|
container.appendChild(newFieldset);
|
|
|
|
// ...including the CSS.
|
|
|
|
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 =
|
|
|
|
'javascript:if ("nssBadCert" != getErrorCode()) {'
|
|
|
|
+ 'document.body.className += " resurrect";'
|
|
|
|
+ '}; void(0)';
|
|
|
|
|
|
|
|
// Add event listener.
|
2008-04-29 02:29:38 +02:00
|
|
|
contentDoc.getElementById('resurrect').addEventListener(
|
2006-10-08 19:49:45 +02:00
|
|
|
'click', resurrect.clickedHtml, false
|
2006-05-17 04:30:57 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-04-30 02:59:23 +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');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2006-05-14 23:48:10 +02:00
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
2006-05-15 01:27:39 +02:00
|
|
|
page:function(event) {
|
|
|
|
var doc=getBrowser().contentWindow.document;
|
|
|
|
resurrect.showDialog(doc.location.href);
|
2006-05-14 23:48:10 +02:00
|
|
|
},
|
|
|
|
|
2006-05-15 01:27:39 +02:00
|
|
|
link:function(event) {
|
2006-05-14 23:48:10 +02:00
|
|
|
var el=document.popupNode;
|
|
|
|
|
|
|
|
try {
|
2011-01-17 04:18:48 +01:00
|
|
|
while (el && el.tagName && 'A'!=el.tagName.toUpperCase()) {
|
2006-05-14 23:48:10 +02:00
|
|
|
el=el.parentNode;
|
|
|
|
}
|
2006-05-15 01:27:39 +02:00
|
|
|
resurrect.showDialog(el.href);
|
2006-05-14 23:48:10 +02:00
|
|
|
} catch (e) { }
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2009-04-30 19:11:32 +02:00
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
|
|
|
loadTarget:function() {
|
|
|
|
var pref=Components.classes['@mozilla.org/preferences-service;1']
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
var target=pref.getCharPref('extensions.resurrect.target');
|
|
|
|
|
|
|
|
document.getElementById('targetGroup').selectedItem=
|
|
|
|
document.getElementById(target);
|
|
|
|
},
|
|
|
|
|
|
|
|
saveTarget:function(el) {
|
|
|
|
var target=document.getElementById('targetGroup').selectedItem.id;
|
|
|
|
|
|
|
|
var pref=Components.classes['@mozilla.org/preferences-service;1']
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
pref.setCharPref('extensions.resurrect.target', target);
|
|
|
|
},
|
|
|
|
|
2006-05-14 23:48:10 +02:00
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
|
|
|
showDialog:function(url) {
|
2006-05-15 00:37:23 +02:00
|
|
|
resurrect.originalDoc=getBrowser().contentWindow.document;
|
|
|
|
|
|
|
|
window.openDialog(
|
|
|
|
'chrome://resurrect/content/resurrect-select-mirror.xul',
|
|
|
|
'_blank',
|
2006-08-25 02:44:49 +02:00
|
|
|
'modal,centerscreen,resizable=no,chrome,dependent',
|
|
|
|
getBrowser().contentWindow.document, url
|
2006-05-15 00:37:23 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2006-10-08 19:49:45 +02:00
|
|
|
clickedHtml:function(event) {
|
2008-04-30 02:59:23 +02:00
|
|
|
if ('true'==event.target.getAttribute('disabled')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-28 16:34:28 +02:00
|
|
|
return resurrect.clickHandler(
|
2008-04-29 02:29:38 +02:00
|
|
|
event,
|
2006-10-08 19:49:45 +02:00
|
|
|
event.target.ownerDocument,
|
|
|
|
event.target.ownerDocument.location.href
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
clickedXul:function(event) {
|
2009-04-30 19:11:32 +02:00
|
|
|
resurrect.saveTarget(event.target);
|
|
|
|
|
2007-05-28 16:34:28 +02:00
|
|
|
return resurrect.clickHandler(
|
2008-04-29 02:29:38 +02:00
|
|
|
event,
|
2006-10-08 19:49:45 +02:00
|
|
|
window.arguments[0],
|
|
|
|
window.arguments[1]
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2008-04-30 02:59:23 +02:00
|
|
|
clickHandler:function(event, contentDoc, rawUrl) {
|
|
|
|
resurrect.disableButtons(event.target.ownerDocument);
|
2007-05-28 16:34:28 +02:00
|
|
|
|
|
|
|
// Run the actual code. After timeout for UI repaint.
|
2008-04-29 02:29:38 +02:00
|
|
|
setTimeout(
|
|
|
|
resurrect.selectMirror, 1,
|
2011-01-17 04:18:48 +01:00
|
|
|
event.target.getAttribute('value'),
|
2008-04-30 02:59:23 +02:00
|
|
|
event.target.ownerDocument,
|
|
|
|
contentDoc, rawUrl
|
2008-04-29 02:29:38 +02:00
|
|
|
);
|
2007-05-28 16:34:28 +02:00
|
|
|
},
|
|
|
|
|
2008-04-29 02:29:38 +02:00
|
|
|
selectMirror:function(mirror, ownerDoc, contentDoc, rawUrl) {
|
2006-05-17 04:30:57 +02:00
|
|
|
var gotoUrl=null;
|
2006-05-15 00:37:23 +02:00
|
|
|
var encUrl=encodeURIComponent(rawUrl);
|
2008-04-29 03:14:22 +02:00
|
|
|
var xmlUrl=rawUrl.replace('&', '&');
|
2006-05-15 00:37:23 +02:00
|
|
|
|
2008-04-29 02:29:38 +02:00
|
|
|
switch (mirror) {
|
2006-05-15 00:37:23 +02:00
|
|
|
case 'coralcdn':
|
|
|
|
gotoUrl=rawUrl.substring(0, 8)+
|
2008-07-25 02:06:14 +02:00
|
|
|
rawUrl.substring(8).replace(/\//, '.nyud.net/');
|
2006-05-15 00:37:23 +02:00
|
|
|
break;
|
2006-05-15 00:38:47 +02:00
|
|
|
case 'google':
|
2011-03-05 15:45:26 +01:00
|
|
|
gotoUrl='http://www.google.com/search?q=cache:'+encUrl;
|
2006-05-15 00:38:47 +02:00
|
|
|
break;
|
2006-12-23 17:37:01 +01:00
|
|
|
case 'googletext':
|
2011-03-05 15:45:26 +01:00
|
|
|
gotoUrl='http://www.google.com/search?strip=1&q=cache:'+encUrl;
|
2006-12-23 17:37:01 +01:00
|
|
|
break;
|
2006-05-15 00:41:06 +02:00
|
|
|
case 'archive':
|
2011-03-05 15:45:26 +01:00
|
|
|
gotoUrl='http://web.archive.org/web/*/'+rawUrl;
|
2006-05-15 01:09:01 +02:00
|
|
|
break;
|
2011-03-05 16:30:33 +01:00
|
|
|
case 'waybackmachine':
|
|
|
|
gotoUrl='http://waybackmachine.org/*/'+rawUrl;
|
|
|
|
break;
|
2006-05-15 01:09:01 +02:00
|
|
|
case 'yahoo':
|
|
|
|
var xhr=new XMLHttpRequest();
|
|
|
|
xhr.open('GET',
|
|
|
|
'http://api.search.yahoo.com/WebSearchService/V1/'+
|
|
|
|
'webSearch?appid=firefox-resurrect&query='+encUrl+'&results=1',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
xhr.send(null);
|
|
|
|
|
|
|
|
try {
|
|
|
|
var c=xhr.responseXML.getElementsByTagName('Cache');
|
|
|
|
gotoUrl=c[0].firstChild.textContent;
|
|
|
|
} catch (e ) {
|
|
|
|
gotoUrl='http://search.yahoo.com/search?p='+encUrl;
|
|
|
|
}
|
|
|
|
|
2006-05-15 01:27:39 +02:00
|
|
|
break;
|
2009-09-06 21:08:02 +02:00
|
|
|
case 'bing':
|
2006-05-15 01:27:39 +02:00
|
|
|
var xhr=new XMLHttpRequest();
|
2009-09-06 21:08:02 +02:00
|
|
|
xhr.open('GET',
|
|
|
|
'http://api.search.live.net/xml.aspx'+
|
|
|
|
'?AppId=FD382E93B5ABC456C5E34C238A906CAB1E6F9875'+
|
|
|
|
'&Query=url:'+encUrl+
|
|
|
|
'&Sources=web&Web.Count=1',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
xhr.send(null);
|
2006-05-15 01:27:39 +02:00
|
|
|
|
|
|
|
try {
|
2009-09-06 21:08:02 +02:00
|
|
|
var c=xhr.responseXML.getElementsByTagName('web:CacheUrl');
|
2006-05-19 02:14:34 +02:00
|
|
|
gotoUrl=c[0].textContent;
|
|
|
|
} catch (e) {
|
2009-09-06 21:08:02 +02:00
|
|
|
gotoUrl='http://www.bing.com/search?q=url:'+encUrl;
|
2006-05-15 01:27:39 +02:00
|
|
|
}
|
|
|
|
|
2008-04-29 03:14:22 +02:00
|
|
|
break;
|
|
|
|
case 'gigablast':
|
|
|
|
var apiUrl=[
|
|
|
|
'http://feed.gigablast.com/search',
|
2008-04-29 16:56:10 +02:00
|
|
|
'?q=url:', encUrl,
|
2008-04-29 03:14:22 +02:00
|
|
|
'&site=', (rawUrl.match(/:\/\/([^/]+)/)[1]),
|
|
|
|
'&n=1&ns=0&raw=9&bq=0&nrt=0'
|
|
|
|
].join('');
|
|
|
|
|
|
|
|
var xhr=new XMLHttpRequest();
|
|
|
|
xhr.open('GET', apiUrl, false);
|
|
|
|
xhr.send(null);
|
|
|
|
|
|
|
|
try {
|
|
|
|
var docId=xhr.responseXML
|
|
|
|
.getElementsByTagName('docId')[0].textContent;
|
|
|
|
gotoUrl='http://www.gigablast.com/index.php'
|
|
|
|
+'?page=get&ih=1&ibh=1&cas=0&d='
|
|
|
|
+docId;
|
|
|
|
} catch (e) {
|
2008-04-30 03:38:12 +02:00
|
|
|
gotoUrl='http://www.gigablast.com/index.php?q=url:'+encUrl;
|
2008-04-29 03:14:22 +02:00
|
|
|
}
|
|
|
|
|
2008-04-30 03:26:26 +02:00
|
|
|
break;
|
|
|
|
case 'webcitation':
|
|
|
|
gotoUrl='http://webcitation.org/query.php?url='+encUrl;
|
2006-05-17 04:30:57 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
2006-05-15 00:41:06 +02:00
|
|
|
break;
|
2006-05-15 00:37:23 +02:00
|
|
|
}
|
2006-06-18 02:41:53 +02:00
|
|
|
|
2006-05-15 00:37:23 +02:00
|
|
|
if (gotoUrl) {
|
2006-06-18 02:41:53 +02:00
|
|
|
if (ownerDoc.getElementById('targetTab').getAttribute('selected')) {
|
2008-06-28 02:51:02 +02:00
|
|
|
window.opener.openUILinkIn(gotoUrl, 'tab');
|
2006-06-18 02:41:53 +02:00
|
|
|
} 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);
|
|
|
|
}
|
2006-05-15 00:37:23 +02:00
|
|
|
|
2008-04-29 02:29:38 +02:00
|
|
|
if ('chrome://resurrect/content/resurrect-select-mirror.xul'==window.document.location) {
|
|
|
|
// setTimeout avoids errors because the window is gone
|
|
|
|
setTimeout(window.close, 0);
|
|
|
|
}
|
2006-05-17 04:30:57 +02:00
|
|
|
}
|
2006-05-14 23:48:10 +02:00
|
|
|
}
|
2011-01-17 05:36:39 +01:00
|
|
|
};
|