[Vimperator] pageInfo patch
calmar
mac at calmar.ws
Sun Nov 4 17:23:30 PST 2007
Hi all,
Not yet finished (even so should work), but since there are quite
some differences, I thought it's good to commit it...
(I'm using two helper function, and put them into private, if that
is ok)
Cheers
marco
--
(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
-------------- next part --------------
Index: options.js
===================================================================
RCS file: /cvs/vimperator/src/content/options.js,v
retrieving revision 1.24
diff -u -r1.24 options.js
--- options.js 3 Nov 2007 08:51:07 -0000 1.24
+++ options.js 5 Nov 2007 01:18:15 -0000
@@ -594,7 +594,7 @@
"</ul>" +
"The order matters",
default_value: "gm",
- validator: function (value) { if (/[^gm]/.test(value) || value.length > 2 ||
+ validator: function (value) { if (/[^grm]/.test(value) || value.length > 3 ||
value.length < 1) return false; else return true; }
}
));
Index: commands.js
===================================================================
RCS file: /cvs/vimperator/src/content/commands.js,v
retrieving revision 1.48
diff -u -r1.48 commands.js
--- commands.js 2 Nov 2007 10:05:51 -0000 1.48
+++ commands.js 5 Nov 2007 01:18:17 -0000
@@ -1495,8 +1508,8 @@
addDefaultCommand(new vimperator.Command(["pa[geinfo]"],
function () { vimperator.buffer.pageInfo(true); },
{
- short_help: "Show general and/or meta-content site informations",
- help: "Show general and/or meta-content site informations"
+ short_help: "Show various page informations (see :help 'pageinfo')",
+ help: "Show various page informations (see :help 'pageinfo')"
}
));
addDefaultCommand(new vimperator.Command(["pc[lose]"],
Index: buffers.js
===================================================================
RCS file: /cvs/vimperator/src/content/buffers.js,v
retrieving revision 1.20
diff -u -r1.20 buffers.js
--- buffers.js 1 Nov 2007 13:31:53 -0000 1.20
+++ buffers.js 5 Nov 2007 01:18:18 -0000
@@ -125,6 +125,84 @@
win.scrollTo(h, v);
}
+// const feedTypes = {
+// "application/rss+xml": gBundle.getString("feedRss"),
+// "application/atom+xml": gBundle.getString("feedAtom"),
+// "text/xml": gBundle.getString("feedXML"),
+// "application/xml": gBundle.getString("feedXML"),
+// "application/rdf+xml": gBundle.getString("feedXML")
+// };
+
+ function isValidFeed(aData, aPrincipal, aIsFeed)
+ {
+ if (!aData || !aPrincipal)
+ return false;
+
+ if (!aIsFeed) {
+ var type = aData.type && aData.type.toLowerCase();
+ type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");
+
+ aIsFeed = (type == "application/rss+xml" ||
+ type == "application/atom+xml");
+
+ if (!aIsFeed) {
+ // really slimy: general XML types with magic letters in the title
+ const titleRegex = /(^|\s)rss($|\s)/i;
+ aIsFeed = ((type == "text/xml" || type == "application/rdf+xml" ||
+ type == "application/xml") && titleRegex.test(aData.title));
+ }
+ }
+
+ if (aIsFeed) {
+ try {
+ urlSecurityCheck(aData.href, aPrincipal,
+ Components.interfaces.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
+ }
+ catch(ex) {
+ aIsFeed = false;
+ }
+ }
+
+ if (type)
+ aData.type = type;
+
+ return aIsFeed;
+ }
+
+ function pageInfoTextSetup(data)
+ {
+ var tmpS1 = "<table><tr><td class='hl-Title' style='font-weight: bold;' colspan='2'>";
+ var tmpS2 = "</td></tr>";
+ var tmpS3 = "<tr><td style='font-weight: bold;'> ";
+ var tmpS4 = ": </td><td>";
+ var tmpS5 = "</table>";
+ var newLine = "";
+ var joinedText = "";
+ var arrLength = data.length;
+
+ joinedText += tmpS1 + data[arrLength -1][0] + tmpS2;
+
+ if (arrLength - 1)
+ {
+ for (var i = 0; i < arrLength - 1 ; i++)
+ joinedText += tmpS3 + data[i][0] + tmpS4 + data[i][1] + tmpS2;
+ }
+ else
+ {
+ joinedText += "<tr><td colspan='2'> (" + data[arrLength - 1][1] + ")</td></tr>";
+ }
+
+ joinedText += tmpS5;
+ return joinedText;
+ }
+
+
+ function hiUrl(text)
+ {
+ return '<a class="hl-URL" href="' + text + '">' + text + '</a>';
+ }
+
+
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
@@ -495,7 +573,12 @@
this.pageInfo = function(verbose)
{
- // to get the file size later (from pageInfo.js) (setup cacheEntryDescriptor)
+
+ var pageGeneral = []; // keeps general infos
+ var pageRss = [];
+ var pageMeta = []; // keeps meta infos
+
+ // get file size
const nsICacheService = Components.interfaces.nsICacheService;
const ACCESS_READ = Components.interfaces.nsICache.ACCESS_READ;
const cacheService = Components.classes["@mozilla.org/network/cache-service;1"].getService(nsICacheService);
@@ -517,6 +600,54 @@
catch (ex2) { }
}
+ var pageSize = '';
+ if (cacheEntryDescriptor)
+ {
+ var pageSize = cacheEntryDescriptor.dataSize;
+ var bytes = pageSize + '';
+ for (var u = bytes.length - 3; u > 0; u -= 3) // make a 1400 -> 1'400
+ bytes = bytes.slice(0, u) + "," + bytes.slice(u, bytes.length);
+
+ var kbytes = (Math.round(pageSize / 1024 * 100) / 100);
+ for (var u = kbytes.length - 3; u > 0; u -= 3) // make a 1400 -> 1'400
+ bytes = kbytes.slice(0, u) + "," + kbytes.slice(u, kbytes.length);
+
+ if (verbose)
+ pageGeneral.push(["File Size", kbytes + "KB (" + bytes + " bytes)"]);
+ else
+ pageSize = kbytes + "KB";
+ }
+
+ // put feeds rss into pageRss[]
+ var linkNodes = window.content.document.getElementsByTagName("link");
+ var length = linkNodes.length;
+ for (var i = 0; i < length; i++)
+ {
+ var link = linkNodes[i];
+ if (!link.href)
+ continue;
+
+ var rel = link.rel && link.rel.toLowerCase();
+ var rels = {};
+ if (rel)
+ {
+ for each (let relVal in rel.split(/\s+/))
+ rels[relVal] = true;
+ }
+
+ if (rels.feed || (link.type && rels.alternate && !rels.stylesheet))
+ {
+ var feed = { title: link.title, href: link.href, type: link.type || "" };
+ if (isValidFeed(feed, window.content.document.nodePrincipal, rels.feed))
+ {
+// var type = feedTypes[feed.type] || feedTypes["application/rss+xml"]; // TODO: dig into that..
+ var type = feed.type || "application/rss+xml";
+ pageRss.push([feed.title, hiUrl(feed.href)]);
+ }
+ }
+ }
+
+ // Ctrl-g single line output
if (!verbose)
{
// TODO: strip off any component after &
@@ -526,40 +657,38 @@
var title = window.content.document.title || "[No Title]";
- if (cacheEntryDescriptor)
- var pageSize = Math.round(cacheEntryDescriptor.dataSize / 1024 * 100) / 100 + "KB";
-
var lastmod = window.content.document.lastModified.slice(0, -3);
+ if (pageSize)
+ lastmod = ", " + lastmod;
- var pageInfoText = '"' + file + '" [' + pageSize + ", " + lastmod + "] " + title;
+ var countRss = '';
+ if (pageRss.length)
+ {
+ countRss = ", " + pageRss.length + " RSS";
+ countRss += (pageRss.length > 1) ? "'s" : "";
+ }
+
+ var pageInfoText = '"' + file + '" [' + pageSize + lastmod + countRss + "] " + title;
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_SINGLELINE);
return;
}
- var pageGeneral = []; // keeps general infos
- var pageMeta = []; // keeps meta infos
-
// get general infos
pageGeneral.push(["Title", window.content.document.title]);
- pageGeneral.push(["URL", '<a class="hl-URL" href="' + window.content.document.location.toString() + '">' +
- window.content.document.location.toString() + '</a>']);
- pageGeneral.push(["Referrer", ("referrer" in window.content.document && window.content.document.referrer)]);
+ pageGeneral.push(["URL", hiUrl(window.content.document.location.toString())]);
+
+ var ref = "referrer" in window.content.document && window.content.document.referrer;
+ if (ref)
+ pageGeneral.push(["Referrer", ref]);
+
pageGeneral.push(["Mime-Type", window.content.document.contentType]);
pageGeneral.push(["Encoding", window.content.document.characterSet]);
- if (cacheEntryDescriptor)
- {
- var pageSize = cacheEntryDescriptor.dataSize;
- var bytes = pageSize + '';
- for (var u = bytes.length - 3; u > 0; u -= 3) // make a 1400 -> 1'400
- bytes = bytes.slice(0, u) + "," + bytes.slice(u, bytes.length);
- pageGeneral.push(["File Size", (Math.round(pageSize / 1024 * 100) / 100) + "KB (" + bytes + " bytes)"]);
- }
pageGeneral.push(["Compatibility", content.document.compatMode == "BackCompat" ?
- "Quirks Mode" : "Full/Almost Standards Mode"]);
- pageGeneral.push(["Last Modified", window.content.document.lastModified]);
+ "Quirks Mode" : "Full/Almost Standard Mode"]);
+ pageGeneral.push(["Last Modified", window.content.document.lastModified]); //TODO: do not show bogus times (=current time)
// get meta tag data, sort and put into pageMeta[]
var metaNodes = window.content.document.getElementsByTagName("meta");
@@ -572,10 +701,9 @@
for (var i = 0; i < length; i++)
{
var tmpTag = metaNodes[i].name || metaNodes[i].httpEquiv;// +
- //'<span style="font-weight: normal; font-size: 90%;">-eq</span>'; // XXX: really important?
- var tmpTagNr = tmpTag + "-" + i; // allows multiple (identical) meta names
+ var tmpTagNr = tmpTag + "-" + i; // allows multiple (identical) meta names
tmpDict[tmpTagNr] = [tmpTag, metaNodes[i].content];
- tmpSort.push(tmpTagNr); // array for sorting
+ tmpSort.push(tmpTagNr); // array for sorting
}
// sort: ignore-case
@@ -587,37 +715,20 @@
}
}
+ pageMeta.push(["Meta Tags", "no Meta-Tags on this page"]); // add extra text to the end
+ pageGeneral.push(["General Info", "general Info not available for this page"]);
+ pageRss.push(["RSS Feeds", "no RSS-Feeds on this page"]);
+
var pageInfoText = "";
var option = vimperator.options["pageinfo"];
for (var z = 0; z < option.length; z++)
{
- var newLine = z > 0 ? "<br/>" : "";
switch (option[z])
{
- case "g": pageInfoText += newLine + "<table><tr><td class='hl-Title' style='font-weight: bold;' colspan='2'>General</td></tr>";
- for (var i = 0; i < pageGeneral.length; i++)
- {
- if (pageGeneral[i][1])
- pageInfoText += "<tr><td style='font-weight: bold;'> " + pageGeneral[i][0] + ": </td><td>" + pageGeneral[i][1] + "</td></tr>";
- }
- pageInfoText += "</table>";
- break;
-
- case "m": pageInfoText += newLine + "<table><tr><td class='hl-Title' style='font-weight: bold;' colspan='2'>Meta Tags</td></tr>";
- if (pageMeta.length)
- {
- for (var i = 0; i < pageMeta.length; i++)
- {
- pageInfoText += "<tr><td style='font-weight: bold;'> " + pageMeta[i][0] + ": </td><td>" + pageMeta[i][1] + "</td></tr>";
- }
- }
- else
- {
- pageInfoText += "<tr><td colspan='2'>(no Meta-Tags on this page)</td></tr>";
- }
- pageInfoText += "</table>";
- break;
+ case "g": pageInfoText += pageInfoTextSetup(pageGeneral); break;
+ case "r": pageInfoText += pageInfoTextSetup(pageRss); break;
+ case "m": pageInfoText += pageInfoTextSetup(pageMeta); break;
}
}
More information about the Vimperator
mailing list