From f087f3d759aab5a7ce40da89147dd192e8f52ff8 Mon Sep 17 00:00:00 2001 From: anekos Date: Tue, 9 Mar 2010 14:31:20 +0000 Subject: おぷーな git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@36976 d0d07461-0603-4401-acd4-de1884942a52 --- opener.js | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 opener.js (limited to 'opener.js') diff --git a/opener.js b/opener.js new file mode 100755 index 0000000..6584c1f --- /dev/null +++ b/opener.js @@ -0,0 +1,116 @@ +// PLUGIN_INFO {{{ +let PLUGIN_INFO = + + opener + opener + --- + URL 移動時にそのURLが既に開かれていたら、そのタブに移動する + 1.0.0 + voidy21 + anekos + http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/opener.js + 2.3 + 2.3 + + +; +// }}} +// INFO {{{ +let INFO = +<> + + voidy21 + anekos + +

URL 移動時にそのURLが既に開かれていたら、そのタブに移動する

+
+; +// }}} + +/* + * Original version by voidy21: + * http://vimperator.g.hatena.ne.jp/voidy21/20100119/1263907211 + * http://vimperator.g.hatena.ne.jp/voidy21/20100127/1264542669 + */ + +(function () { + let U = liberator.plugins.libly.$U; + + function jump (url) { + let index = 0; + let url = util.stringToURLArray(url).toString(); + for each ( [,tab] in tabs.browsers ) { + if(url == tab.currentURI.spec){ + tabs.select(index); + return true; + } + ++index; + } + return false; + } + + "open tabopen edit".split(/\s/).forEach( + function (name) { + let command = commands.get(name); + if (!command) + return; + U.around( + command, + "action", + function (next, args) { + let url = args[0].string; + if (!(url && jump(url))) + return next(); + } + ); + } + ); + + //buffer.followLink()を変更 + //hint-a-hint時[f,F]に対象のタブが既に開いてあったらjump + let (ignore = false) { + let ignoreBlock = function (block) { + ignore = true; + let result = block(); + ignore = false; + return result; + }; + + U.around( + buffer, + "followLink", + function (next, args) { + return ignoreBlock(function () { + let [elem,] = args; + let url = elem.href; + if (!(url && jump(url))){ + liberator.echo("Now Loading... " + url); + return next(); + } + }); + } + ); + + document.addEventListener( + 'click', + function (event) { + if (ignore) + return; + let e = event.target; + if (e && e.tagName.match(/^a$/i) && e.href && jump(e.href)) { + event.preventDefault(); + event.stopPropagation(); + } + }, + true + ); + } + +})(); -- cgit v1.2.3