mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 00:27:57 +01:00
merge new support for feeds in :pageinfo
This commit is contained in:
@@ -449,13 +449,83 @@ vimperator.Buffer = function() //{{{
|
|||||||
|
|
||||||
this.pageInfo = function(verbose)
|
this.pageInfo = function(verbose)
|
||||||
{
|
{
|
||||||
// to get the file size later (from pageInfo.js) (setup cacheEntryDescriptor)
|
// TODO: copied from firefox. Needs some review/work...
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: could this be useful for other commands?
|
||||||
|
function createTable(data)
|
||||||
|
{
|
||||||
|
var ret = "<table><tr><th class='hl-Title' style='font-weight: bold;' align='left' colspan='2'>" +
|
||||||
|
data[data.length -1][0] + "</th></tr>";
|
||||||
|
|
||||||
|
if (data.length - 1)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < data.length - 1 ; i++)
|
||||||
|
ret += "<tr><td style='font-weight: bold; min-width: 150px'> " + data[i][0] + ": </td><td>" + data[i][1] + "</td></tr>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret += "<tr><td colspan='2'> (" + data[data.length - 1][1] + ")</td></tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret + "</table>";
|
||||||
|
}
|
||||||
|
|
||||||
|
var pageGeneral = [];
|
||||||
|
var pageFeeds = [];
|
||||||
|
var pageMeta = [];
|
||||||
|
|
||||||
|
// get file size
|
||||||
const nsICacheService = Components.interfaces.nsICacheService;
|
const nsICacheService = Components.interfaces.nsICacheService;
|
||||||
const ACCESS_READ = Components.interfaces.nsICache.ACCESS_READ;
|
const ACCESS_READ = Components.interfaces.nsICache.ACCESS_READ;
|
||||||
const cacheService = Components.classes["@mozilla.org/network/cache-service;1"].getService(nsICacheService);
|
const cacheService = Components.classes["@mozilla.org/network/cache-service;1"].getService(nsICacheService);
|
||||||
var httpCacheSession = cacheService.createSession("HTTP", 0, true);
|
var httpCacheSession = cacheService.createSession("HTTP", 0, true);
|
||||||
httpCacheSession.doomEntriesIfExpired = false;
|
|
||||||
var ftpCacheSession = cacheService.createSession("FTP", 0, true);
|
var ftpCacheSession = cacheService.createSession("FTP", 0, true);
|
||||||
|
httpCacheSession.doomEntriesIfExpired = false;
|
||||||
ftpCacheSession.doomEntriesIfExpired = false;
|
ftpCacheSession.doomEntriesIfExpired = false;
|
||||||
var cacheKey = window.content.document.location.toString().replace(/#.*$/, "");
|
var cacheKey = window.content.document.location.toString().replace(/#.*$/, "");
|
||||||
try
|
try
|
||||||
@@ -471,49 +541,83 @@ vimperator.Buffer = function() //{{{
|
|||||||
catch (ex2) { }
|
catch (ex2) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pageSize = []; // [0] bytes; [1] kbytes
|
||||||
|
if (cacheEntryDescriptor)
|
||||||
|
{
|
||||||
|
pageSize[0] = vimperator.util.formatNumber(cacheEntryDescriptor.dataSize);
|
||||||
|
pageSize[1] = vimperator.util.formatNumber(Math.round(cacheEntryDescriptor.dataSize / 1024 * 100) / 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// put feeds rss into pageFeeds[]
|
||||||
|
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.. --calmar
|
||||||
|
var type = feed.type || "application/rss+xml";
|
||||||
|
pageFeeds.push([feed.title, vimperator.util.highlightURL(feed.href, true)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctrl-g single line output
|
||||||
if (!verbose)
|
if (!verbose)
|
||||||
{
|
{
|
||||||
// TODO: strip off any component after &
|
var info = []; // tmp array for joining later
|
||||||
var file = window.content.document.location.pathname.split('/').pop();
|
var file = window.content.document.location.pathname.split("/").pop() || "[No Name]";
|
||||||
if (!file)
|
|
||||||
file = "[No Name]";
|
|
||||||
|
|
||||||
var title = window.content.document.title || "[No Title]";
|
var title = window.content.document.title || "[No Title]";
|
||||||
|
|
||||||
if (cacheEntryDescriptor)
|
if (pageSize[1])
|
||||||
var pageSize = Math.round(cacheEntryDescriptor.dataSize / 1024 * 100) / 100 + "KB";
|
info.push(pageSize[1] + "KiB");
|
||||||
|
|
||||||
var lastmod = window.content.document.lastModified.slice(0, -3);
|
var lastMod = window.content.document.lastModified.slice(0, -3);
|
||||||
|
if (lastMod)
|
||||||
|
info.push(lastMod);
|
||||||
|
|
||||||
var pageInfoText = '"' + file + '" [' + pageSize + ", " + lastmod + "] " + title;
|
var countFeeds = "";
|
||||||
|
if (pageFeeds.length)
|
||||||
|
countFeeds = pageFeeds.length + (pageFeeds.length == 1 ? " feed" : " feeds");
|
||||||
|
|
||||||
|
if (countFeeds)
|
||||||
|
info.push(countFeeds);
|
||||||
|
|
||||||
|
var pageInfoText = '"' + file + '" [' + info.join(", ") + "] " + title;
|
||||||
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_SINGLELINE);
|
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_SINGLELINE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pageGeneral = []; // keeps general infos
|
|
||||||
var pageMeta = []; // keeps meta infos
|
|
||||||
|
|
||||||
// get general infos
|
// get general infos
|
||||||
pageGeneral.push(["Title", window.content.document.title]);
|
pageGeneral.push(["Title", window.content.document.title]);
|
||||||
pageGeneral.push(["URL", '<a class="hl-URL" href="' + window.content.document.location.toString() + '">' +
|
pageGeneral.push(["URL", vimperator.util.highlightURL(window.content.document.location.toString(), true)]);
|
||||||
window.content.document.location.toString() + '</a>']);
|
|
||||||
pageGeneral.push(["Referrer", ("referrer" in window.content.document && window.content.document.referrer)]);
|
var ref = "referrer" in window.content.document && window.content.document.referrer;
|
||||||
|
if (ref)
|
||||||
|
pageGeneral.push(["Referrer", vimperator.util.highlightURL(ref, true)]);
|
||||||
|
|
||||||
|
if (pageSize[0])
|
||||||
|
pageGeneral.push(["File Size", pageSize[1] + "KiB (" + pageSize[0] + " bytes)"]);
|
||||||
|
|
||||||
pageGeneral.push(["Mime-Type", window.content.document.contentType]);
|
pageGeneral.push(["Mime-Type", window.content.document.contentType]);
|
||||||
pageGeneral.push(["Encoding", window.content.document.characterSet]);
|
pageGeneral.push(["Encoding", window.content.document.characterSet]);
|
||||||
|
pageGeneral.push(["Compatibility", content.document.compatMode == "BackCompat" ? "Quirks Mode" : "Full/Almost Standards Mode"]);
|
||||||
if (cacheEntryDescriptor)
|
pageGeneral.push(["Last Modified", window.content.document.lastModified]); //TODO: do not show bogus times (=current time)
|
||||||
{
|
|
||||||
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]);
|
|
||||||
|
|
||||||
// get meta tag data, sort and put into pageMeta[]
|
// get meta tag data, sort and put into pageMeta[]
|
||||||
var metaNodes = window.content.document.getElementsByTagName("meta");
|
var metaNodes = window.content.document.getElementsByTagName("meta");
|
||||||
@@ -526,7 +630,6 @@ vimperator.Buffer = function() //{{{
|
|||||||
for (var i = 0; i < length; i++)
|
for (var i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
var tmpTag = metaNodes[i].name || metaNodes[i].httpEquiv;// +
|
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];
|
tmpDict[tmpTagNr] = [tmpTag, metaNodes[i].content];
|
||||||
tmpSort.push(tmpTagNr); // array for sorting
|
tmpSort.push(tmpTagNr); // array for sorting
|
||||||
@@ -534,47 +637,48 @@ vimperator.Buffer = function() //{{{
|
|||||||
|
|
||||||
// sort: ignore-case
|
// sort: ignore-case
|
||||||
tmpSort.sort(function (a,b){return a.toLowerCase() > b.toLowerCase() ? 1 : -1;});
|
tmpSort.sort(function (a,b){return a.toLowerCase() > b.toLowerCase() ? 1 : -1;});
|
||||||
|
|
||||||
for (var i=0; i < tmpSort.length; i++)
|
for (var i=0; i < tmpSort.length; i++)
|
||||||
{
|
pageMeta.push([tmpDict[tmpSort[i]][0], vimperator.util.highlightURL(tmpDict[tmpSort[i]][1], false)]);
|
||||||
pageMeta.push([tmpDict[tmpSort[i]][0], tmpDict[tmpSort[i]][1]]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pageMeta.push(["Meta Tags", ""]); // add extra text to the end
|
||||||
|
pageGeneral.push(["General Info", ""]);
|
||||||
|
pageFeeds.push(["Feeds", ""]);
|
||||||
|
|
||||||
var pageInfoText = "";
|
var pageInfoText = "";
|
||||||
var option = vimperator.options["pageinfo"];
|
var option = vimperator.options["pageinfo"];
|
||||||
|
var br = "";
|
||||||
|
|
||||||
for (var z = 0; z < option.length; z++)
|
for (var z = 0; z < option.length; z++)
|
||||||
{
|
{
|
||||||
var newLine = z > 0 ? "<br/>" : "";
|
|
||||||
switch (option[z])
|
switch (option[z])
|
||||||
{
|
{
|
||||||
case "g": pageInfoText += newLine + "<table><tr><td class='hl-Title' style='font-weight: bold;' colspan='2'>General</td></tr>";
|
case "g":
|
||||||
for (var i = 0; i < pageGeneral.length; i++)
|
if (pageGeneral.length > 1)
|
||||||
{
|
{
|
||||||
if (pageGeneral[i][1])
|
pageInfoText += br + createTable(pageGeneral);
|
||||||
pageInfoText += "<tr><td style='font-weight: bold;'> " + pageGeneral[i][0] + ": </td><td>" + pageGeneral[i][1] + "</td></tr>";
|
if (!br)
|
||||||
|
br = "<br/>";
|
||||||
}
|
}
|
||||||
pageInfoText += "</table>";
|
|
||||||
break;
|
break;
|
||||||
|
case "f":
|
||||||
case "m": pageInfoText += newLine + "<table><tr><td class='hl-Title' style='font-weight: bold;' colspan='2'>Meta Tags</td></tr>";
|
if (pageFeeds.length > 1)
|
||||||
if (pageMeta.length)
|
|
||||||
{
|
{
|
||||||
for (var i = 0; i < pageMeta.length; i++)
|
pageInfoText += br + createTable(pageFeeds);
|
||||||
|
if (!br)
|
||||||
|
br = "<br/>";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "m":
|
||||||
|
if (pageMeta.length > 1)
|
||||||
{
|
{
|
||||||
pageInfoText += "<tr><td style='font-weight: bold;'> " + pageMeta[i][0] + ": </td><td>" + pageMeta[i][1] + "</td></tr>";
|
pageInfoText += br + createTable(pageMeta);
|
||||||
|
if (!br)
|
||||||
|
br = "<br/>";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pageInfoText += "<tr><td colspan='2'>(no Meta-Tags on this page)</td></tr>";
|
|
||||||
}
|
|
||||||
pageInfoText += "</table>";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE);
|
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE);
|
||||||
}
|
}
|
||||||
//}}}
|
//}}}
|
||||||
|
|||||||
@@ -429,20 +429,6 @@ vimperator.Options = function() //{{{
|
|||||||
default_value: "homepage,quickmark,tabopen,paste"
|
default_value: "homepage,quickmark,tabopen,paste"
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
this.add(new vimperator.Option(["pageinfo", "pa"], "charlist",
|
|
||||||
{
|
|
||||||
short_help: "Desired info on :pa[geinfo]",
|
|
||||||
help: "Available items:<br/>" +
|
|
||||||
"<ul>" +
|
|
||||||
"<li><b>g</b>: general info</li>" +
|
|
||||||
"<li><b>m</b>: meta tags</li>" +
|
|
||||||
"</ul>" +
|
|
||||||
"The order matters",
|
|
||||||
default_value: "gm",
|
|
||||||
validator: function (value) { if (/[^gm]/.test(value) || value.length > 2 ||
|
|
||||||
value.length < 1) return false; else return true; }
|
|
||||||
}
|
|
||||||
));
|
|
||||||
this.add(new vimperator.Option(["complete", "cpt"], "charlist",
|
this.add(new vimperator.Option(["complete", "cpt"], "charlist",
|
||||||
{
|
{
|
||||||
short_help: "Items which are completed at the :[tab]open prompt",
|
short_help: "Items which are completed at the :[tab]open prompt",
|
||||||
@@ -585,6 +571,20 @@ vimperator.Options = function() //{{{
|
|||||||
validator: function (value) { if (value >= 1 && value <= 1000) return true; else return false; }
|
validator: function (value) { if (value >= 1 && value <= 1000) return true; else return false; }
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
this.add(new vimperator.Option(["pageinfo", "pa"], "charlist",
|
||||||
|
{
|
||||||
|
short_help: "Desired info on :pa[geinfo]",
|
||||||
|
help: "Available items:<br/>" +
|
||||||
|
"<ul>" +
|
||||||
|
"<li><b>g</b>: general info</li>" +
|
||||||
|
"<li><b>f</b>: feeds</li>" +
|
||||||
|
"<li><b>m</b>: meta tags</li>" +
|
||||||
|
"</ul>" +
|
||||||
|
"The order matters",
|
||||||
|
default_value: "gfm",
|
||||||
|
validator: function (value) { return !(/[^gfm]/.test(value) || value.length > 3 || value.length < 1) }
|
||||||
|
}
|
||||||
|
));
|
||||||
this.add(new vimperator.Option(["popups", "pps"], "number",
|
this.add(new vimperator.Option(["popups", "pps"], "number",
|
||||||
{
|
{
|
||||||
short_help: "Where to show requested popup windows",
|
short_help: "Where to show requested popup windows",
|
||||||
|
|||||||
@@ -75,6 +75,27 @@ vimperator.util = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return arg;
|
return arg;
|
||||||
|
},
|
||||||
|
|
||||||
|
highlightURL: function(str, force)
|
||||||
|
{
|
||||||
|
if (force || /^[a-zA-Z]+:\/\/.*\//.test(str))
|
||||||
|
return "<a class='hl-URL' href='" + str + "'>" + vimperator.util.escapeHTML(str) + "</a>";
|
||||||
|
else
|
||||||
|
return str;
|
||||||
|
},
|
||||||
|
|
||||||
|
formatNumber: function(num)
|
||||||
|
{
|
||||||
|
var strNum = (num + "").split(".", 2);
|
||||||
|
|
||||||
|
for (var u = strNum[0].length - 3; u > 0; u -= 3)
|
||||||
|
strNum[0] = strNum[0].substring(0, u) + "," + strNum[0].substring(u, strNum[0].length);
|
||||||
|
|
||||||
|
if (strNum[1])
|
||||||
|
strNum[0] += "." + strNum[1]
|
||||||
|
|
||||||
|
return strNum[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user