Google Search Extra Buttons

Add buttons (past 1/2/3 days, weeks, PDF search etc.) for Google search page

目前为 2018-12-06 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Google Search Extra Buttons
  3. // @name:ru GoogleSearchExtraButtons
  4. // @description Add buttons (past 1/2/3 days, weeks, PDF search etc.) for Google search page
  5. // @description:ru Кнопки вариантов поиска для страницы поиска Google (1-2-3 дня, недели, PDF, ...)
  6. // @version 35.2018.12.61
  7. // @namespace spmbt.github.com
  8. // @include http://www.google.*/search*
  9. // @include https://www.google.*/search*
  10. // @include https://www.google.*/*
  11. // @include https://encrypted.google.*/search*
  12. // @include https://encrypted.google.*/*
  13. // @include https://spmbt.github.io/googleSearchExtraButtons/saveYourLocalStorage.html
  14. // @include https://www.gstatic.com/sites/p/b9356d/system/services/test.html
  15. // @include https://www.gstatic.com/index.html
  16. // ==/UserScript==
  17. var xLocStI =0, xLocSto = [{origin:'https://spmbt.github.io', restHref:'/googleSearchExtraButtons/saveYourLocalStorage.html'},
  18. {origin:'https://www.gstatic.com', restHref:'/sites/p/b9356d/system/services/test.html', '//':'blank page'},
  19. {origin:'https://www.gstatic.com', restHref:'/index.html', '//':'404 page'}];
  20. // For use own eXternal LocalStorage add to array your origin+restHref of site with https protocol,
  21. // set xLocStI pointed to it, @include directive with this URL. If this script is Chrome extension, fill include_globs in manifest.json.
  22. // TODO If localStorage will be unavailable, script will be use next indexes of array.
  23. if(location.host == xLocSto[xLocStI].origin.replace(/[^/]*\/\//,'')){
  24. window.addEventListener('message', function(ev){
  25. if(/^https?:\/\/www\.google\./.test(ev.origin)){
  26. var d = typeof ev.data =='string' && ev.data[0] =='{' ? JSON.parse(ev.data) : ev.data;
  27. if(!d.do) return;
  28. var tok = d.tok, key = d.key; try{
  29. switch(d.do){
  30. case 'set':
  31. var prev = localStorage[key];
  32. if(d.val !==undefined)
  33. localStorage[key] = JSON.stringify(d.val);
  34. else
  35. localStorage.removeItem(key);
  36. break;
  37. case 'get':
  38. prev = localStorage[key];
  39. prev = prev === undefined || typeof prev =='string'&& prev[0] !='{'? prev : JSON.parse(prev); break;
  40. case 'remove':
  41. prev = localStorage[key];
  42. if(prev !==undefined)
  43. localStorage.removeItem(key);
  44. }} catch(er){}
  45. xLocStI !=0 && console.log('[xLocSto]', tok, 'prev=', prev);
  46. xLocStI !=0 && ev.source.postMessage(JSON.stringify(prev !==undefined ? {tok: tok, prev: prev} : {tok: tok, undef:1}), ev.origin);
  47. }},!1); console.log('[xLocSto-1]_'+ xLocStI);
  48. }else (function(setts){ //lang, sites, lastHoursLess
  49.  
  50. var $x = function(el, h){if(h) for(var i in h) el[i] = h[i]; return el;} //===extend===
  51. ,$pd = function(ev){ev.preventDefault();}
  52. ,d = document
  53. ,$q = function(q, el){return (el||d).querySelector(q)}
  54. ,lh = location.href
  55. ,$e = function(g,el){ //===create or use existing element=== //g={el|clone,cl,ht,cs,at,atRemove,on,apT}
  56. g.el = el || g.el || g.clone ||'DIV';
  57. var o = g.o = g.clone && g.clone.cloneNode && g.clone.cloneNode(!0)
  58. || (typeof g.el =='string' ? d.createElement(g.el) : g.el);
  59. if(o){ //execute if exist
  60. if(g.cl)
  61. o.className = g.cl;
  62. if(g.clRemove)
  63. o.classList.remove(g.clRemove);
  64. if(g.clAdd)
  65. o.classList.add(g.clAdd);
  66. if(g.cs)
  67. $x(o.style, g.cs);
  68. if(g.ht || g.at){
  69. var at = g.at ||{}; if(g.ht) at.innerHTML = g.ht;}
  70. if(at)
  71. for(var i in at){
  72. if(i=='innerHTML') o[i] = at[i];
  73. else o.setAttribute(i, at[i]);}
  74. if(g.atRemove)
  75. for(var i in g.atRemove)
  76. o.removeAttribute(g.atRemove[i]);
  77. if(g.on)
  78. for(var i in g.on) if(g.on[i])
  79. o.addEventListener(i, g.on[i],!1);
  80. g.ap && o.appendChild(g.ap);
  81. g.apT && g.apT.appendChild(o);
  82. }
  83. return o;
  84. },
  85. addRules = function(css){$e({apT: d.getElementsByTagName('head')[0], ap: d.createTextNode(css)},'style')},
  86. //check occurrence of third-party event with growing interval: h.t=time, h.i=count, h.c=check, h.o=occur, h.m=multi
  87. CS = function(h,d){d?h.o(d):h.i--&&setTimeout(function(){CS(h,h.c())},h.t*=h.m)} //example: t:120, i:12, m: 1.6 => wait around 55 sec
  88. //for xLocStor:
  89. ,xLocStorOrigin = d.location.protocol + xLocSto[xLocStI].origin.replace(/[^/]*/,'')
  90. ,qr, qrs ={} //set of queries "key-calls" (ок, toutLitt, toutLong, noService, noStorage)
  91. ,qrI = 0 //queries counter
  92. ,qrN = 12 //max number of waiting queries
  93. ,errIMax = 120, errNMax = errIMax //max number of errors
  94. ,ns ='googXButtons_' //namespace for keys
  95. ,listenMsg
  96. /**
  97. * external localStorage for using another domain if current domain storage is erased anywhere
  98. * @param{String} h.do - action: set|get|remove
  99. * @param{String} h.key
  100. * @param{Object|undefined} h.val (any type)
  101. * @param{Number|undefined} h.toutLitt
  102. * @param{Number|undefined} h.tout
  103. * @param{Function} h.cB - callback with 2 arguments
  104. * @param{Function|undefined} h.err - callback for err with one argument
  105. */
  106. ,xLocStor = function(h){
  107. var h0 = h;
  108. h.toutLitt = h.toutLitt || 400;
  109. h.tout = h.tout || 4000;
  110. var ifr = d.getElementById('xLocStor')
  111. ,query = function(){
  112. if((qrI += 1) > qrN){
  113. xCatch('longQrs', null, h);
  114. return;}
  115. ifr.contentWindow.postMessage(JSON.stringify($x({
  116. do: h.do
  117. ,tok: token
  118. ,key: ns + h.key
  119. }, h.val !==undefined ? {val: h.val}:{}) )
  120. , xLocStorOrigin);
  121. qrs[token] = $x({ //for wait of response
  122. wToutLitt: (function(h, qrI, errIMax){return setTimeout(function(){
  123. qrI -= 1;
  124. if((errIMax -= 1) >=0)
  125. ;//console.warn('toutLitt', h);
  126. chkErrMax();
  127. }, h.toutLitt);})(h, qrI, errIMax)
  128. ,wTout: (function(h, qrI){return setTimeout(function(){
  129. qrI -= 1;
  130. //xCatch('tout', null, h);
  131. //xLocStor(h0);
  132. }, h.tout);})(h, qrI)
  133. }, h);
  134. }
  135. ,token = +new Date() + (Math.random()+'').substr(1,8)
  136. ,el = h.el;
  137. delete h.el;
  138. if(ifr) query();
  139. else ifr = $e({
  140. el: 'iframe',
  141. at:{id: 'xLocStor'
  142. ,src: xLocStorOrigin + xLocSto[xLocStI].restHref},
  143. cs: {display: 'none'},
  144. on: {load: query},
  145. apT: el || d.body
  146. });
  147. if(!listenMsg) addEventListener('message', function(ev){
  148. if(ev.origin == xLocStorOrigin){ // {"tok":"<value>"[,"err":"<txt>"],"h":...}
  149. //console.log('from_io', JSON.parse(ev.data))
  150. var resp = ev.data && ev.data[0] =='{' && JSON.parse(ev.data);
  151. if(!resp) xCatch('bad_format', resp, h);
  152. if(( qr = qrs[resp.tok] )){
  153. qrI -= 1;
  154. qr.cB(resp.prev, resp.undef);
  155. var er = qr.err;
  156. delete qrs[resp.tok];} // else ignore unsufficient token
  157. if(resp.err && (!er || er(resp.err)) ) //individual or common error processing depends of er()
  158. xCatch(resp.err, resp, h);
  159. }},!1);
  160. listenMsg =1;
  161. },
  162. //for tests: localStorage.googXButtons_dwmyh = JSON.stringify({h:[1,2,1,1,1]})
  163. //$('#xLocStor').contentWindow.postMessage('{"do":"get","key":"googXButtons_dwmyh"}',xLocSto[xLocStI].origin)
  164. xCatch = function(er, resp, h){
  165. if((errIMax -= 1) >=0)
  166. console.error('tok:', resp && resp.tok ||'--','; err:', er,'; h:', h,'; respH:', resp && resp.h);
  167. chkErrMax();
  168. },
  169. chkErrMax = function(){if(!errIMax) console.error('Too many err messages:', errNMax)}
  170. ,fileType ='PDF,DOC,RTF,ODF,XLS,ODS,PPT,ODP,TXT,XML,More..., KML,DWF,PS,WPM,BAS,C,CC,CPP,CXX, Java,PL,PY,H,HPP,CS'
  171. .split(/,\s*/).map(function(x){return '&nbsp; '+x+'&nbsp; '})
  172. ,isFTMore =0
  173. ,meta={Goog:'',Duck:'',Bing:'',Ask:'',Baidu:'',Yandex:'',Mailru:'',SlideS:''} //will create child-tabs (window names)
  174. ,imgFile='SVG,JPG,GIF,PNG,BMP,webp,ICO,RAW'.split(',').map(function(x){return '&nbsp; '+x+'&nbsp; '}) //will switch to Img Search
  175. ,imgType='face,clipart,photo,lineart,animated'.split(',') //for Img Search (+imgColor,imgSize,imgSizeLt)
  176. ,imgColor='red,orange,yellow,green,teal,blue,purple,pink,white,gray,black,brown'.split(',')
  177. ,imgSize='l,m,small,icon,>=,Exact...'.split(',')
  178. ,imgSizeLt='vga,svga,xga,2mp,4mp,qsvga'.split(',')
  179. ,$l ={ru:{
  180. 'search in PDF files':'поиск по документам PDF'
  181. ,'search in':'искать по'
  182. ,'More':'Ещё'
  183. ,'show sizes':'показывать размеры'
  184. ,'hide sizes':'скрыть размеры'
  185. ,'from / to':'за период'
  186. ,'past':['за последний','за последние','за последнюю']
  187. ,'day':'сутки'
  188. ,'days':['дня','дней']
  189. ,'week':'неделю'
  190. ,'weeks':['недели','недель']
  191. ,'month':'месяц'
  192. ,'months':['месяца','месяцев']
  193. ,'year':'год'
  194. ,'years':['года','лет']
  195. ,'hour':'час'
  196. ,'hours':['часа','часов']
  197. ,'Settings':'Настройки'
  198. ,'of userscript':'юзерскрипта'
  199. ,'reload page for effect':'перезагрузить страницу'
  200. ,'Interface language':'Язык интерфейса'
  201. ,'Less positions at the end of selects':'Меньше выбора в конце селектов'
  202. ,'Gray design of buttons':'Серый дизайн кнопок'
  203. ,'Sites':'Сайты'
  204. },fr:{
  205. 'search in PDF files':'la recherche dans les fichiers PDF'
  206. ,'search in':'rechercher dans'
  207. ,'More':'Plus'
  208. ,'show sizes':'montrer les tailles'
  209. ,'hide sizes':'masquer les tailles'
  210. ,'from / to':'pour la période'
  211. ,'past':['le dernier','dans les derniers','dans les derniers']
  212. ,'day':'jour'
  213. ,'days':['jours','jours']
  214. ,'week':'semaine'
  215. ,'weeks':['semaines','semaines']
  216. ,'month':'mois'
  217. ,'months':['mois','mois']
  218. ,'year':'an'
  219. ,'years':['ans','ans']
  220. ,'hour':'heure'
  221. ,'hours':['heures','heures']
  222. ,'Settings':'Paramètres'
  223. ,'of userscript':'de Userscript'
  224. ,'reload page for effect':'recharger la page pour effet'
  225. ,'Interface language':'Langue de l\'interface'
  226. ,'Less positions at the end of selects':'Moins de choix les longues listes'
  227. ,'Gray design of buttons':'Gris design des boutons'
  228. ,'Sites':'Les sites'
  229. },de:{
  230. 'search in PDF files':'Suche in PDF-Dateien'
  231. ,'search in':'Suche in'
  232. ,'show sizes':'Größen anzeigen'
  233. ,'More':'Mehr'
  234. ,'hide sizes':'Größen ausblenden'
  235. ,'from / to':'im Zeitraum'
  236. ,'past':['letzte','letzte','letzte']
  237. ,'day':'Tag'
  238. ,'days':['Tage','Tage']
  239. ,'week':'Woche'
  240. ,'weeks':['Wochen','Wochen']
  241. ,'month':'Monat'
  242. ,'months':['Monate','Monate']
  243. ,'year':'Jahr'
  244. ,'years':['Jahre','Jahre']
  245. ,'hour':'Stunde'
  246. ,'hours':['Stunden','Stunden']
  247. ,'Settings':'Einstellungen'
  248. ,'of userscript':'von Userscript'
  249. ,'reload page for effect':'Seite neu laden'
  250. ,'Interface language':'Sprache'
  251. ,'Less positions at the end of selects':'Weniger Auswahl in langen Listen'
  252. ,'Gray design of buttons':'Graues Design der Schaltflächen'
  253. ,'Sites':'Websites'
  254. },es:{
  255. 'search in PDF files':'búsqueda en archivos PDF'
  256. ,'search in':'busca en'
  257. ,'show sizes':'muestra los tamaños'
  258. ,'More':'Más'
  259. ,'hide sizes':'ocultar tamaños'
  260. ,'from / to':'para el período'
  261. ,'past':['el último','en los últimos','en los últimos']
  262. ,'day':'día'
  263. ,'days':['días','días']
  264. ,'week':'Semana'
  265. ,'weeks':['semanas','semanas']
  266. ,'month':'mes'
  267. ,'months':['meses','meses']
  268. ,'year':'año'
  269. ,'years':['años','años']
  270. ,'hour':'hora'
  271. ,'hours':['horas','horas']
  272. ,'Settings':'Ajustes'
  273. ,'of userscript':'de userscript'
  274. ,'reload page for effect':'página para efecto de recargar'
  275. ,'Interface language':'Idioma de interfaz'
  276. ,'Less positions at the end of selects':'Menos elección en listas largas'
  277. ,'Gray design of buttons':'Diseño gris de botones'
  278. ,'Sites':'Sitios'
  279. }},cB; //if !lang, then no hints
  280. addRules('.hp .sfsbc,.sfsbc{display: inline-block}.siteList:hover button{display: block}'
  281. +'.gb_Ib >.gb_e{height:47px}.gb_Fb{z-index:1087}.tsf-p{z-index:203}'
  282. +'.lsbb .xButt,.sbibod .xButt,.lsbb >.siteList,.sbibod >.siteList{z-index: 2002; width:34px; height:17px;'
  283. +'padding:0 2px; line-height:14px; font-size:14px; border:1px solid transparent; border-radius:2px;'
  284. +'background-color:#dddae6; color:#eee; opacity: .07; transition: opacity .57s ease-in}'
  285. +'.lsbb .xButt:not(.xButt2),.sbibod .xButt:not(.xButt2),.lsbb >.siteList{text-align: center; background-color:#4889f1; color:#fff; opacity: 0.75}'
  286. +'.xButt2{padding:0 0 2px; background-color:#dad6e2; color:#eee; opacity: 1}'
  287. +'.lsbb .xButt:hover,.sbibod .xButt:hover,.xButt.xButt2:hover .xButt2,.xButt2:hover{background-color:#c3d4e1; color:#fff; opacity:1}'
  288. +'.sbibod .xButt:hover,.sbibod .xButt2:hover,.sbibod .xButt:hover .xButt2{background-color:#c3c6c7}.lsbb >.siteList:hover{background-color:#4889f1}'
  289. +'.lsbb >.siteList,.sbibod >.siteList{width:32px; height:auto; padding:1px 0 2px; text-align:center}'
  290. +'.lsbb >.siteList .lsb,.sbibod >.siteList .lsb{font-weight: normal; color:#d4d4d4}'
  291. +'.lsbb .lsb:hover,.sbibod .lsb:hover{opacity: 1; color: #987b2b; cursor:default}'
  292. +'.sbibod >.siteList:hover,.lsbb >.siteList >div:not([class]):hover{background-color:#c2d4e0; color: #f7f7f7; opacity:.93}'
  293. +'.lsbb > .siteList > div:not([class]):hover span{color: #aa6c1c}'
  294. +'.sbibod:not(.lsbb) >.siteList, .sbibod:not(.lsbb) > .xButt2{background-color:#dddae6; opacity:.45}'
  295. +'.sbibod:not(.lsbb) >.siteList:hover, .sbibod:not(.lsbb) > .xButt2:hover{background-color:#dddae6; opacity:.87}'
  296. +'.sbibod.lsbb{height:44px}'
  297. +'.sbibod >.siteList >.list{background-color:#e1deeb}.list .more ~.xButt{display:none!important}'
  298. +'.list .moreShow ~ .xButt{position:absolute!important; left: 52px; height: 19px!important}'
  299. +'.list .moreShow~.x2.xButt, .list .moreShow~.x2 ~.xButt{left: 99px}'
  300. +'.sbibod >.siteList.fade:hover{opacity: 1; transition: opacity .1s ease-in}'
  301. +'.sbibod >.siteList.fade{opacity: 0.23}'
  302. +'.siteList .sett .txt{padding:2px 2px 4px; font-size: 14px}'
  303. +'.lsbb >.siteList .sett .txt{background-color:#4889f1}'
  304. +'.siteList .settIn{display: none; width: 250px; padding: 2px 4px; text-align:left; border:1px solid #48f; font-size: 14px;'
  305. +'background-color:#eef; color:#336}'
  306. +'.siteList .settIn hr{margin:2px 0}'
  307. +'.sbibtd .sfsbc .nojsb, .siteList .sett:hover .settIn, .siteList .settIn.changed,'
  308. +'.siteList .settIn.changed .reload{display: block}.siteList .settIn .reload, .siteList.hiddn{display: none}'
  309. +'div.gb_g[aria-label="promo"],.pdp-psy.og-pdp, .gb_Sc.gb_g .gb_ha, .gb_g.gb_ha:not(.xpdopen ){display: none}'
  310. +'.xpdopen{display: block!important}.rhsvw{opacity:.16; transition:.4s}.rhsvw:hover{opacity:1}'
  311. +'.srp #sfdiv{overflow: inherit}' //hide promo
  312. +'.UUbT9 >div.aajZCb{background-color: rgba(255, 255, 255, 0.7);}' //opacity for suggests
  313. +'.UUbT9 ul li div span b{background-color: rgba(237, 242, 248, 0.9); margin: 0 -6px 0 -1px; padding: 0 6px 0 1px;}' //white under suggest texts
  314. +'.gb_kb{padding-left: 10px; padding-right: 7px}form .RNNXgb{position: relative; background: rgba(255, 255, 255, 0.9)}'
  315. +'.RNNXgb, #tsf{width:auto!important} #searchform form#tsf{max-width:auto} body div#searchform,body .ctr-p{min-width:0}'
  316. +'div#searchform.minidiv{top: -8px!important}.minidiv .sfbg{margin-top: -26px!important}' // for narrow sticked searchbar
  317. +'.minidiv .sfbg{top: -39px}.minidiv .sfbg +form#tsf{top: -39px}.minidiv .sfbg +form#tsf:hover{top: 0}' //hide sticked
  318. +'.minidiv .sfbg +form#tsf:hover .siteList, .minidiv .sfbg +form#tsf:hover .lsbb >.xButt{top: -6px!important}'
  319. +'.RNNXgb .Tg7LZd{flex: 0 0 auto; visibility:hidden; width: 44px; height: 44px; margin-right:-31px; padding: 0 13px 0 0;'
  320. +' border-radius: 0 8px 8px 0; background: transparent; border: none; outline: none}'
  321. +'.A8SBwf .logo +.RNNXgb .Tg7LZd{visibility:visible; margin-right:-9px; margin-bottom:-2px; transition: margin 5s ease-in-out}');
  322. //console.log('==cB-00');
  323. try{xLocStor({do:'get', key:'sett', val:setts, cB: cB=function(prev,undef){
  324. //console.log('==cB-0');
  325. S = prev || setts;
  326. S.dwmyh = S.dwmyh || setts.dwmyh; //temp. transitional expr.
  327. S.hiddenEdgeLeft = setts.hiddenEdgeLeft;
  328. console.timeStamp = function(){};
  329.  
  330. CS({t:120, i:12, m: 1.6
  331. ,c: function(){
  332. return d && d.getElementsByName('q') && !/[?&]tbm=(shop|bks|fin)/.test(lh) && d.getElementsByName('q')[0];
  333. },
  334. o: function(dat){
  335. var lang = S.lang != null ? S.lang : setts.lang
  336. ,sites = S.sites && (S.sites.length && S.sites[0] || S.sites.length >1) && S.sites
  337. || typeof sites =='string'&& [sites] || !S.sites && setts.sites || null;
  338. var strSites = sites && sites.join('\n').replace(/^\n/,'\n\n') ||''
  339. ,$L = $l[lang] || $l.ru; //default template of lang
  340. if(!lang || !$l[lang] || lang =='en') for(var l in $L){ //replace 'en' lang for default or substitution
  341. if($L[l] instanceof Array) for(var l2 in $L[l])
  342. $L[l][l2] = l;
  343. else
  344. $L[l] = l;
  345. }
  346. var srch = $q('.RNNXgb')
  347. ,startPg = srch && !$q('button', srch);
  348. if(startPg){
  349. //console.log('==-==startPg', srch);
  350. $e({el:'button', cl:'Tg7LZd', at: {'aria-label':'Google Search', type:'button', jsname:'Tg7LZd'
  351. ,innerHTML:'<div class="gBCQ5d"><span class="z1asCe MZy1Rb">sr</span></div>'}
  352. , apT: srch});
  353. }
  354. var $LSettings = $L['Settings'];
  355. if(sites && sites.length)
  356. sites.push($LSettings);
  357. var mainPg = /\/search\?|&q=|#q=/.test(lh)
  358. ,inputSearch = dat
  359. ,layout1811 = $q('.Tg7LZd') || $q('button[aria-label="Google Search"]')
  360. ,design1612 = ($q('#_fZl') || $q('.sbico-c')) && !layout1811
  361. ,d16 = (design1612 || layout1811) && S.design1612
  362. ,imgSrch = /[?&]tbm=isch/.test(lh)
  363. ,imgTools = imgSrch && /[&?]tbs=[^&]*/.exec(lh) //'tbs' with all params
  364. ,isWHShown = imgTools && /[&?]tbs[^&]*?(=|,|%2C)imgo(:|%3A)1/i.exec(lh) // sizes are shown if images
  365. ,buttSearcStart = startPg && layout1811 && ($q('input[name="btnK"]') || $('input[aria-label="Google Search"]')) //for the start page
  366. ,buttSearch = d.getElementsByName('btnG') && d.getElementsByName('btnG')[0] || design1612 || layout1811
  367. ,buttS ={
  368. Srch:{url:'', txt:'search'}
  369. ,PDF:{url:'filetype:PDF', txt:$L[imgSrch?(isWHShown ?'hide':'show') +' sizes':'search in PDF files']}
  370. ,site:{url:'site:'+ S.sites[0], txt:$L['search in']+' '+ S.sites[0], one:'day'} //you may comment this line
  371. ,'.. : ..':{url:'', txt:$L['from / to']}
  372. ,'1D':{url:'&tbs=qdr:d', txt:$L['past'][1] +' '+ $L['day'], one:'day', up:13,lett:'D'}
  373. ,'1W':{url:'&tbs=qdr:w', txt:$L['past'][2] +' '+ $L['week'], one:'week', up:14,lett:'W'}
  374. ,'1M':{url:'&tbs=qdr:m', txt:$L['past'][0] +' '+ $L['month'], one:'month', up:20,lett:'M'}
  375. ,'1Y':{url:'&tbs=qdr:y', txt:$L['past'][0] +' '+ $L['year'], one:'year', up:10,lett:'Y'}
  376. ,'1H':{url:'&tbs=qdr:h', txt:$L['past'][0] +' '+ $L['hour'], one:'hour', up:23,lett:'H'}
  377. }, ii = -1, iD = -1;
  378. if((design1612 || layout1811) && !d16)
  379. buttSearch.parentNode.className +=' lsbb';
  380. !sites && delete buttS.site;
  381. if(!layout1811){ buttSearch.parentNode.style.position ='relative';
  382. buttSearch.parentNode.style.zIndex ='1003';}
  383. if(buttSearch && top == self) for(var i in buttS) if(i !='site'|| S.sites){ //buttons under search input line
  384. if(i.length ==2) iD++; else iD=-1;
  385. var bI = buttS[i]
  386. ,Gesch = ({m:'letzter',f:'letzte',n:'letztes'})['m,f,m,n,f'.split(',')[iD]]
  387. ,hint = function(j){return (j+1) +' '+ (j % 10 || j==10 ? $L[bI.one +'s'][j % 10 <4 && (j/10|0)!=1 ?0:1] : $L[bI.one]) }
  388. ,csLeft = function(ii,a){a = -127 + 37 * (ii-1 - (ii >2 && !mainPg)); return design1612 || layout1811 ?{right: -a+33+'px'}:{left: a+'px'}}
  389. ,isWHShown2 = isWHShown && i=='PDF'
  390. ,butt2 = $e({clone: i =='site'|| i.length ==2 || i=='PDF'
  391. ? $e({cl: 'siteList', cs: {cursor:'default'}, at: {site: S.sites[0], date: bI.url} })
  392. : i !='.. : ..'|| mainPg ? $e({el:'button', cl: 'xButt ' +(d16 ?'xButt2':'lsb')}) : $e({cl: 'siteList hiddn'})
  393. ,at: {value: iD !=-1 && S.dwmyh[iD] !=1 ? S.dwmyh[iD] + bI.lett : i
  394. ,innerHTML: '<div'+ (d16 ?' class=xButt2':'') +'><s'+ (isWHShown2?'':'pan') +' class=txt onclick=this.parentNode.click();return!1 title="'
  395. +(lang || i=='site'|| i=='.. : ..'
  396. ? (iD==-1 || S.dwmyh[iD]==1 ? bI.txt : $L['past'][1] +' '+ hint(S.dwmyh[iD]-1)).replace(/letzte/,Gesch) :'')
  397. +'" itrvNum="'+ (i=='site'?'': bI.url + S.dwmyh[iD]) +'">'
  398. +(iD !=-1 && S.dwmyh[iD] !=1 ? S.dwmyh[iD] + bI.lett : imgSrch && i=='PDF' ?'WxH': i) +(isWHShown2?'/s>':'</span>')+'</div>'}
  399. ,cs: $x({position:'absolute', top:startPg ?'40px':'33px',wordSpacing:'-1px', display: ii < S.hiddenEdgeLeft ?'none':'block'}, csLeft(++ii))
  400. ,on: {click: (function(bI, i, iD){
  401. //console.log('clic0:', i, iD);
  402. return /Srch|PDF|DOC|site/.test(i)
  403. ? function(ev){
  404. var t = ev.target;
  405. //console.log('cli-DocSite: i,t.class,value,ev,attrSite,$LS,aPSite,bSSta',i, t.className, inputSearch.value,ev, 'attrSite:'
  406. // ,t.getAttribute('site'),'aP:', t.parentNode.getAttribute('site'), buttSearcStart);
  407. if(t.className =='defa')
  408. saveLocStor('','','remove'); $pd(ev);
  409. if((t.getAttribute('site')==$LSettings || t.parentNode.getAttribute('site')==$LSettings)
  410. && !/Srch|PDF|DOC/.test(i)) return;
  411. if(t.className !='txt')
  412. inputSearch.value = (inputSearch.value||'').replace(/( site(:|%3A)\s*\S*|$)/ig, /Srch|site/.test(i)?'':'$1').replace(/( |\+|&as_)filetype(:|%3A)[^\&]*/g,'')
  413. +' '+ (/Srch|PDF|DOC/.test(i) ? imgSrch ?'': bI.url
  414. : 'site:'+ (t.getAttribute('site')|| t.parentNode.getAttribute('site')||''));
  415. if(t.getAttribute('site') ==null && t.parentNode.getAttribute('site') ==null && !/Srch|PDF|DOC/.test(i))
  416. return;
  417. if(imgSrch && i=='PDF'){
  418. ev.stopPropagation();
  419. S.imgWHShown = !isWHShown; //TODO for going to link of Images Search
  420. saveLocStor();
  421. location.href = isWHShown ? lh.replace(new RegExp(imgTools[0]), imgTools[0]
  422. .replace(/(,|%2C)?imgo(:|%3A)1/ig,'').replace(/([?&])tbs=?,?(&|$)/,'$1')) //hide sizes
  423. : imgTools ? lh.replace(new RegExp(imgTools[0]), imgTools[0] + (imgTools[0].length <5 ?'':',') +'imgo:1') //upd.'Show'
  424. : lh + (/\?/.test(lh) ?'&':'?') +'tbs=imgo:1'; //new Tools-More_tools_Show_sizes
  425. }else if(/xButt|txt/.test(t.className) && !(i=='site'&& !(/list/.test(t.parentNode.className)
  426. || /list/.test(t.parentNode.parentNode.className))) || /Srch|PDF|DOC/.test(t.value))
  427. /*console.log('==startSrch'),*/(buttSearcStart || buttSearch).click();
  428. }: !bI.url ? function(ev){ //from-to date
  429. var el = $q('#cdrlnk'), o;
  430. el && el.dispatchEvent(((o = d.createEvent('Events')).initEvent('click', !0, !1), o));
  431. $pd(ev);
  432. }: function(ev){ //past interval
  433. var t = ev && ev.target, sbd = /,sbd:1/.test(lh), ta = t
  434. ,tOvr = t && t.parentNode, tOv0 = tOvr
  435. ,date2 = tOvr.getAttribute('date');
  436. var l2 = startPg ? lh.replace(/^([^/]*)\/\/([^/]+)\/?([^?#]*)([?#]?.*)/, '$1//$2/search$4') : lh; // insert '/search?' instead any
  437. //console.log('cli-Past: value,date2,siteList,list,l2',inputSearch.value,date2,tOvr.classList.contains('siteList'), t.classList.contains('list'), l2);
  438. if(tOvr.classList.contains('siteList') && !ta.classList.contains('list')){ //clicked by top button
  439. var elTop = $q('div:not(.list) >.txt', tOvr) ||''
  440. ,itrvNum = elTop && elTop.getAttribute('itrvNum') ||''
  441. ,newSrch = /[?&]q=/.test(l2) ? l2.replace(/(&|\?)q=([^&]*)(&|$)/g,'$1q='+ encodeURIComponent(inputSearch.value) +'$3') //add value to '[?&]q=[^&]*'
  442. : l2 + (/\?/.test(l2) ?'&':'?') +'q='+ encodeURIComponent(inputSearch.value); //set new value as &q=.+
  443. if(layout1811 && itrvNum !=='' && date2)
  444. location.href = /qdr(:|%3A)([dwmyh])\d*/.test(l2)
  445. ? newSrch.replace(/([?&]tbs=)?qdr(:|%3A)[dwmyh]\d*/
  446. ,function(x){return itrvNum.replace(/&/, /\?/.test(x) ?'?':'&')}) //patch date in URL
  447. : newSrch + (/\?/.test(newSrch) ?'&':'?') + itrvNum; //add date in URL
  448. if(itrvNum != null) S.dwmyh[iD] = +(itrvNum ||'').replace(/\D/g,'');
  449. }else if(t.textContent || tOv0.textContent){
  450. var sa = (t.textContent || tOv0.textContent ||'').replace(/\D/g,'');
  451. if(sa.length <=6)
  452. S.dwmyh[iD] = +sa;
  453. }
  454. //console.log('==noDocNoSite', tOvr.value, itrvNum);
  455. $pd(ev);
  456. ev.stopPropagation();
  457. saveLocStor();
  458. }
  459. })(bI, i, iD),
  460. mouseover: i =='site' || i.length ==2 || i=='PDF' ? (function(bI,i){return function(ev){
  461. clearTimeout(bI.ww);
  462. var t = ev.currentTarget;
  463. t.classList.add('fade');
  464. $q('.list', t).style.display ='block';
  465. }})(bI,i) :'',
  466. mouseout: i =='site' || i.length ==2 || i=='PDF' ? (function(bI,i){return function(ev){
  467. var t = ev.currentTarget;
  468. clearTimeout(bI.ww);
  469. bI.ww = setTimeout(function(){
  470. $q('.list',t).style.display ='none';
  471. t.classList.remove('fade');
  472. }, 570);
  473. }})(bI,i) :'',
  474. change: saveLocStor
  475. }
  476. ,apT: buttSearch.parentNode
  477. });
  478. bI.el = butt2;
  479. if(i =='site' || i.length ==2 || i =='PDF'){ //dropdown lists under some buttons
  480. var siteList = $e({cl:'list',cs:{display:'none'}, apT: butt2}), arr =[];
  481. for(var j =0; j <= bI.up -1 -(i=='1W'&& S.lastHoursLess ?4:0) -(i=='1M'&& S.lastHoursLess ?9:0); j++)
  482. if(i !='1H' || !S.lastHoursLess || j < 8 || j % 2 )
  483. arr.push(hint(j));
  484. //console.log(S.sites,i, S.dwmyh);
  485. var list = i=='site' ? sites||[] : i =='1D'&& !sites ? arr.concat([$LSettings])
  486. : i=='PDF'? imgSrch ? imgFile : fileType : arr,
  487. fTMoreX2 =0;
  488. for(var j in list) if(j !=0 || iD!=-1 && S.dwmyh[iD] !=1){
  489. //console.log('==i,sI', i, sI);
  490. fTMoreX2 = /CPP/.test(fTyp) || fTMoreX2;
  491. var sI = list[j]
  492. ,fTyp = sI.replace(/&nbsp; ?/g,'')
  493. ,fTMore = /More\.\.\./.test(fTyp)
  494. ,butt3 = $e({clone: sI==$LSettings ? $e({cl: 'sett' +(d16 ?' xButt xButt2':' lsb')})
  495. : $e({el:'button', cl: 'xButt' +(d16 ?' xButt2':' lsb') +(fTMore ?' more':'') +(fTMoreX2 ?' x2':'')})
  496. ,at:{value: sI
  497. ,site: sI
  498. ,date: bI.url.replace(/pdf$/i, fTyp)
  499. ,title: sI==$LSettings || !lang ?'':(/site|PDF/.test(i)
  500. ? ($L[i=='PDF'?'search in PDF files':'search in'] +(i=='PDF'?'':' '+ sI)).replace(/PDF/,fTyp)
  501. : j==0 ? bI.txt : $L['past'][1] +' '+ sI).replace(/letzte/,Gesch)
  502. ,innerHTML:'<span class=txt>'+ sI +'</span>'+ (sI != $LSettings &&!(!S.sites && i =='1H')
  503. ?'':'<div class="settIn">'
  504. +$L.Settings +' '+ $L['of userscript'] +'<br/>"Google Search Extra Buttons"<hr/>'
  505. +$L['Interface language'] +': <select class="lang" style="width:70px">'
  506. +(function(){var s='<option'+ (lang=='en'?' selected':'') +'>en</option>';
  507. for(var i in $l)
  508. s+='<option'+ (lang==i ?' selected':'') +'>'+ i +'</option>';
  509. return s +'<option value=""'+ (lang==''?' selected':'') +'>en w/o hints</option>'})()
  510. +'</select><br/>'
  511. +'<input type="checkbox" class="less" id="hoursLess"'+ (S.lastHoursLess ?' checked':'') +'/>'
  512. +'<label for="hoursLess" id="hoursLessL">'+ $L['Less positions at the end of selects'] +'</label><br/>'
  513. +'<input type="checkbox" class="des16" id="design1612"'+ (!layout1811 && S.design1612 ?' checked':'')+ (layout1811 ?' disabled':'') +'/>'
  514. +'<label for="design1612" id="design1612L">'+ $L['Gray design of buttons'] +'</label><br/>'
  515. +'<i><a href="#" class="defa" style="float: right">Default settings</a></i>'
  516. +$L.Sites +': <br/><textarea class="sites" style="width:97%" rows=8>'
  517. + strSites +'</textarea><br/>'
  518. +'<a class="reload" href=# onclick="location.reload();return!1">'
  519. + $L['reload page for effect'] +'</a>'
  520. +'</div>')}
  521. ,cs: Object.assign({position: (sI != $LSettings || design1612 || layout1811)&& !fTMore ?'static':'absolute',display:'block'
  522. ,width: sI != $LSettings ?'auto': /en|es/.test(lang)||!lang ?'4em':'6.2em'
  523. ,height: sI != $LSettings ?'18px':'16px',margin:'2px 0 -1px -13px', padding:'0 2px 0 1px', minWidth:'42px'
  524. ,top: (19* j - 175 - 133* fTMoreX2) +'px'
  525. ,textAlign:'left', fontWeight:'normal', opacity:1, whiteSpace:'nowrap'}, fTMore ?{top:'18px',left:'47px'}:{})
  526. ,on:{click: (function(fTyp,pdf,fTMore){return function(ev){
  527. var less = $q('#hoursLess')
  528. ,des16 = $q('#design1612') && !layout1811, t = ev.target
  529. ,itrv = t.getAttribute('date')||t.parentNode.getAttribute('date')||''
  530. ,num = (t.getAttribute('site')||t.parentNode.getAttribute('site')||'').replace(/\D/g,'');
  531. //console.log('==clic3:t,itrv,num,fTyp,pdf:',t, itrv, num,'|',fTyp,pdf);
  532. if(less && /hoursLess/.test(t.id)){
  533. less.outerHTML = '<input type="checkbox" class="less" id="hoursLess"'
  534. +(less.getAttribute('checked')!=null ?'':' checked="checked"')+'/>';
  535. saveLocStor();}
  536. if(des16 && /design1612/.test(t.id)){
  537. des16.outerHTML = '<input type="checkbox" class="des16" id="design1612"'
  538. +(des16.getAttribute('checked')!=null ?'':' checked="checked"')+'/>';
  539. saveLocStor();}
  540. if(pdf || buttSearcStart && /site/.test(itrv)) {//console.log('==pdf|site');
  541. inputSearch.value = inputSearch.value.replace(/ filetype(:|%3A)\s*\S*|$/
  542. ,fTMore ?'': ' '+ (imgSrch? itrv.toLowerCase() : itrv +(pdf ?'': fTyp)));}
  543. var l2 = startPg ? lh.replace(/^([^/]*)\/\/([^/]+)\/?([^?#]*)([?#]?.*)/, '$1//$2/search$4') : lh // insert '/search?' instead any
  544. ,newSrch = /[?&]q=/.test(l2) ? l2.replace(/(&|\?)q=([^&]*)(&|$)/g,'$1q='+ encodeURIComponent(inputSearch.value) +'$3') //add value to '[?&]q=[^&]*'
  545. : l2 + (/\?/.test(l2) ?'&':'?') +'q='+ encodeURIComponent(inputSearch.value); //set new value as &q=.+
  546. //console.log('==inputSearch.value,newSrch,fTyp,pdf,num', inputSearch.value, newSrch, fTyp, pdf, num);
  547. if(buttSearcStart && (pdf && !fTMore || num !==''&& num != +num)){buttSearcStart.click();ev.stopPropagation();return}
  548. if(layout1811 && num !==''|| pdf) {pdf && ev.stopPropagation();
  549. if(!fTMore) location.href = /qdr(:|%3A)([dwmyh])\d*/.test(l2)
  550. ? newSrch.replace(/([?&]tbs=)?qdr(:|%3A)[dwmyh]\d*/
  551. ,function(x){return pdf ?'': (itrv + num).replace(/&/, /\?/.test(x) ?'?':'&')}) //patch date in URL
  552. : newSrch + (/\?/.test(newSrch) ?'&':'?') + (pdf ?'': itrv + num); //add date in URL
  553. else{if(t.classList.contains('txt')) {if(t.parentNode.classList.contains('more')) t.parentNode.className ='xButt lsb moreShow';
  554. else t.parentNode.className ='xButt lsb more';} //'className' because bug of Chrome in upper line with .toggle
  555. else {if(t.classList.contains('more')) t.className ='xButt lsb moreShow';
  556. else t.className ='xButt lsb more';}}} //bug of Fx with .toggle,.toggle - list is changed slow (0.4 s)
  557. $pd(ev);
  558. }})(fTyp,i=='PDF',fTMore)}//, mouseover: function(ev){ev.stopPropagation()}, mouseout: function(ev){ev.stopPropagation()}
  559. ,apT: siteList
  560. });}
  561. siteList.style.height ='auto'; siteList.style.textAlign ='center';
  562. }
  563. }
  564. }
  565. });
  566.  
  567. }, el: d.body})}catch(er){console.log('==cB');cB()}
  568. var saveLocStor = function(ev, val, do2){ var aaa,aab,aac,aad, t = ev && ev.target.form || document.documentElement || document.body;
  569. xLocStor({do: do2 ||'set', key:'sett'
  570. , val:{lang: (aaa=d.querySelectorAll('.lang', t))[aaa.length-1].value
  571. ,sites: ((aab=d.querySelectorAll('.sites', t))[aab.length-1].value||'').replace(/^[ \t]*|[ \n\t]*$/g,'')
  572. .split('\n')
  573. ,lastHoursLess: (aac=d.querySelectorAll('.less', t))[aac.length-1].checked
  574. ,design1612: (aad=d.querySelectorAll('.des16', t))[aad.length-1].checked
  575. ,dwmyh: S.dwmyh || setts.dwmyh
  576. ,imgWHShown: S.imgWHShown
  577. }
  578. ,cB: function(prev){
  579. console.info('Settings are saved. prev=', prev);}
  580. });
  581. $q('.siteList .settIn').classList.add('changed');
  582. };
  583.  
  584. })({ //write "lang:''," to remove hints; 'en' for English hints (fr - Français, es - espagnol), 'ru' for Russian
  585. lang:''|| (navigator.languages && navigator.languages[1] || navigator.language.substr(0,2)) //='' if hide hints, or 2 letters from $l{}
  586. ,sites: [ //=array or one site in string
  587. '','slashdot.org','reddit.com','techcrunch.com','habr.com','geektimes.com'
  588. ,'smashingmagazine.com','engadget.com'] //write your favorite sites
  589. ,design1612: 0 //=boolean - gray design is disabled for layout1811
  590. ,lastHoursLess: 1 //=boolean - not show odd some values of hours after 8 h
  591. ,dwmyh: [1,1,1,1,1] //=array of numbers - current vals of days, weeks, months, years, hours
  592. ,fileType:{} // turn on or off {doc:1, txt:1}
  593. ,meta:{} // on/off {Ask:1, }
  594. //TODO meta-data for search of same results {Ya:{title:'',txt:'',url:''},...}
  595. ,imgFile:'' // one of: switch to img search or in img search
  596. ,imgType:{} //{itp:'face'}
  597. ,imgColor:{} //{isc:'blue'}
  598. ,imgSize:{} //{isz:'i'}
  599. ,imgSizeLt:{} //{islt:'vga'}
  600. ,ShowSizes:{} //{iszw:120,iszh:120}
  601. ,hiddenEdgeLeft: 0 //how many extra buttons to hide from left
  602. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址