1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-04 12:34:11 +01:00

Add short URL to g<C-g>. Also fix bugs.

This commit is contained in:
Kris Maglione
2013-03-17 14:25:21 -07:00
parent c3e430ab39
commit 1f1b7e06ec
2 changed files with 69 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ defineModule("buffer", {
});
lazyRequire("bookmarkcache", ["bookmarkcache"]);
lazyRequire("contexts", ["Group"]);
lazyRequire("io", ["io"]);
lazyRequire("finder", ["RangeFind"]);
lazyRequire("overlay", ["overlay"]);
@@ -575,6 +576,30 @@ var Buffer = Module("Buffer", {
*/
get selectionController() util.selectionController(this.focusedFrame),
/**
* @property {string|null} The canonical short URL for the current
* document.
*/
get shortURL() {
let { uri, doc } = this;
for each (let shortener in Buffer.uriShorteners)
try {
let shortened = shortener(uri, doc);
if (shortened)
return shortened.spec;
}
catch (e) {
util.reportError(e);
}
let link = DOM("link[href]:-moz-any([rev=canonical], [rel=shortlink])", doc);
if (link)
return link.attr("href");
return null;
},
/**
* Opens the appropriate context menu for *elem*.
*
@@ -1176,12 +1201,20 @@ var Buffer = Module("Buffer", {
let self = this;
let uri = this.uri;
if (services.has("contentPrefs") && prefs.get("browser.zoom.siteSpecific"))
services.contentPrefs.getPref(uri, "dactyl.content.full-zoom", function (val) {
if (services.has("contentPrefs") && prefs.get("browser.zoom.siteSpecific")) {
let callback = function (val) {
if (val != null && uri.equals(self.uri) && val != prefs.get("browser.zoom.full"))
[self.contentViewer.textZoom, self.contentViewer.fullZoom] =
[self.contentViewer.fullZoom, self.contentViewer.textZoom];
}, sanitizer.getContext(this.win));
}
// God damn it.
if (util.haveGecko("19.0a1"))
services.contentPrefs.getPref(uri, "dactyl.content.full-zoom",
sanitizer.getContext(this.win), callback);
else
services.contentPrefs.getPref(uri, "dactyl.content.full-zoom",
callback);
}
}),
/**
@@ -1240,6 +1273,27 @@ var Buffer = Module("Buffer", {
this.pageInfo[option] = Buffer.PageInfo(option, title, func);
},
uriShorteners: [],
/**
* Adds a new URI shortener for documents matching the given filter.
*
* @param {string|function(URI, Document):boolean} filter A site filter
* string or a function which accepts a URI and a document and
* returns true if it can shorten the document's URI.
* @param {function(URI, Document):URI} shortener Returns a shortened
* URL for the given URI and document.
*/
addURIShortener: function addURIShortener(filter, shortener) {
if (isString(filter))
filter = Group.compileFilter(filter);
this.uriShorteners.push(function uriShortener(uri, doc) {
if (filter(uri, doc))
return shortener(uri, doc);
});
},
Scrollable: function Scrollable(elem) {
if (elem instanceof Ci.nsIDOMElement)
return elem;
@@ -1885,8 +1939,7 @@ var Buffer = Module("Buffer", {
uri.query = uri.query.replace(/(?:^|&)utm_[^&]+/g, "")
.replace(/^&/, "");
let link = DOM("link[href][rev=canonical], link[href][rel=shortlink]", doc);
let url = link.length && options.get("yankshort").getKey(uri) ? link.attr("href") : uri.spec;
let url = options.get("yankshort").getKey(uri) && buffer.shortURL || uri.spec;
dactyl.clipboardWrite(url, true);
});
@@ -2509,6 +2562,10 @@ Buffer.addPageInfoSection("g", "General Info", function (verbose) {
yield ["Title", doc.title];
yield ["URL", template.highlightURL(doc.location.href, true)];
let { shortURL } = this;
if (shortURL)
yield ["Short URL", template.highlightURL(shortURL, true)];
let ref = "referrer" in doc && doc.referrer;
if (ref)
yield ["Referrer", template.highlightURL(ref, true)];

View File

@@ -290,6 +290,13 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
}
},
/**
* Returns a load context for the given thing, to be used with
* interfaces needing one for per-window private browsing support.
*
* @param {Window|Document|Node} thing The thing for which to return
* a load context.
*/
getContext: function getContext(thing) {
if (!Ci.nsILoadContext)
return null;