ゼロと無限の間に

フリーでオープンソースなJavaScriptとかPHPとか。

ユーザ用ツール

サイト用ツール


greasemonkey:google-search-date-limiter

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
最新のリビジョン両方とも次のリビジョン
greasemonkey:google-search-date-limiter [2011/04/27 22:31] – 0.3.0 インスタント検索に対応 dgbadmingreasemonkey:google-search-date-limiter [2014/08/24 22:40] – 0.7.0 dgbadmin
行 5: 行 5:
  
 ===== 使い方 ===== ===== 使い方 =====
-インストールすると、テキストボックスと検索ボタンの間に期間を指定する選択リスト(ドロップダウンリスト)が表示される\\+インストールすると、テキストボックスと検索ボタンの間に期間を指定する選択リスト(ドロップダウンリスト)が表示される 
 {{:javascript:google-search-result.jpg|}} {{:javascript:google-search-result.jpg|}}
 +
 +※この画面イメージは古いGoogle検索のときのもの
  
 期間を指定したい時だけ、好きな期間を選択して検索すればOK。 期間を指定したい時だけ、好きな期間を選択して検索すればOK。
行 15: 行 18:
  
  
-===== インストール ===== +===== ダウンロード・インストール ===== 
-[[http://0-oo.net/us/google_search_date_limiter.user.js|google_search_date_limiter.user.js]]+[[https://0-oo.googlecode.com/svn/trunk/us/google_search_date_limiter.user.js|Google Code]]からどうぞ。
  
  
行 25: 行 28:
 // @namespace   http://0-oo.net/ // @namespace   http://0-oo.net/
 // @description Add the date-range selector on Google Search. // @description Add the date-range selector on Google Search.
-// @homepage    http://0-oo.net/sbox/greasemonkey/google-search-date-limiter +// @homepage    http://0-oo.net/log/category/javascript/google-search-date-limiter/ 
-// @version     0.3.0 +// @version     0.7.0 
-// @include     http://www.google.tld/search* +// @grant       none 
-// @include     http://www.google.tld/webhp* +// @include     http*://www.google.tld/search* 
-// @include     http://www.google.tld/ig* +// @include     http*://www.google.tld/webhp* 
-// @include     http://www.google.tld/+// @include     http*://www.google.tld/imghp 
 +// @include     http*://www.google.tld/ig* 
 +// @include     http*://www.google.tld/#
 +// @include     http*://www.google.tld/
 // ==/UserScript== // ==/UserScript==
 // //
 // ( The MIT License ) // ( The MIT License )
 // //
-(function(){ +setInterval(function() { 
- var selStyle = "margin-top:5px"; //select要素のスタイル+ if (document.getElementsByTagName("SELECT").length) { //消えたらまた追加する 
 + return; 
 +
 +     
 + var btn document.getElementsByName("btnG")[0];
   
- var btn = document.getElementsByName("btnG")[0]; //検索ボタン + if (!btn) { 
- btn.parentNode.setAttribute("style", "white-space:nowrap"); + return; 
- var insertBefore function(elm{ btn.parentNode.insertBefore(elm, btn); };+
 +  
 + var btnDiv btn.parentNode.parentNode; //検索ボタンを含むdiv 
 + btnDiv.setAttribute("style", "white-space:nowrap"); 
 +  
 + //(あれば)指定された期間 
 + var selected decodeURIComponent(location.search).match(/tbs=qdr:([a-z])([0-9]+)/) || [];
   
  //数字のselect  //数字のselect
  var selNum = document.createElement("select");  var selNum = document.createElement("select");
- selNum.setAttribute("style", selStyle); 
  selNum.appendChild(document.createElement("option"));  selNum.appendChild(document.createElement("option"));
   
- for (var i = 1; i < 13i++) {+ for (var i = 1; i < 60;) {
  var opt = document.createElement("option");  var opt = document.createElement("option");
  opt.appendChild(document.createTextNode(i));  opt.appendChild(document.createTextNode(i));
 +
 + if (i == selected[2]) {
 + opt.selected = true;
 + }
 +
  selNum.appendChild(opt);  selNum.appendChild(opt);
 +
 + if (i < 10) {
 + i++;
 + } else {
 + i += 10; //10以上は10ずつ増加
 + }
  }  }
   
- insertBefore(selNum);+ btnDiv.appendChild(selNum);
   
  //単位のselect  //単位のselect
  var selUnit = document.createElement("select");  var selUnit = document.createElement("select");
- selUnit.setAttribute("style", selStyle); + var units = {}, suffix = "";
- var units = {};+
   
  if (navigator.language == "ja") {  if (navigator.language == "ja") {
- units = { d: "日", w: "週間", m: "ヶ月", y: "年" };+ units = { s: "秒", n: "分", h: "時間", d: "日", w: "週間", m: "ヶ月", y: "年" }
 + suffix = " 以内";
  } else {  } else {
-  units = { d: "day(s)", w: "week(s)", m: "month(s)", y: "year(s)" };+  units = { s: "second", n: "minute", h: "hour", d: "day", w: "week", m: "month", y: "year" }; 
 + suffix = "(s)";
  }  }
   
行 69: 行 96:
  opt = document.createElement("option");  opt = document.createElement("option");
  opt.setAttribute("value", val);  opt.setAttribute("value", val);
- opt.appendChild(document.createTextNode(units[val] + " 以内のみ"));+ opt.appendChild(document.createTextNode(units[val] + suffix)); 
 +  
 + if (val == selected[1]) { 
 + opt.selected = true; 
 +
 +
  selUnit.appendChild(opt);  selUnit.appendChild(opt);
  }  }
   
- selUnit.selectedIndex = 2; //デフォルトは"月" + if (!selected[1]) { 
- insertBefore(selUnit);+ selUnit.selectedIndex = 5; //デフォルトは"月" 
 + }
   
- document.forms[0].addEventListener("submit", function() { + btnDiv.appendChild(selUnit); 
- if (!selNum.selectedIndex) { +  
- return; //数字を選んだ場合のみ期間限定にする + btn.addEventListener("click", function() { 
-+ var url = "/search?q=";
-  +
- var url = location.href.split("/").slice(0, 3).join("/") + "/search?q=";+
   
  //検索ワード  //検索ワード
  url += encodeURIComponent(document.getElementsByName("q")[0].value);  url += encodeURIComponent(document.getElementsByName("q")[0].value);
   
- //期間 + if (selNum.selectedIndex) { 
- var qdr = "qdr:" + selUnit.options[selUnit.selectedIndex].value; + //期間 
- qdr += selNum.options[selNum.selectedIndex].text; + var qdr = "qdr:" + selUnit.options[selUnit.selectedIndex].value; 
- url += "&tbs=" + qdr;+ qdr += selNum.options[selNum.selectedIndex].text; 
 + url += "&tbs=" + qdr
 +
 +  
 + //(あれば)検索種類(画像検索等) 
 + url += location.href.match(/&tbm=[a-z]+/) || ""; 
 +  
 + //(あれば)表示言語 
 + url += location.href.match(/&hl=[-a-z]+/i) || "";
   
  //(あれば)言語での絞り込み  //(あれば)言語での絞り込み
  url += location.href.match(/&lr=lang_[-a-z]+/i) || "";  url += location.href.match(/&lr=lang_[-a-z]+/i) || "";
   
- //インスタント検索が有効な場合は生成したURLにちょっと待ってから遷移 + location.href = url; 
- setTimeout(function() { location.href = url; }, 900); + }, true); 
-  +}, 10);  //レンダリグ後のイミ見計らう
- //タント検索が無効な場合は既存のformに隠し項目追加 +
- var hdn = document.createElement("input"); +
- hdn.setAttribute("name", "tbs"); +
- hdn.setAttribute("type", "hidden"); +
- hdn.value = qdr; +
- insertBefore(hdn); +
- }, false); +
-})();+
 </code> </code>
  
greasemonkey/google-search-date-limiter.txt · 最終更新: 2015/09/19 21:14 by dgbadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki