aboutsummaryrefslogtreecommitdiffstats
path: root/hatenabookmark_show.js
blob: e5ce846ec26c3ee6edfb4aa67f6e3a606c826b1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Vimperator plugin: 'Show Hatena Bookmark Comments'
// Last Change: 21-Mar-2008. Jan 2008
// License: Creative Commons
// Maintainer: Trapezoid <trapezoid.g@gmail.com> - http://unsigned.g.hatena.ne.jp/Trapezoid
//
// show hatena bookmark comments script for Vimperator 0.6

(function(){
    function showComments(url){
        const endPoint = "http://b.hatena.ne.jp/entry/json/";
        var xhr = new XMLHttpRequest();
        var tagString,showString = "<div>";
        xhr.open("GET",endPoint + url.replace(/#/,"%23") ,false);
        xhr.send(null);
        var response;
        if(!(response = window.eval(xhr.responseText))){
            liberator.echoerr("Does not exists!!");return;
        }
        var bookmarks = response["bookmarks"];
        showString += response["count"] + " users : " + response["title"] + "<dl>";

        bookmarks.forEach(function(bookmark){
            tagString = bookmark.tags.length ? "[" + bookmark.tags.join("][") + "]":"";
            showString += "<dt style=\"float:left;clear:both;width:10%;margin:0;\">" + bookmark.user + "</dt>";
            showString += "<dd style=\"margin:0 0 0 10%;width:90%;border-left:1px solid;\"> "
            showString += tagString + (bookmark.tags.length > 0 && bookmark.comment ? "<br/> ":"") + bookmark.comment + "</dd>";
        });
        showString += "</dl></div>";
        liberator.commandline.echo(showString, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
    }
    liberator.commands.addUserCommand(["hbinfo"], "show hatena bookmark comments",
        function(arg,special){
            var clipboard = readFromClipboard();
            if(special)
                arg = window.content.document.getSelection() || clipboard;
            showComments(arg?encodeURIComponent(arg):liberator.buffer.URL);
        },{ completer: liberator.completion.url }
    );
    liberator.mappings.addUserMap([liberator.modes.VISUAL], [",h"], "show hatena bookmark comments",
        function(count){
            showComments(window.content.document.getSelection());
        },{ noremap: true }
    );
})();
ass="kr">const table = { f: liberator.NEW_TAB, t: liberator.NEW_TAB, n: liberator.NEW_TAB, b: liberator.NEW_BACKGROUND_TAB, c: liberator.CURRENT_TAB, w: liberator.NEW_WINDOW, }; return (str && table[str.charAt(0).toLowerCase()]) || fail; } const WHERE_COMPLETIONS = ['f', 't', 'n', 'b', 'c', 'w']; let (foihandle) { commands.addUserCommand( ['fo[pen]', 'filteropen'], 'Filtered open', function (opts, bang) { let where = charToWhere(opts['-where'], bang ? liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB); let [i, links] = [1, filteredLinks(opts.arguments.join(''))]; if (!links.length) return; liberator.open(links[0].href, where); if (links.length <= 1) return; let interval = (opts['-interval'] || liberator.globalVariables.fopen_default_interval || 1) * 1000; foihandle = setInterval(function () { try { liberator.open(links[i].href, where); if ((++i) >= links.length) clearInterval(foihandle); } catch (e) { clearInterval(foihandle); } }, interval); }, { bang: true, options: [ [['-interval', '-i'], commands.OPTION_INT], [['-where', '-w'], commands.OPTION_STRING], ], completer: function (word) { let links = filteredLinks(word); return [0, [[it.href, it.textContent] for each (it in links)]]; }, } ); commands.addUserCommand( ['stopfilteropen', 'stopfo[pen]'], 'Stop filtered open', function () { clearInterval(foihandle); } ); } let ( lolinks = [], looptions = [ [['-where', '-w'], commands.OPTION_STRING, null, WHERE_COMPLETIONS] ] ) { commands.addUserCommand( ['lo[pen]', 'linkopen'], 'Filtered open', function (opts, bang) { let where = charToWhere(opts['-where'], bang ? liberator.NEW_TAB : liberator.CURRENT_TAB); let arg = opts.arguments[0]; let m = arg.match(/^\d+(?=,)/); if (m) buffer.followLink(lolinks[parseInt(m[0], 10)], where); }, { options: looptions, bang: true, completer: function (word) { if (!word || word.match(/\s|\d+,/)) return []; lolinks = filteredLinks(word); return [0, [[i + ',' + lolinks[i].href, lolinks[i].textContent] for (i in lolinks || [])]]; } } ); } } catch (e) { liberator.log(e); }})(); // vim:sw=2 ts=2 et: