1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 06:07:59 +01:00

Simplify feed auto-detection code.

--HG--
extra : rebase_source : 70d362bc1b442c52336a34038fc2facc2f460c8c
This commit is contained in:
Kris Maglione
2009-10-15 18:09:55 -04:00
parent 2ea5acb45a
commit 9ef122da08
2 changed files with 25 additions and 27 deletions

View File

@@ -105,8 +105,7 @@ function Buffer() //{{{
if (!(elem instanceof Element)) if (!(elem instanceof Element))
{ {
let doc = findScrollableWindow().document; let doc = findScrollableWindow().document;
elem = find(doc.body || elem = find(doc.body || doc.getElementsByTagName("body")[0] ||
buffer.evaluateXPath("//body || //xhtml:body", doc).snapshotItem(0) ||
doc.documentElement); doc.documentElement);
} }
return elem; return elem;
@@ -387,8 +386,8 @@ function Buffer() //{{{
buffer.focusElement(buffer.lastInputField); buffer.focusElement(buffer.lastInputField);
else else
{ {
let xpath = util.makeXPath(["input[not(@type) or @type='text' or @type='password' or @type='file']", let xpath = ["input[not(@type) or @type='text' or @type='password' or @type='file']",
"textarea[not(@disabled) and not(@readonly)]"]); "textarea[not(@disabled) and not(@readonly)]"];
let elements = [m for (m in buffer.evaluateXPath(xpath))].filter(function (match) { let elements = [m for (m in buffer.evaluateXPath(xpath))].filter(function (match) {
let computedStyle = util.computedStyle(match); let computedStyle = util.computedStyle(match);
@@ -778,12 +777,9 @@ function Buffer() //{{{
var type = data.type && data.type.toLowerCase(); var type = data.type && data.type.toLowerCase();
type = type.replace(/^\s+|\s*(?:;.*)?$/g, ""); type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");
isFeed = ["application/rss+xml", "application/atom+xml"].indexOf(type) >= 0; isFeed = ["application/rss+xml", "application/atom+xml"].indexOf(type) >= 0 ||
if (!isFeed) // really slimy: general XML types with magic letters in the title
{ type in feedTypes && /\brss\b/i.test(data.title);
// really slimy: general XML types with magic letters in the title
isFeed = type in feedTypes && /\brss\b/i.test(data.title);
}
} }
if (isFeed) if (isFeed)
@@ -805,25 +801,17 @@ function Buffer() //{{{
return isFeed; return isFeed;
} }
// put feeds rss into pageFeeds[]
let nFeed = 0; let nFeed = 0;
for (let [, link] in Iterator(doc.getElementsByTagName("link"))) for (let link in buffer.evaluateXPath(["link[@href and (@rel='feed' or (@rel='alternate' and @type))]"], doc))
{ {
if (!link.href) let rel = link.rel.toLowerCase();
return; let feed = { title: link.title, href: link.href, type: link.type || "" };
if (isValidFeed(feed, doc.nodePrincipal, rel == "feed"))
let rel = link.rel && link.rel.toLowerCase();
if (rel == "feed" || (link.type && rel == "alternate"))
{ {
let feed = { title: link.title, href: link.href, type: link.type || "" }; nFeed++;
if (isValidFeed(feed, doc.nodePrincipal, rel == "feed")) let type = feedTypes[feed.type] || "RSS";
{ if (verbose)
nFeed++; yield [feed.title, template.highlightURL(feed.href, true) + <span class="extra-info">&#xa0;({type})</span>];
let type = feedTypes[feed.type] || "RSS";
if (verbose)
yield [feed.title, template.highlightURL(feed.href, true) + <span class="extra-info">&#xa0;({type})</span>];
}
} }
} }
@@ -1043,6 +1031,8 @@ function Buffer() //{{{
doc = window.content.document; doc = window.content.document;
if (!elem) if (!elem)
elem = doc; elem = doc;
if (util.isArray(expression))
expression = util.makeXPath(expression);
let result = doc.evaluate(expression, elem, let result = doc.evaluate(expression, elem,
function lookupNamespaceURI(prefix) function lookupNamespaceURI(prefix)
@@ -1535,7 +1525,7 @@ function Buffer() //{{{
if (bookmarks.isBookmarked(this.URL)) if (bookmarks.isBookmarked(this.URL))
info += ", bookmarked"; info += ", bookmarked";
let pageInfoText = <>"{file}" [{info}] {title}</>; let pageInfoText = <>{file.quote()} [{info}] {title}</>;
liberator.echo(pageInfoText, commandline.FORCE_SINGLELINE); liberator.echo(pageInfoText, commandline.FORCE_SINGLELINE);
return; return;
} }

View File

@@ -11,6 +11,14 @@ const NS = Namespace("liberator", "http://vimperator.org/namespaces/liberator");
default xml namespace = XHTML; default xml namespace = XHTML;
const util = { //{{{ const util = { //{{{
/**
* Returns true if its argument is an Array object, regardless
* of which context it comes from.
*
* @param {object} obj
*/
isArray: function isArray(obj) Object.prototype.toString.call(obj) == "[object Array]",
/** /**
* Returns a shallow copy of <b>obj</b>. * Returns a shallow copy of <b>obj</b>.
* *