Greasy Fork is available in English.

Fix Google Search Options

Google検索で検索オプションのメニューをサイドバーへ移して表示します

  1. // ==UserScript==
  2. // @name Fix Google Search Options
  3. // @description Google検索で検索オプションのメニューをサイドバーへ移して表示します
  4. // @namespace https://pcvogel.sarakura.net/
  5. // @include http://*.google.*/search?*
  6. // @include https://*.google.*/search?*
  7. // @include http://*.google.*/images?*
  8. // @include https://*.google.*/images?*
  9. // @exclude https://*.google.*/*tbm=shop*
  10. // @exclude https://*.google.*/*tbm=bks*
  11. // @exclude https://*.google.*/*tbm=app*
  12. // @exclude https://*.google.*/*tbm=lcl*
  13. // @exclude https://*.google.*/preferences?*
  14. // @grant GM_addStyle
  15. // @version 1.4.6
  16. // @license MIT
  17. // ==/UserScript==
  18.  
  19. (function() {
  20.  
  21. var CSS =
  22. '#center_col{ margin-left:20px !important; }';
  23. GM_addStyle(CSS);
  24.  
  25.  
  26. //lr:検索範囲
  27. function get_form_lr(){
  28.  
  29. var list = ['lang_ja', 'lang_en',''];
  30. var strlist = ['日本語のページ', '英語のページ','ウェブ全体'];
  31.  
  32. var baseurl = document.location.href.replace(/lr=([^&]+)&?/, '');
  33. var current = (RegExp.$1)? RegExp.$1 : '';
  34. var generateOption = function(v) {
  35. var i;
  36. var valuestr;
  37. for( i = 0 ; i < list.length ; i++ ){
  38. if( v == list[i] ){
  39. valuestr = strlist[i];
  40. }
  41. }
  42. return '<option value="' + v + '"'
  43. + ((v == current)? ' selected="1"' : '') + '>' + valuestr + '</option>';
  44. };
  45. var opts = list.map(generateOption).join("\n");
  46.  
  47. return '<select id="get_form_lr" style="width:110px" size="3" name="lr2" >' + opts + '</select>';
  48.  
  49. }
  50.  
  51.  
  52.  
  53. //検索期間
  54. function get_form_qdr(){
  55.  
  56. var list = ['', 'qdr%3Ah','qdr%3Ad','qdr%3Aw','qdr%3Am','qdr%3Am3','qdr%3Am6','qdr%3Ay','qdr%3Ay3',];
  57. var strlist = ['期間指定なし','1 時間以内','24 時間以内','1 週間以内','1 か月以内','3 か月以内','6 か月以内','1 年以内','3 年以内'];
  58.  
  59. var baseurl = document.location.href.replace(/tbs=([^&]+)&?/, '');
  60. var currenttbs = (RegExp.$1)? RegExp.$1 : '';
  61.  
  62. currenttbs = currenttbs.replace(/\:/, '%3A');
  63. var notqdr_tbs = currenttbs.replace(/,?(qdr%3A[^&^,]+)[&,]?/, '');
  64.  
  65. var currentqdr;
  66. if( notqdr_tbs == currenttbs ){
  67. currentqdr = '';
  68. }else{
  69. currentqdr = RegExp.$1;
  70. }
  71. currentqdr = currentqdr.replace(/%2C.+/, '');
  72. currentqdr = currentqdr.replace(/,.+/, '');
  73.  
  74. var generateOption = function(v) {
  75. var i;
  76. var valuestr;
  77. for( i = 0 ; i < list.length ; i++ ){
  78. if( v == list[i] ){
  79. valuestr = strlist[i];
  80. }
  81. }
  82. var newtbs;
  83. if( currenttbs == '' ){
  84. if( v == '' ){
  85. newtbs = '';
  86. }else{
  87. newtbs = 'tbs=' + v;
  88. }
  89. }else{
  90. if( currentqdr == '' ){
  91. if( v == '' ){
  92. newtbs = 'tbs=' + currenttbs;
  93. }else{
  94. newtbs = 'tbs=' + currenttbs + ',' + v;
  95. }
  96. }else{
  97. if( v == '' ){
  98. newtbs = 'tbs=' + notqdr_tbs;
  99. }else{
  100. newtbs = 'tbs=' + notqdr_tbs + ',' + v;
  101. }
  102. }
  103. }
  104. newtbs = newtbs.replace( /tbs=,/ , 'tbs=');
  105. return '<option value="' + newtbs
  106. + ((v == currentqdr)? '" selected="1"' : '"') + '>' + valuestr + '</option>';
  107. };
  108. var opts = list.map(generateOption).join("\n");
  109.  
  110. return '<select id="get_form_qdr" style="width:110px" size="9" name="qdr2">' + opts + '</select>';
  111.  
  112. }
  113.  
  114.  
  115.  
  116. function get_form_iXX( regstr , argstr , list , strlist ){
  117.  
  118. var baseurl = document.location.href.replace(/tbs=([^&]+)&?/, '');
  119. var currenttbs = (RegExp.$1)? RegExp.$1 : '';
  120.  
  121. currenttbs = currenttbs.replace(/\:/g, '%3A');
  122. currenttbs = currenttbs.replace(/,,/, ',');
  123. var notiXX_tbs = currenttbs.replace( regstr , '' );
  124.  
  125. var currentiXX;
  126. if( notiXX_tbs == currenttbs ){
  127. currentiXX = '';
  128. }else{
  129. currentiXX = RegExp.$1;
  130. }
  131. currentiXX = currentiXX.replace(/%2C.+/, '');
  132. currentiXX = currentiXX.replace(/,.+/, '');
  133.  
  134. var generateOption = function(v) {
  135. var i;
  136. var valuestr;
  137. for( i = 0 ; i < list.length ; i++ ){
  138. if( v == list[i] ){
  139. valuestr = strlist[i];
  140. }
  141. }
  142. var newtbs;
  143. if( currenttbs == '' ){
  144. if( v == '' ){
  145. newtbs = '';
  146. }else{
  147. newtbs = 'tbs=' + v;
  148. }
  149. }else{
  150. if( currentiXX == '' ){
  151. if( v == '' ){
  152. newtbs = 'tbs=' + currenttbs;
  153. }else{
  154. newtbs = 'tbs=' + currenttbs + ',' + v;
  155. }
  156. }else{
  157. if( v == '' ){
  158. newtbs = 'tbs=' + notiXX_tbs;
  159. }else{
  160. newtbs = 'tbs=' + notiXX_tbs + ',' + v;
  161. }
  162. }
  163. }
  164. newtbs = newtbs.replace( /tbs=,/ , 'tbs=');
  165. return '<option value="' + newtbs
  166. + ((v == currentiXX)? '" selected="1"' : '"') + '>' + valuestr + '</option>';
  167. };
  168. var opts = list.map(generateOption).join("\n");
  169.  
  170. return '<select class="D7EDBF8C40" style="width:110px" size="' + list.length + '" name="' + argstr + '2" >' + opts + '</select>';
  171.  
  172. }
  173.  
  174. function get_form_imagesearch( type ){
  175. var str = "" , bstr;
  176. if( type == 1 ){
  177. bstr = "<br><br>";
  178. }else{
  179. bstr = "<br>";
  180. }
  181.  
  182. str = "<div style=\"position:fixed;margin-left:0px; margin-top:60px; display\"><form>" +
  183. get_form_iXX( /(isz%3A[^&^,]+)[&]?/ , 'isz' , ['', 'isz%3Al','isz%3Am','isz%3Ai'],['すべてのサイズ','大','中','アイコンサイズ']) +
  184. bstr +
  185. get_form_iXX(/(ic%3A[^&^,]+)[&]?/ , 'ic' , ['', 'ic%3Acolor','ic%3Agray','ic%3Atrans'],['すべての色','フルカラー','白黒','透明']) +
  186. bstr +
  187. get_form_iXX(/(itp%3A[^&^,]+)[&]?/ , 'itp' , ['', 'itp%3Aclipart','itp%3Alineart','itp%3Aanimated'],['すべての種類','クリップアート','線画','GIF']) +
  188. bstr +
  189. get_form_iXX(/(qdr%3A[^&^,]+)[&]?/ , 'qdr' , ['', 'qdr%3Ad','qdr%3Aw','qdr%3Am','qdr%3Ay',],['期間指定なし','24 時間以内','1 週間以内','1 か月以内','1 年以内']) +
  190. bstr +
  191. get_form_iXX(/(il%3A[^&^,]+)[&]?/ , 'qdr' , ['','il%3Acl','il%3Aol' ],['すべて','クリエイティブ・コモンズ ライセンス','商用およびその他のライセンス']) +
  192. "</form></div>";
  193. return str;
  194. }
  195.  
  196.  
  197. var e;
  198. var style;
  199.  
  200. var targetElement , newDiv , parentDiv;
  201. if( document.URL.indexOf("tbm=") == -1 ){
  202.  
  203. targetElement = document.getElementById('center_col');
  204. newDiv = document.createElement("div");
  205. newDiv.style.position = "fixed";
  206. newDiv.style.left = "30px";
  207. newDiv.style.top = "200px";
  208. newDiv.style.zIndex = 90000;
  209. newDiv.innerHTML = "<form>" + get_form_lr() + "<br><br>" + get_form_qdr() + "</form>";
  210. parentDiv =targetElement.parentNode;
  211. parentDiv.insertBefore(newDiv, parentDiv.firstChild);
  212.  
  213. document.getElementById('rcnt').style.paddingLeft = (newDiv.clientWidth+30).toString(10) + "px";
  214.  
  215. var entryElement;
  216. entryElement = document.getElementById('get_form_qdr');
  217. entryElement.addEventListener('change', function() {
  218. var baseurl = document.location.href.replace(/&+tbs=([^&]+|)(&+|$)/, '&');
  219. var url = baseurl.replace(/https*:\/\/www\.google\.co\.jp\/search\?/, 'search?');
  220. url = url + '&' + this.options[ this.selectedIndex ].value;
  221. location.href = url;
  222. url = url.replace( /,,/ , ',' );
  223. url = url.replace( /,$/ , '' );
  224. });
  225. entryElement = document.getElementById('get_form_lr');
  226. entryElement.addEventListener('change', function() {
  227. var baseurl = document.location.href.replace(/&+lr=([^&]+|)(&+|$)/, '&');
  228. baseurl = baseurl.replace( /\?lr=.+?&/ , '?' );
  229. var url = baseurl.replace(/https*:\/\/www\.google\.co\.jp\/search\?/, 'search?');
  230. url = url + '&lr=' + this.options[ this.selectedIndex ].value;
  231. location.href = url;
  232. });
  233. }
  234.  
  235. if( document.URL.indexOf("tbm=isch") > 0 ){
  236.  
  237.  
  238. trustedTypes.createPolicy('default', {
  239. createHTML: (unsafeValue) => {
  240. return unsafeValue;
  241. }
  242. });
  243.  
  244. e = document.getElementById('islrg');
  245. e = document.getElementById('kO001e');
  246.  
  247. newDiv = document.createElement("div");
  248. newDiv.style.position = "fixed";
  249. newDiv.style.left = "30px";
  250. newDiv.style.top = "200px";
  251. newDiv.style.zIndex = 90000;
  252. newDiv.innerHTML = get_form_imagesearch(1);
  253. e.appendChild(newDiv);
  254.  
  255. style = document.createElement("style");
  256. style.setAttribute( "type" , "text/css" );
  257. style.appendChild( document.createTextNode("") );
  258. document.getElementsByTagName("head")[0].appendChild(style);
  259. style.sheet.insertRule(".islrc {padding-left:160px !important; width:90% !important;}" , style.sheet.cssRules.length );
  260.  
  261.  
  262. e = document.getElementsByClassName('D7EDBF8C40');
  263. for( var i = 0; i < e.length ; i++ ){
  264. e[i].addEventListener('click', function() {
  265. var baseurl = document.location.href.replace(/&+tbs=([^&]+|)(&+|$)/, '&');
  266. var url = baseurl.replace(/https*:\/\/www.google.co.jp\/search\?/, 'search?');
  267. url = url + '&' + this.options[ this.selectedIndex ].value;
  268. url = url.replace( /,,/ , ',' );
  269. url = url.replace( /,$/ , '' );
  270. location.href = url;
  271. });
  272. }
  273. return;
  274. }
  275.  
  276. })();
  277.  
  278.  
  279.  
  280.