diff options
author | elzzup | 2014-11-12 23:15:31 +0900 |
---|---|---|
committer | elzzup | 2014-11-12 23:15:31 +0900 |
commit | d392c44a652331495e13fb8ea99cc2ac8a40527c (patch) | |
tree | 33bdf78ca978dfa0f6177b111a989a1789215576 | |
parent | f025b62c92a60d8437aada56d6f35f730412d7eb (diff) | |
download | vimperator-plugins-d392c44a652331495e13fb8ea99cc2ac8a40527c.tar.bz2 |
create googleselect.js
グーグル検索結果画面で楽に選択するためのプラグイン
コマンド:
googleselect back -次の検索結果リンクにフォーカス
googleselect[ front] -前の検索結果リンクにフォーカス
-rw-r--r-- | googleselect.js | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/googleselect.js b/googleselect.js new file mode 100644 index 0000000..24c4eca --- /dev/null +++ b/googleselect.js @@ -0,0 +1,96 @@ + +// PLUGIN_INFO {{{ +let PLUGIN_INFO = xml` +<VimperatorPlugin> +<name>GoogleSelect</name> +<name lang="ja">グーグルセレクト</name> +<description>you can quick select in Google search result page</description> +<description lang="ja">Google検索結果からページ選択を楽にできる</description> +<version>1.0</version> +<author mail="hiro@elzup.com" homepage="blog.elzup.com">elzup</author> +<minVersion>1.0</minVersion> +<maxVersion>2.0pre</maxVersion> +<detail lang="ja"><![CDATA[ +]]></detail> +</VimperatorPlugin>`; +// }}} + +(function () { + var google_url = 'https:\/\/www.google.co.jp\/search.*'; + /* user config */ + // 選択状態表示マーカー + var SELECT_MARKER_CHAR = '▶'; + // マーカー位置微調整 + var SELECT_MARKER_REPOSITION_LEFT = '0em'; + var SELECT_MARKER_REPOSITION_TOP = '0.3em'; + + /* hard config */ + var GOOGLE_SELECTION_CLASS = 'r'; + var GOOGLE_SELECTION_SELECTED_CLASS = 'r-selected'; + + commands.addUserCommand( + ['googleselect'], + 'move select in google search result', + function (args) { + var v = 1; + if (args.length && args[0] == 'back') { + v = -1; + } + var $rs = window.content.window.document.getElementsByClassName(GOOGLE_SELECTION_CLASS); + var pre = -1; + for (var i = 0; i < $rs.length; i++) { + if ($rs[i].className.indexOf(GOOGLE_SELECTION_SELECTED_CLASS) != -1) { + pre = i; + break; + } + } + // ターゲット表示スタイル + var $pointer = window.content.window.document.createElement('span'); + $pointer.style.color = 'blue'; + $pointer.id = 'google-select-pointer'; + $pointer.style.position = 'absolute'; + $pointer.style.marginTop = SELECT_MARKER_REPOSITION_TOP; + $pointer.style.left = SELECT_MARKER_REPOSITION_LEFT; + $pointer.innerHTML = SELECT_MARKER_CHAR; + + if (pre != -1) { + // 現在の選択状態削除 + $rs[pre].className = GOOGLE_SELECTION_CLASS; +// $rs[pre].style.borderLeft = "none"; + $rs[pre].childNodes[0].blur(); + var $e = window.content.window.document.getElementById('google-select-pointer'); + $e.parentNode.removeChild($e); + } else if (v == -1) { + pre = $rs.length; + } + if ((pre == 0 && v == -1) || (pre == $rs.length - 1 && v == 1)) { + return; + } + +// $rs[pre + v].style.borderLeft = "solid 5px blue"; + $rs[pre + v].className = $rs[pre + v].className + " " + GOOGLE_SELECTION_SELECTED_CLASS; + $rs[pre + v].childNodes[0].focus(); + $rs[pre + v].parentNode.parentNode.insertBefore($pointer, $rs[pre + v].parentNode.parentNode.firstChild); + }, + { + literal: 0, + bang: true, + count: true, + argCount: '?', + options: [], + completer: function (context, args) { + context.title = ['value', 'description']; + context.completions = [ + ['front', 'move front item'], + ['back', 'move back item'] + ]; + } + }, + true // replace + ); + + +})(); + +// vim:sw=2 ts=2 et si fdm=marker: + |