From d37ef3e6cbba87d14505d8d12d3402d6e96bbb8d Mon Sep 17 00:00:00 2001 From: elzup Date: Fri, 27 Jun 2014 21:02:18 +0900 Subject: create pushfind.js --- pushfind.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 pushfind.js diff --git a/pushfind.js b/pushfind.js new file mode 100755 index 0000000..04e0c8f --- /dev/null +++ b/pushfind.js @@ -0,0 +1,53 @@ + +// PLUGIN_INFO {{{ +let PLUGIN_INFO = xml` + + PushFind + プッシュファインド + push FIndHistory word searched on google + Google検索したワードをfindの履歴に放り込みます + 1.0 + elzup + 2.0pre + 2.0pre + +`; +// }}} + +(function () { + + autocommands.add( + 'PageLoad', + 'https:\/\/www.google.co.jp\/search.*', + function (args) { + var get_regex,delimiter,res,words; + var hs = storage['history-search']; + get_regex = /google.co.jp\/search.*[&?]q=(.*?)&/; + delimiter = "+"; + res = args.url.match(get_regex); + if (res[1]) { + words = res[1].split(delimiter); + } + for (var i = 0; i < words.length; i++) { + /* + * 最近のfindワードと被っていたらそれをpopする + var l = hs.length; + for (var j = l - 1; j >= l - recent_pop; j--) { + if (hs.get(j) == words[i]) { + } + var w = hs.get(j); + } + */ + hs.push(decodeURI(words[i])); + } + + // autocommandsの出力をクリア + // 抑制方法がわからない + liberator.echomsg(""); + } + ); +})(); + +// vim:sw=2 ts=2 et si fdm=marker: + -- cgit v1.2.3 From 34815a6173f07011856a693616add6fb08fea2e3 Mon Sep 17 00:00:00 2001 From: elzzup Date: Fri, 4 Jul 2014 13:32:22 +0900 Subject: udpate pushfind multi --- pushfind.js | 123 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 89 insertions(+), 34 deletions(-) diff --git a/pushfind.js b/pushfind.js index 04e0c8f..06e3e98 100755 --- a/pushfind.js +++ b/pushfind.js @@ -2,51 +2,106 @@ // PLUGIN_INFO {{{ let PLUGIN_INFO = xml` - PushFind - プッシュファインド - push FIndHistory word searched on google - Google検索したワードをfindの履歴に放り込みます - 1.0 - elzup - 2.0pre - 2.0pre - +PushFind +プッシュファインド +push FIndHistory word searched on google +Google検索したワードをfindの履歴に放り込みます +1.1 +elzup +2.0pre +2.0pre + `; // }}} (function () { + /* n文字以下は弾く */ + var skip_char_num = 2; + /* 実行した際にコマンドラインにechoする */ + var is_echo_pushfind = true; + /* ヒットした文字列を逆に流し込む */ + var is_reverse_push = true; + var pushfind_configs = + [ +{ + name: "wikipedia", + url: 'http:\/\/ja.wikipedia.org\/wiki/*', + get_regex: /http:\/\/ja.wikipedia.org\/wiki\/([^#\/]*)/, + delimiter: "+" +}, +{ + name: "nicovideo", + url: 'http:\/\/www.nicovideo.jp\/search\/*', + get_regex: /http:\/\/www.nicovideo.jp\/search\/(.*)/, + delimiter: "%20" +}, +{ + name: "google", + url: 'https:\/\/www.google.co.jp\/search.*', + get_regex: /google.co.jp\/search.*[&?]q=(.*?)&/, + delimiter: "+" +}, +]; + + var urls,hiturl; + urls = []; + for each (var cf in pushfind_configs) { + urls.push(cf.url); + } + hiturl = "(" + urls.join("|") + ")"; autocommands.add( 'PageLoad', - 'https:\/\/www.google.co.jp\/search.*', + hiturl, function (args) { - var get_regex,delimiter,res,words; - var hs = storage['history-search']; - get_regex = /google.co.jp\/search.*[&?]q=(.*?)&/; - delimiter = "+"; - res = args.url.match(get_regex); - if (res[1]) { - words = res[1].split(delimiter); - } - for (var i = 0; i < words.length; i++) { - /* - * 最近のfindワードと被っていたらそれをpopする - var l = hs.length; - for (var j = l - 1; j >= l - recent_pop; j--) { - if (hs.get(j) == words[i]) { - } - var w = hs.get(j); - } - */ - hs.push(decodeURI(words[i])); + var words, res, hits, hs, pushwords; + hs = storage['history-search']; + for each (var cf in pushfind_configs) { + liberator.echomsg("pushfind: " + cf.name + "check start"); + pushwords = []; + hits = (args.url.match(cf.get_regex)); + if (!hits || !hits[1]) { + // liberator.echomsg(is_echo_pushfind ? "pushfind: [no hits]" + pushwords : ""); + continue; + // return; + } + res = hits[1]; + if (!cf.delimiter) { + words.push(res); + } else { + words = res.split(cf.delimiter); + } + for (var i = 0; i < words.length; i++) { + var w = decodeURI(words[i]); + if (!w || pushwords.indexOf(w) != -1) { + continue; + } + pushwords.push(w); + /* + * 最近のfindワードと被っていたらそれをpopする + var l = hs.length; + for (var j = l - 1; j >= l - recent_pop; j--) { + if (hs.get(j) == words[i]) { + } + var w = hs.get(j); + } + */ + } + if (is_reverse_push) { + pushwords.reverse(); + } + for (var i = 0; i < pushwords.length; i++) { + hs.push(pushwords[i]); + } + // autocommandsの出力をクリア + // 抑制方法がわからない + break; } - - // autocommandsの出力をクリア - // 抑制方法がわからない - liberator.echomsg(""); + liberator.echomsg(is_echo_pushfind ? "pushfind: " + pushwords : ""); } ); + liberator.echomsg("pushfind: 3.8 loaded"); })(); // vim:sw=2 ts=2 et si fdm=marker: -- cgit v1.2.3 From db1b6fc9e6dd3055cbc4686ff3dac4d2a07e1189 Mon Sep 17 00:00:00 2001 From: elzzup Date: Fri, 4 Jul 2014 13:40:12 +0900 Subject: fix echos --- pushfind.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pushfind.js b/pushfind.js index 06e3e98..ce6a145 100755 --- a/pushfind.js +++ b/pushfind.js @@ -24,25 +24,25 @@ let PLUGIN_INFO = xml` var is_reverse_push = true; var pushfind_configs = [ -{ - name: "wikipedia", - url: 'http:\/\/ja.wikipedia.org\/wiki/*', - get_regex: /http:\/\/ja.wikipedia.org\/wiki\/([^#\/]*)/, - delimiter: "+" -}, -{ - name: "nicovideo", - url: 'http:\/\/www.nicovideo.jp\/search\/*', - get_regex: /http:\/\/www.nicovideo.jp\/search\/(.*)/, - delimiter: "%20" -}, -{ - name: "google", - url: 'https:\/\/www.google.co.jp\/search.*', - get_regex: /google.co.jp\/search.*[&?]q=(.*?)&/, - delimiter: "+" -}, -]; + { + name: "wikipedia", + url: 'http:\/\/ja.wikipedia.org\/wiki/*', + get_regex: /http:\/\/ja.wikipedia.org\/wiki\/([^#\/]*)/, + delimiter: "+" + }, + { + name: "nicovideo", + url: 'http:\/\/www.nicovideo.jp\/search\/*', + get_regex: /http:\/\/www.nicovideo.jp\/search\/(.*)/, + delimiter: "%20" + }, + { + name: "google", + url: 'https:\/\/www.google.co.jp\/search.*', + get_regex: /google.co.jp\/search.*[&?]q=(.*?)&/, + delimiter: "+" + }, + ]; var urls,hiturl; urls = []; @@ -58,7 +58,7 @@ let PLUGIN_INFO = xml` var words, res, hits, hs, pushwords; hs = storage['history-search']; for each (var cf in pushfind_configs) { - liberator.echomsg("pushfind: " + cf.name + "check start"); +// liberator.echomsg("pushfind: " + cf.name + "check start"); pushwords = []; hits = (args.url.match(cf.get_regex)); if (!hits || !hits[1]) { @@ -101,7 +101,7 @@ let PLUGIN_INFO = xml` liberator.echomsg(is_echo_pushfind ? "pushfind: " + pushwords : ""); } ); - liberator.echomsg("pushfind: 3.8 loaded"); +// liberator.echomsg("pushfind: 4.1 loaded"); })(); // vim:sw=2 ts=2 et si fdm=marker: -- cgit v1.2.3 From 6c9743431ee74ae50296f596d38ec1980dc5e675 Mon Sep 17 00:00:00 2001 From: elzzup Date: Fri, 4 Jul 2014 14:22:32 +0900 Subject: udpate pushfind delimiter fix --- pushfind.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pushfind.js b/pushfind.js index ce6a145..733914d 100755 --- a/pushfind.js +++ b/pushfind.js @@ -6,7 +6,7 @@ let PLUGIN_INFO = xml` プッシュファインド push FIndHistory word searched on google Google検索したワードをfindの履歴に放り込みます -1.1 +1.2 elzup 2.0pre 2.0pre @@ -28,19 +28,19 @@ let PLUGIN_INFO = xml` name: "wikipedia", url: 'http:\/\/ja.wikipedia.org\/wiki/*', get_regex: /http:\/\/ja.wikipedia.org\/wiki\/([^#\/]*)/, - delimiter: "+" + delimiter: " " }, { name: "nicovideo", url: 'http:\/\/www.nicovideo.jp\/search\/*', get_regex: /http:\/\/www.nicovideo.jp\/search\/(.*)/, - delimiter: "%20" + delimiter: " " }, { name: "google", url: 'https:\/\/www.google.co.jp\/search.*', get_regex: /google.co.jp\/search.*[&?]q=(.*?)&/, - delimiter: "+" + delimiter: " " }, ]; @@ -58,22 +58,18 @@ let PLUGIN_INFO = xml` var words, res, hits, hs, pushwords; hs = storage['history-search']; for each (var cf in pushfind_configs) { -// liberator.echomsg("pushfind: " + cf.name + "check start"); pushwords = []; hits = (args.url.match(cf.get_regex)); if (!hits || !hits[1]) { - // liberator.echomsg(is_echo_pushfind ? "pushfind: [no hits]" + pushwords : ""); continue; - // return; } - res = hits[1]; + res = decodeURI(hits[1]).replace(/[ +]/g, cf.delimiter); if (!cf.delimiter) { words.push(res); } else { words = res.split(cf.delimiter); } - for (var i = 0; i < words.length; i++) { - var w = decodeURI(words[i]); + for each (var w in words) { if (!w || pushwords.indexOf(w) != -1) { continue; } -- cgit v1.2.3 From 81fa434afbd7589c7eecb11c014562b3dca9999b Mon Sep 17 00:00:00 2001 From: elzzup Date: Fri, 4 Jul 2014 14:29:44 +0900 Subject: update pushfind mini chars skip option --- pushfind.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pushfind.js b/pushfind.js index 733914d..35f78bd 100755 --- a/pushfind.js +++ b/pushfind.js @@ -17,7 +17,7 @@ let PLUGIN_INFO = xml` (function () { /* n文字以下は弾く */ - var skip_char_num = 2; + var skip_char_num = 1; /* 実行した際にコマンドラインにechoする */ var is_echo_pushfind = true; /* ヒットした文字列を逆に流し込む */ @@ -70,7 +70,8 @@ let PLUGIN_INFO = xml` words = res.split(cf.delimiter); } for each (var w in words) { - if (!w || pushwords.indexOf(w) != -1) { + //空白文字列,重複,短い単語のskip + if (!w || pushwords.indexOf(w) != -1 || w.length <= skip_char_num) { continue; } pushwords.push(w); -- cgit v1.2.3