2006-05-14 23:48:10 +02:00
|
|
|
var resurrect={
|
2006-05-15 00:37:23 +02:00
|
|
|
|
|
|
|
mirrors:[
|
|
|
|
{name:'CoralCDN', id:'coralcdn'},
|
|
|
|
{name:'Google Cache', id:'google'},
|
2006-05-15 01:27:39 +02:00
|
|
|
{name:'The Internet Archive', id:'archive'},
|
2006-05-15 01:09:01 +02:00
|
|
|
{name:'MSN Cache', id:'msn'},
|
2006-05-15 01:27:39 +02:00
|
|
|
{name:'Yahoo! Cache', id:'yahoo'}
|
2006-05-15 00:37:23 +02:00
|
|
|
],
|
|
|
|
|
|
|
|
originalDoc:null,
|
2006-05-20 23:04:35 +02:00
|
|
|
disabled:false,
|
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
|
|
|
|
|
|
|
window.document.getElementById("appcontent").addEventListener(
|
|
|
|
'DOMContentLoaded', resurrect.attachClickEvent, false
|
|
|
|
);
|
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);
|
|
|
|
},
|
|
|
|
|
2006-07-18 21:02:10 +02:00
|
|
|
attachClickEvent:function(event) {
|
2006-07-04 16:40:46 +02:00
|
|
|
resurrect.disabled=false;
|
|
|
|
|
2006-07-18 21:02:10 +02:00
|
|
|
var contentDoc=event.target;
|
|
|
|
if (contentDoc.documentURI.match(/^about:neterror/)) {
|
|
|
|
contentDoc.getElementById('mirror').addEventListener(
|
2006-10-08 19:49:45 +02:00
|
|
|
'click', resurrect.clickedHtml, false
|
2006-05-17 04:30:57 +02:00
|
|
|
);
|
|
|
|
try {
|
|
|
|
// because this button isn't always there
|
2006-07-18 21:02:10 +02:00
|
|
|
contentDoc.getElementById('mirrorSelect').addEventListener(
|
2006-10-08 19:49:45 +02:00
|
|
|
'click', resurrect.clickedHtml, false
|
2006-05-17 04:30:57 +02:00
|
|
|
);
|
2006-05-18 01:29:33 +02:00
|
|
|
} catch (e) { }
|
2006-05-17 04:30:57 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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 {
|
2006-05-15 01:27:39 +02:00
|
|
|
while (el && el.tagName && 'A'!=el.tagName) {
|
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;
|
|
|
|
},
|
|
|
|
|
2006-06-18 02:41:53 +02:00
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
|
|
|
selectTab:function(aTab) {
|
|
|
|
with (gBrowser) {
|
|
|
|
selectedTab=aTab;
|
|
|
|
mTabBox.selectedPanel=getBrowserForTab(mCurrentTab).parentNode;
|
|
|
|
mCurrentTab.selected = true;
|
|
|
|
updateCurrentBrowser();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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) {
|
|
|
|
resurrect.selectMirror(
|
|
|
|
event.target.ownerDocument,
|
|
|
|
event.target.ownerDocument,
|
|
|
|
event.target.ownerDocument.location.href
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
clickedXul:function(event) {
|
|
|
|
resurrect.selectMirror(
|
|
|
|
event.target.ownerDocument,
|
|
|
|
window.arguments[0],
|
|
|
|
window.arguments[1]
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
selectMirror:function(ownerDoc, contentDoc, rawUrl) {
|
2006-05-17 04:30:57 +02:00
|
|
|
var listbox=ownerDoc.getElementById('mirror');
|
2006-05-20 23:04:35 +02:00
|
|
|
if (resurrect.disabled) return false;
|
|
|
|
resurrect.disabled=true;
|
2006-05-17 04:30:57 +02:00
|
|
|
|
|
|
|
var gotoUrl=null;
|
2006-05-15 00:37:23 +02:00
|
|
|
var encUrl=encodeURIComponent(rawUrl);
|
|
|
|
|
|
|
|
switch (listbox.value) {
|
|
|
|
case 'coralcdn':
|
|
|
|
gotoUrl=rawUrl.substring(0, 8)+
|
|
|
|
rawUrl.substring(8).replace(/\//, '.nyud.net:8080/');
|
|
|
|
break;
|
2006-05-15 00:38:47 +02:00
|
|
|
case 'google':
|
|
|
|
gotoUrl='http://www.google.com/search?q=cache:'+encUrl
|
|
|
|
break;
|
2006-12-23 17:37:01 +01:00
|
|
|
case 'googletext':
|
|
|
|
gotoUrl='http://www.google.com/search?strip=1&q=cache:'+encUrl
|
|
|
|
break;
|
2006-05-15 00:41:06 +02:00
|
|
|
case 'archive':
|
|
|
|
gotoUrl='http://web.archive.org/web/*/'+rawUrl
|
2006-05-15 01:09:01 +02:00
|
|
|
break;
|
|
|
|
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;
|
|
|
|
case 'msn':
|
2006-05-19 02:14:34 +02:00
|
|
|
var xmlUrl=rawUrl.replace('&', '&');
|
|
|
|
var soapBody='<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd"><SOAP-ENV:Body><ns1:Search xmlns:ns1="http://testuri.org"><Request><AppID xsi:type="xsd:string">FD382E93B5ABC456C5E34C238A906CAB2DEEB5D6</AppID><Query xsi:type="xsd:string">'+xmlUrl+'</Query><CultureInfo xsi:type="xsd:string">en-US</CultureInfo><SafeSearch xsi:type="xsd:string">Off</SafeSearch><Requests><SourceRequest><Source xsi:type="xsd:string">Web</Source><Offset xsi:type="xsd:int">0</Offset><Count xsi:type="xsd:int">1</Count><ResultFields xsi:type="xsd:string">All</ResultFields></SourceRequest></Requests></Request></ns1:Search></SOAP-ENV:Body></SOAP-ENV:Envelope>';
|
2006-05-15 01:27:39 +02:00
|
|
|
|
|
|
|
var xhr=new XMLHttpRequest();
|
2006-05-19 02:14:34 +02:00
|
|
|
xhr.open('POST', 'http://soap.search.msn.com/webservices.asmx', false);
|
|
|
|
xhr.setRequestHeader('Content-Type', 'text/xml; charset=ISO-8859-1');
|
|
|
|
xhr.setRequestHeader('SOAPAction', '""');
|
|
|
|
xhr.send(soapBody);
|
2006-05-15 01:27:39 +02:00
|
|
|
|
|
|
|
try {
|
2006-05-19 02:14:34 +02:00
|
|
|
var c=xhr.responseXML.getElementsByTagName('CacheUrl');
|
|
|
|
gotoUrl=c[0].textContent;
|
|
|
|
} catch (e) {
|
|
|
|
gotoUrl='http://search.msn.com/results.aspx?q='+encUrl;
|
2006-05-15 01:27:39 +02:00
|
|
|
}
|
|
|
|
|
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')) {
|
|
|
|
var newTab=window.opener.gBrowser.addTab(gotoUrl);
|
|
|
|
|
|
|
|
//replicate broken focus-new-tab functionality
|
|
|
|
var prefServ=Components.classes['@mozilla.org/preferences-service;1']
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
if (!prefServ.getBoolPref('browser.tabs.loadInBackground')) {
|
|
|
|
window.opener.resurrect.selectTab(newTab);
|
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
2006-05-17 04:30:57 +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-14 23:48:10 +02:00
|
|
|
}
|
|
|
|
|
2006-05-15 00:37:23 +02:00
|
|
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
|
|
|
2006-05-14 23:48:10 +02:00
|
|
|
}//end var resurrect
|
|
|
|
|
2006-05-15 00:37:23 +02:00
|
|
|
if ('undefined'!=typeof gBrowser) {
|
|
|
|
window.addEventListener('load', resurrect.onLoad, false);
|
|
|
|
}
|