[Vimperator] pageInfo patch (update)
joshyu
joshyupeng at gmail.com
Wed Dec 5 19:06:34 PST 2007
hi,marco!
I am a linux newbie, so If I ask question like a beginner, don't blame
me. I use ff2+vimperator 0.53pre, I want to patch your diff,I go into
the content directory of download sources from cvs,and run command:
patch -p0 < buffers.js.diff
I got some error information,such as:
patching file buffers.js
Hunk #1 FAILED at 524.
Hunk #2 FAILED at 549.
2 out of 2 hunks FAILED -- saving rejects to file buffers.js.rej
can you tell me what's wrong? any advice from anyone would be
appreciated too. thanks.
calmar <mac at calmar.ws> wrote:
> On Mon, Nov 05, 2007 at 02:23:30AM +0100, calmar wrote:
>
> Hi Martin,
>
> Update (latest):
>
> http://www.calmar.ws/tmp/pageInfo.patch
>
> update/fixes like url-highlighting of the referrer and a missing
> line in the option.js for rss-feeds especially.
>
> It also addes the <c-d> (what is ok has been said) and Ctrl-b and Ctrl-f
> (move forward/backward one char), and that also prevents the ffox's
> 'search' box what shouldn't popup anyway I guess (beeing bound to
> c-f) and ffox's c-b -> side-bookmar-thing.
>
> Cheers
> marco
>
> PS: besides the rss thing is also noy yet polished, seems to work
> nicely alrady so.
>
> PSII: there's a little (one-liner almost) hiUrl function in
> private. You told something about putting it inside 'pageInfo' or
> so? I woudn't know how to do that really at least..
>
>
>> 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
>
>> 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;
>> }
>> }
>>
>
>> _______________________________________________
>> Vimperator mailing list
>> Vimperator at mozdev.org
>> http://www.mozdev.org/mailman/listinfo/vimperator
>
>
More information about the Vimperator
mailing list