diff --git a/NEWS b/NEWS index 1ccc1aea..fdbcba63 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,9 @@
 2007-XX-XX:
 	* version 0.5.3
-	* options are no longer stored in preferences - use the RC file instead
+	* new :pa[geinfo] command (thanks Marco Candrian)
+	* IMPORTANT! options are no longer automatically stored - use the
+	  ~/.vimperatorrc file instead for persistent options
 	* added new :mkvimperatorc command
 	* remove :redraw and Ctrl-L commands as they rely on FF3 features
 	* :ls, :history and :bmarks output is now hyperlinked
diff --git a/content/buffers.js b/content/buffers.js
index 8e7389a7..4d585cfd 100644
--- a/content/buffers.js
+++ b/content/buffers.js
@@ -444,6 +444,136 @@ vimperator.Buffer = function() //{{{
     {
         bumpZoomLevel(-steps);
     }
+
+    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", '' + 
+                window.content.document.location.toString() + '']);
+        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;// + 
+                    //'-eq'; // 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 ? "
" : ""; + switch (option[z]) + { + case "g": pageInfoText += newLine + ""; + for (var i = 0; i < pageGeneral.length; i++) + { + if (pageGeneral[i][1]) + pageInfoText += ""; + } + pageInfoText += "
General
" + pageGeneral[i][0] + ": " + pageGeneral[i][1] + "
"; + break; + + case "m": pageInfoText += newLine + ""; + if (pageMeta.length) + { + for (var i = 0; i < pageMeta.length; i++) + { + pageInfoText += ""; + } + } + else + { + pageInfoText += ""; + } + pageInfoText += "
Meta Tags
" + pageMeta[i][0] + ": " + pageMeta[i][1] + "
(no Meta-Tags on this page)
"; + break; + } + } + + vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE); + } //}}} } //}}} diff --git a/content/commands.js b/content/commands.js index 0d15f1c8..e5525b98 100644 --- a/content/commands.js +++ b/content/commands.js @@ -227,6 +227,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); }, { diff --git a/content/options.js b/content/options.js index eaa94a50..449af7bf 100644 --- a/content/options.js +++ b/content/options.js @@ -429,6 +429,20 @@ vimperator.Options = function() //{{{ default_value: "homepage,quickmark,tabopen,paste" } )); + this.add(new vimperator.Option(["pageinfo", "pa"], "charlist", + { + short_help: "Desired info on :pa[geinfo]", + help: "Available items:
" + + "" + + "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",