/* {{{ Copyright (c) 2008-2011, anekos. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ################################################################################### # http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license # # に参考になる日本語訳がありますが、有効なのは上記英文となります。 # ################################################################################### }}} */ // PLUGIN_INFO {{{ let PLUGIN_INFO = Read Cat Later Read it later 後で読む 1.1.5 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) https://github.com/vimpr/vimperator-plugins/raw/master/readcatlater.js 2.4 3.0 ; // }}} (function () { // このプラグインでブックマークしたときに必ずつくタグ const RCL_TAG = 'readcatlater'; // このプラグインが保存するブックマークのフォルダ名 // 変更しても良いし、場所を移動しても平気である。 const FOLDER_NAME = 'L'; // 逆順表示 const REVERSE = eval(liberator.globalVariables.readcatlater_reverse || 'false'); let prefs = { prefix: 'extensions.vimperator.plugins.readcatlater.', prefs: Components.classes["@mozilla.org/preferences-service;1"]. getService(Components.interfaces.nsIPrefBranch), get: function (name, def) { var name, type; try { const nsIPrefBranch = Components.interfaces.nsIPrefBranch; name = this.prefix + name; type = this.prefs.getPrefType(name); switch (type) { case nsIPrefBranch.PREF_STRING: try { return this.prefs.getComplexValue(name, Components.interfaces.nsISupportsString).data; } catch (e) { this.prefs.getCharPref(name); } break; case nsIPrefBranch.PREF_INT: return this.prefs.getIntPref(name); break; case nsIPrefBranch.PREF_BOOL: return this.prefs.getBoolPref(name); default: return def; } } catch (e) { return def; } }, set: function (name, value, type) { var name = this.prefix + name; switch (type || typeof value) { case 'string': let str = Cc['@mozilla.org/supports-string;1']. createInstance(Ci.nsISupportsString); str.data = value; return this.prefs.setComplexValue(name, Components.interfaces.nsISupportsString, str); case 'boolean': return this.prefs.setBoolPref(name, value); case 'number': return this.prefs.setIntPref(name, value); default: alert('unknown pref type'); } }, }; const tagssvc = Cc["@mozilla.org/browser/tagging-service;1"]. getService(Ci.nsITaggingService); const IOService = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService); const myURI = IOService.newURI("http://www.mozilla.com", null, null); const bookmarks = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. getService(Ci.nsINavBookmarksService); const history = Cc["@mozilla.org/browser/nav-history-service;1"]. getService(Ci.nsINavHistoryService); let folderId = prefs.get('folderId', false); if (!folderId) { folderId = bookmarks.createFolder(bookmarks.toolbarFolder, FOLDER_NAME, bookmarks.DEFAULT_INDEX); prefs.set('folderId', folderId); } /* // Get an array of tags for a URI let myTags = tagssvc.getTagsForURI(myURI, {}); // Get an array of URIs for a tag let taggedURIs = tagssvc.getURIsForTag("mozilla"); // Get an array of all tags let arrayOfAllTags = tagssvc.allTags; // Remove tags from a URI
// PLUGIN_INFO//{{{
var PLUGIN_INFO =
<VimperatorPlugin>
    <name>{NAME}</name>
    <description>hash of file</description>
    <author mail="konbu.komuro@gmail.com" homepage="http://d.hatena.ne.jp/hogelog/">hogelog</author>
    <version>0.2.2</version>
    <minVersion>2.3</minVersion>
    <maxVersion>2.3</maxVersion>
    <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/hash.js</updateURL>
    <detail><![CDATA[

== COMMANDS ==
hash:
    :hash md2|md5|sha1|sha256|sha384|sha512 file-path

]]></detail>
</VimperatorPlugin>;
//}}}

(function() {
    const PR_UINT_MAX = 0xffffffff;
    let Crypt = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash);
    let Algos = [
        ["md2", "MD2 Algorithm"],
        ["md5", "MD5 Algorithm"],
        ["sha1", "SHA1 Algorithm"],     // SHA-1
        ["sha256", "SHA256 Algorithm"], // SHA-256
        ["sha384", "SHA384 Algorithm"], // SHA-384
        ["sha512", "SHA512 Algorithm"], // SHA-512
    ];

    function getStream(path)
    {
        let file = io.File(path);
        let stream = Cc["@mozilla.org/network/file-input-stream;1"]
            .createInstance(Ci.nsIFileInputStream);
        stream.init(file, 0x01, 0444, 0);
        return stream;
    }

    // return the two-digit hexadecimal code for a byte
    function toHexString(charCode)
    {
      return ("0" + charCode.toString(16)).slice(-2);
    }


    commands.addUserCommand(["hash"], "hash of file",
        function(args){
            if (args.length!=2) {

                liberator.echo("usage \":hash md2|md5|sha1|sha256|sha384|sha512 file-path\"");
                return false;
            }
            let [algo, path] = args;
            let stream = getStream(path);

            Crypt.initWithString(algo);

            // read the entire stream
            Crypt.updateFromStream(stream, PR_UINT_MAX);

            stream.close();

            // get base-64 string
            let hash = Crypt.finish(false);

            // convert the binary hash data to a hex string.
            let str = [toHexString(hash.charCodeAt(i)) for(i in hash)].join("");
            util.copyToClipboard(str, true);
        },
        {
            bang: true,
            completer: function (context, args){
                if (args.completeArg == 0) {
                    context.title = ["hash", "algorithm"];
                    context.completions = Algos;
                } else if (args.completeArg == 1) {
                    completion.url(context, "f");
                }
            },
            literal: 1,
        },
        true
        );

})();
// vim: fdm=marker sw=4 ts=4 et: