1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 18:47:59 +01:00

new :pageinfo command (thanks calmar)

This commit is contained in:
Martin Stubenschrott
2007-10-27 00:52:01 +00:00
parent 95fbbac537
commit 3b82de8c35
5 changed files with 160 additions and 0 deletions

1
NEWS
View File

@@ -6,6 +6,7 @@
~/.vimperatorrc file instead for persistent options
* IMPORTANT! Major hints rewrite
read up the new help for the f, F and ; commands for details
* new :pa[geinfo] command (thanks Marco Candrian)
* added new :mkvimperatorrc command
* you can edit textfields with Ctrl-i now using an external editor (thanks to Joseph Xu)
* :open, :bmarks, etc. filter on space separated tokens now, so you can

View File

@@ -38,6 +38,7 @@ vimperator.Buffer = function() //{{{
var zoom_levels = [ 1, 10, 25, 50, 75, 90, 100,
120, 150, 200, 300, 500, 1000, 2000 ];
function setZoom(value, full_zoom)
{
if (value < 1 || value > 2000)
@@ -491,6 +492,136 @@ vimperator.Buffer = function() //{{{
{
bumpZoomLevel(-steps, full_zoom);
};
this.pageInfo = function(verbose)
{
// to get the file size later (from pageInfo.js) (setup cacheEntryDescriptor)
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);
var httpCacheSession = cacheService.createSession("HTTP", 0, true);
httpCacheSession.doomEntriesIfExpired = false;
var ftpCacheSession = cacheService.createSession("FTP", 0, true);
ftpCacheSession.doomEntriesIfExpired = false;
var cacheKey = window.content.document.location.toString().replace(/#.*$/, "");
try
{
var cacheEntryDescriptor = httpCacheSession.openCacheEntry(cacheKey, ACCESS_READ, false);
}
catch (ex)
{
try
{
cacheEntryDescriptor = ftpCacheSession.openCacheEntry(cacheKey, ACCESS_READ, false);
}
catch (ex2) { }
}
if (!verbose)
{
// TODO: strip off any component after &
var file = window.content.document.location.pathname.split('/').pop();
if (!file)
file = "[No Name]";
var title = window.content.document.title;
if (title.length > 60)
title = title.substr(0,57) + "... ";
else if (!title.length)
title = "[No Title]";
if (cacheEntryDescriptor)
var pageSize = Math.round(cacheEntryDescriptor.dataSize / 1024 * 100) / 100 + "KB";
var pageInfoText = "" + file + ": " + title + " (" + pageSize + ", other cool things)";
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(["Mime-Type", window.content.document.contentType]);
pageGeneral.push(["Encoding", window.content.document.characterSet]);
if (cacheEntryDescriptor) {
var pageSize = cacheEntryDescriptor.dataSize;
pageGeneral.push(["File Size", (Math.round(pageSize / 1024 * 100) / 100) + "KB (" + pageSize + " bytes)"]);
}
pageGeneral.push(["Compatibility", content.document.compatMode == "BackCompat" ?
"Quirks Mode" : "Full/Almost Standard Mode"]);
pageGeneral.push(["Last Modified", window.content.document.lastModified]);
// get meta tag infos info and sort and put into pageMeta[]
var metaNodes = window.content.document.getElementsByTagName("meta");
var length = metaNodes.length;
if (length)
{
var tmpSort = [];
var tmpDict = [];
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
tmpDict[tmpTagNr] = [tmpTag, metaNodes[i].content];
tmpSort.push(tmpTagNr); // array for sorting
}
// sort: ignore-case
tmpSort.sort(function (a,b){return a.toLowerCase() > b.toLowerCase() ? 1 : -1;});
for (var i=0; i < tmpSort.length; i++)
{
pageMeta.push([tmpDict[tmpSort[i]][0], tmpDict[tmpSort[i]][1]]);
}
}
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] + ":&nbsp;</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] + ":&nbsp;</td><td>" + pageMeta[i][1] + "</td></tr>";
}
}
else
{
pageInfoText += "<tr><td colspan='2'>(no Meta-Tags on this page)</td></tr>";
}
pageInfoText += "</table>";
break;
}
}
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE);
}
//}}}
} //}}}

View File

@@ -522,6 +522,14 @@ vimperator.Commands = function() //{{{
////////////////////// DEFAULT COMMANDS ////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
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"
}
));
addDefaultCommand(new vimperator.Command(["addo[ns]"],
function() { vimperator.open("chrome://mozapps/content/extensions/extensions.xul", vimperator.NEW_TAB); },
{

View File

@@ -231,6 +231,12 @@ vimperator.Events = function() //{{{
// FIXME: this currently causes window map events which is _very_ annoying
// we want to stay in command mode after a page has loaded
//setTimeout(vimperator.focusContent, 10);
// setTimeout(function() {
// if (doc.commandDispatcher.focusedElement)
// doc.commandDispatcher.focusedElement.blur();
// alert(doc.commandDispatcher.focusedElement);
// }, 1000);
}
}
}

View File

@@ -435,6 +435,20 @@ vimperator.Options = function() //{{{
default_value: 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>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",
{
short_help: "Items which are completed at the :[tab]open prompt",