1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-25 00:53:31 +01:00

make further refinements to the output of :pageinfo

This commit is contained in:
Doug Kearns
2007-10-27 13:37:23 +00:00
parent 94c423dc3f
commit 961a1bdad3

View File

@@ -32,7 +32,7 @@ vimperator.Buffer = function() //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
// used for the "B" mapping to remember the last :buffer[!] command // used for the "B" mapping to remember the last :buffer[!] command
var lastBufferSwitchArgs = ""; var lastBufferSwitchArgs = "";
var lastBufferSwitchSpecial = true; var lastBufferSwitchSpecial = true;
var zoom_levels = [ 1, 10, 25, 50, 75, 90, 100, var zoom_levels = [ 1, 10, 25, 50, 75, 90, 100,
@@ -190,9 +190,9 @@ vimperator.Buffer = function() //{{{
return result; return result;
} }
// in contrast to vim, returns the selection if one is made, // in contrast to vim, returns the selection if one is made,
// otherwise tries to guess the current word unter the text cursor // otherwise tries to guess the current word unter the text cursor
// NOTE: might change the selection // NOTE: might change the selection
this.getCurrentWord = function() this.getCurrentWord = function()
{ {
var selection = window.content.getSelection().toString(); var selection = window.content.getSelection().toString();
@@ -493,8 +493,8 @@ vimperator.Buffer = function() //{{{
bumpZoomLevel(-steps, full_zoom); bumpZoomLevel(-steps, full_zoom);
}; };
this.pageInfo = function(verbose) this.pageInfo = function(verbose)
{ {
// to get the file size later (from pageInfo.js) (setup cacheEntryDescriptor) // to get the file size later (from pageInfo.js) (setup cacheEntryDescriptor)
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;
@@ -517,23 +517,21 @@ vimperator.Buffer = function() //{{{
catch (ex2) { } catch (ex2) { }
} }
if (!verbose) if (!verbose)
{ {
// TODO: strip off any component after & // TODO: strip off any component after &
var file = window.content.document.location.pathname.split('/').pop(); var file = window.content.document.location.pathname.split('/').pop();
if (!file) if (!file)
file = "[No Name]"; file = "[No Name]";
var title = window.content.document.title; var title = window.content.document.title || "[No Title]";
if (title.length > 60)
title = title.substr(0,57) + "... ";
else if (!title.length)
title = "[No Title]";
if (cacheEntryDescriptor) if (cacheEntryDescriptor)
var pageSize = Math.round(cacheEntryDescriptor.dataSize / 1024 * 100) / 100 + "KB"; var pageSize = Math.round(cacheEntryDescriptor.dataSize / 1024 * 100) / 100 + "KB";
var pageInfoText = "" + file + ": " + title + " (" + pageSize + ", other cool things)"; var lastmod = window.content.document.lastModified.slice(0, -3);
var pageInfoText = '"' + file + '" (' + pageSize + ", " + lastmod + ") " + title;
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_SINGLELINE); vimperator.echo(pageInfoText, vimperator.commandline.FORCE_SINGLELINE);
return; return;
@@ -543,42 +541,46 @@ vimperator.Buffer = function() //{{{
var pageMeta = []; // keeps meta 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", '<a class="hl-URL" href="' + window.content.document.location.toString() + '">' +
window.content.document.location.toString() + '</a>']); window.content.document.location.toString() + '</a>']);
pageGeneral.push(["Referrer", ("referrer" in window.content.document && window.content.document.referrer)]); pageGeneral.push(["Referrer", ("referrer" in window.content.document && window.content.document.referrer)]);
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]);
if (cacheEntryDescriptor) { if (cacheEntryDescriptor) {
var pageSize = cacheEntryDescriptor.dataSize; var pageSize = cacheEntryDescriptor.dataSize;
pageGeneral.push(["File Size", (Math.round(pageSize / 1024 * 100) / 100) + "KB (" + pageSize + " bytes)"]); 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" ? pageGeneral.push(["Compatibility", content.document.compatMode == "BackCompat" ?
"Quirks Mode" : "Full/Almost Standard Mode"]); "Quirks Mode" : "Full/Almost Standard Mode"]);
pageGeneral.push(["Last Modified", window.content.document.lastModified]); pageGeneral.push(["Last Modified", window.content.document.lastModified]);
// get meta tag infos info and 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");
var length = metaNodes.length; var length = metaNodes.length;
if (length) if (length)
{ {
var tmpSort = []; var tmpSort = [];
var tmpDict = []; var tmpDict = [];
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? //'<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
} }
// 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++)
{ {