1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 16:02:26 +01:00

Ignore professed short URLs after AJAX tomfoolery.

This commit is contained in:
Kris Maglione
2014-11-14 21:22:42 -08:00
parent 2acf4a6997
commit 2eb807d026
2 changed files with 46 additions and 9 deletions

View File

@@ -256,6 +256,16 @@ var Buffer = Module("Buffer", {
*/
get uri() util.newURI(this.win.location.href),
/**
* @property {nsIURI} The current top-level document's URI, sans
* fragment ID.
*/
get pageURI() {
let uri = this.uri;
uri.ref = "";
return uri;
},
/**
* @property {nsIURI} The current top-level document's URI, sans any
* fragment identifier.
@@ -702,8 +712,17 @@ var Buffer = Module("Buffer", {
util.reportError(e);
}
let sane = link => {
let a = [link.href, this.pageURI.spec];
let b = overlay.getData(link, "link-check");
return !b
|| a[0] == b[0] && a[1] == b[1]
|| a[0] != b[0] && a[1] != b[1];
}
let link = DOM("link[href][rev=canonical], \
link[href][rel=shortlink]", doc)
.filter(sane)
.attr("href");
if (link)
return hashify(link);
@@ -711,6 +730,19 @@ var Buffer = Module("Buffer", {
return null;
},
locationChanged: function locationChanged() {
// Store current URL to detect tomfoolery. Might go awry if
// links get updated before `history.pushState`, but better safe
// than whatever.
DOM("link[href][rev=canonical], \
link[href][rel=shortlink]", this.doc)
.each(elem => {
overlay.getData(elem, "link-check",
() => [elem.href, this.pageURI.spec])
});
},
/**
* Opens the appropriate context menu for *elem*.
*
@@ -2765,13 +2797,6 @@ Buffer.addPageInfoSection("s", "Security", function (verbose) {
}
});
// internal navigation doesn't currently update link[rel='shortlink']
Buffer.addURIShortener("youtube.com", (uri, doc) => {
let video = array.toObject(uri.query.split("&")
.map(p => p.split("="))).v;
return video ? util.newURI("http://youtu.be/" + video) : null;
});
// catch(e){ if (!e.stack) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); }
endModule();