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

View File

@@ -11,6 +11,14 @@ const NS = Namespace("liberator", "http://vimperator.org/namespaces/liberator");
default xml namespace = XHTML;
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>.
*