Google Search Extra Buttons

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

当前为 2018-11-20 提交的版本,查看 最新版本

  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 31.2018.11.201
  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. // ==/UserScript==
  15. if(location.host=='spmbt.github.io'){
  16. window.addEventListener('message', function(ev){
  17. if(/^https?:\/\/www\.google\./.test(ev.origin)){
  18. var d = typeof ev.data =='string' && ev.data[0] =='{' ? JSON.parse(ev.data) : ev.data;
  19. if(!d.do) return;
  20. var tok = d.tok, key = d.key;
  21. switch(d.do){
  22. case 'set':
  23. var prev = localStorage[key];
  24. if(d.val !==undefined)
  25. localStorage[key] = JSON.stringify(d.val);
  26. else
  27. localStorage.removeItem(key);
  28. break;
  29. case 'get':
  30. prev = localStorage[key];
  31. prev = prev === undefined || typeof prev =='string'&& prev[0] !='{'? prev : JSON.parse(prev);
  32. break;
  33. case 'remove':
  34. prev = localStorage[key];
  35. if(prev !==undefined)
  36. localStorage.removeItem(key);
  37. }
  38. //console.log('[io]', tok, 'prev=', prev);
  39. //ev.source.postMessage(JSON.stringify(prev !==undefined ? {tok: tok, prev: prev} : {tok: tok, undef:1}), ev.origin);
  40. }},!1);
  41. }else (function(setts){ //lang, sites, lastHoursLess
  42.  
  43. var $x = function(el, h){if(h) for(var i in h) el[i] = h[i]; return el;} //===extend===
  44. ,$pd = function(ev){ev.preventDefault();}
  45. ,d = document
  46. ,$q = function(q, el){return (el||d).querySelector(q)}
  47. ,lh = location.href
  48. ,$e = function(g,el){ //===create or use existing element=== //g={el|clone,cl,ht,cs,at,atRemove,on,apT}
  49. g.el = el || g.el || g.clone ||'DIV';
  50. var o = g.o = g.clone && g.clone.cloneNode && g.clone.cloneNode(!0)
  51. || (typeof g.el =='string' ? d.createElement(g.el) : g.el);
  52. if(o){ //execute if exist
  53. if(g.cl)
  54. o.className = g.cl;
  55. if(g.clRemove)
  56. o.classList.remove(g.clRemove);
  57. if(g.clAdd)
  58. o.classList.add(g.clAdd);
  59. if(g.cs)
  60. $x(o.style, g.cs);
  61. if(g.ht || g.at){
  62. var at = g.at ||{}; if(g.ht) at.innerHTML = g.ht;}
  63. if(at)
  64. for(var i in at){
  65. if(i=='innerHTML') o[i] = at[i];
  66. else o.setAttribute(i, at[i]);}
  67. if(g.atRemove)
  68. for(var i in g.atRemove)
  69. o.removeAttribute(g.atRemove[i]);
  70. if(g.on)
  71. for(var i in g.on) if(g.on[i])
  72. o.addEventListener(i, g.on[i],!1);
  73. g.ap && o.appendChild(g.ap);
  74. g.apT && g.apT.appendChild(o);
  75. }
  76. return o;
  77. },
  78. addRules = function(css){$e({apT: d.getElementsByTagName('head')[0], ap: d.createTextNode(css)},'style')},
  79. //check occurrence of third-party event with growing interval: h.t=time, h.i=count, h.c=check, h.o=occur, h.m=multi
  80. 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
  81. //for xLocStor:
  82. ,xLocStorOrigin = d.location.protocol +'//spmbt.github.io'
  83. ,qr, qrs ={} //set of queries "key-calls" (ок, toutLitt, toutLong, noService, noStorage)
  84. ,qrI = 0 //queries counter
  85. ,qrN = 12 //max number of waiting queries
  86. ,errIMax = 120, errNMax = errIMax //max number of errors
  87. ,ns ='googXButtons_' //namespace for keys
  88. ,listenMsg
  89. /**
  90. * external localStorage for using another domain if current domain storage is erased anywhere
  91. * @param{String} h.do - action: set|get|remove
  92. * @param{String} h.key
  93. * @param{Object|undefined} h.val (any type)
  94. * @param{Number|undefined} h.toutLitt
  95. * @param{Number|undefined} h.tout
  96. * @param{Function} h.cB - callback with 2 arguments
  97. * @param{Function|undefined} h.err - callback for err with one argument
  98. */
  99. ,xLocStor = function(h){
  100. var h0 = h;
  101. h.toutLitt = h.toutLitt || 400;
  102. h.tout = h.tout || 4000;
  103. var ifr = d.getElementById('xLocStor')
  104. ,query = function(){
  105. if((qrI += 1) > qrN){
  106. xCatch('longQrs', null, h);
  107. return;}
  108. ifr.contentWindow.postMessage(JSON.stringify($x({
  109. do: h.do
  110. ,tok: token
  111. ,key: ns + h.key
  112. }, h.val !==undefined ? {val: h.val}:{}) )
  113. , xLocStorOrigin);
  114. qrs[token] = $x({ //for wait of response
  115. wToutLitt: (function(h, qrI, errIMax){return setTimeout(function(){
  116. qrI -= 1;
  117. if((errIMax -= 1) >=0)
  118. ;//console.warn('toutLitt', h);
  119. chkErrMax();
  120. }, h.toutLitt);})(h, qrI, errIMax)
  121. ,wTout: (function(h, qrI){return setTimeout(function(){
  122. qrI -= 1;
  123. //xCatch('tout', null, h);
  124. //xLocStor(h0);
  125. }, h.tout);})(h, qrI)
  126. }, h);
  127. }
  128. ,token = +new Date() + (Math.random()+'').substr(1,8)
  129. ,el = h.el;
  130. delete h.el;
  131. if(ifr) query();
  132. else ifr = $e({
  133. el: 'iframe',
  134. at:{id: 'xLocStor'
  135. ,src: xLocStorOrigin +'/googleSearchExtraButtons/saveYourLocalStorage.html'},
  136. cs: {display: 'none'},
  137. on: {load: query},
  138. apT: el || d.body
  139. });
  140. if(!listenMsg) addEventListener('message', function(ev){
  141. if(ev.origin == xLocStorOrigin){ // {"tok":"<value>"[,"err":"<txt>"],"h":...}
  142. //console.log('from_io', JSON.parse(ev.data))
  143. var resp = ev.data && ev.data[0] =='{' && JSON.parse(ev.data);
  144. if(!resp) xCatch('bad_format', resp, h);
  145. if(( qr = qrs[resp.tok] )){
  146. qrI -= 1;
  147. qr.cB(resp.prev, resp.undef);
  148. var er = qr.err;
  149. delete qrs[resp.tok];} // else ignore unsufficient token
  150. if(resp.err && (!er || er(resp.err)) ) //individual or common error processing depends of er()
  151. xCatch(resp.err, resp, h);
  152. }},!1);
  153. listenMsg =1;
  154. },
  155. //for tests: localStorage.googXButtons_dwmyh = JSON.stringify({h:[1,2,1,1,1]})
  156. //$('#xLocStor').contentWindow.postMessage('{"do":"get","key":"googXButtons_dwmyh"}','https://spmbt.github.io')
  157. xCatch = function(er, resp, h){
  158. if((errIMax -= 1) >=0)
  159. console.error('tok:', resp && resp.tok ||'--','; err:', er,'; h:', h,'; respH:', resp && resp.h);
  160. chkErrMax();
  161. },
  162. chkErrMax = function(){if(!errIMax) console.error('Too many err messages:', errNMax)}
  163. ,$l ={ru:{
  164. 'search in PDF files':'поиск по документам PDF'
  165. ,'search in':'искать по'
  166. ,'from / to':'за период'
  167. ,'past':['за последний','за последние','за последнюю']
  168. ,'day':'сутки'
  169. ,'days':['дня','дней']
  170. ,'week':'неделю'
  171. ,'weeks':['недели','недель']
  172. ,'month':'месяц'
  173. ,'months':['месяца','месяцев']
  174. ,'year':'год'
  175. ,'years':['года','лет']
  176. ,'hour':'час'
  177. ,'hours':['часа','часов']
  178. ,'Settings':'Настройки'
  179. ,'of userscript':'юзерскрипта'
  180. ,'reload page for effect':'перезагрузить страницу'
  181. ,'Interface language':'Язык интерфейса'
  182. ,'Less positions at the end of selects':'Меньше выбора в конце селектов'
  183. ,'Gray design of buttons':'Серый дизайн кнопок'
  184. ,'Sites':'Сайты'
  185. },fr:{
  186. 'search in PDF files':'la recherche dans les fichiers PDF'
  187. ,'search in':'rechercher dans'
  188. ,'from / to':'pour la période'
  189. ,'past':['le dernier','dans les derniers','dans les derniers']
  190. ,'day':'jour'
  191. ,'days':['jours','jours']
  192. ,'week':'semaine'
  193. ,'weeks':['semaines','semaines']
  194. ,'month':'mois'
  195. ,'months':['mois','mois']
  196. ,'year':'an'
  197. ,'years':['ans','ans']
  198. ,'hour':'heure'
  199. ,'hours':['heures','heures']
  200. ,'Settings':'Paramètres'
  201. ,'of userscript':'de Userscript'
  202. ,'reload page for effect':'recharger la page pour effet'
  203. ,'Interface language':'Langue de l\'interface'
  204. ,'Less positions at the end of selects':'Moins de choix les longues listes'
  205. ,'Gray design of buttons':'Gris design des boutons'
  206. ,'Sites':'Les sites'
  207. },de:{
  208. 'search in PDF files':'Suche in PDF-Dateien'
  209. ,'search in':'Suche in'
  210. ,'from / to':'im Zeitraum'
  211. ,'past':['letzte','letzte','letzte']
  212. ,'day':'Tag'
  213. ,'days':['Tage','Tage']
  214. ,'week':'Woche'
  215. ,'weeks':['Wochen','Wochen']
  216. ,'month':'Monat'
  217. ,'months':['Monate','Monate']
  218. ,'year':'Jahr'
  219. ,'years':['Jahre','Jahre']
  220. ,'hour':'Stunde'
  221. ,'hours':['Stunden','Stunden']
  222. ,'Settings':'Einstellungen'
  223. ,'of userscript':'von Userscript'
  224. ,'reload page for effect':'Seite neu laden'
  225. ,'Interface language':'Sprache'
  226. ,'Less positions at the end of selects':'Weniger Auswahl in langen Listen'
  227. ,'Gray design of buttons':'Graues Design der Schaltflächen'
  228. ,'Sites':'Websites'
  229. },es:{
  230. 'search in PDF files':'búsqueda en archivos PDF'
  231. ,'search in':'busca en'
  232. ,'from / to':'para el período'
  233. ,'past':['el último','en los últimos','en los últimos']
  234. ,'day':'día'
  235. ,'days':['días','días']
  236. ,'week':'Semana'
  237. ,'weeks':['semanas','semanas']
  238. ,'month':'mes'
  239. ,'months':['meses','meses']
  240. ,'year':'año'
  241. ,'years':['años','años']
  242. ,'hour':'hora'
  243. ,'hours':['horas','horas']
  244. ,'Settings':'Ajustes'
  245. ,'of userscript':'de userscript'
  246. ,'reload page for effect':'página para efecto de recargar'
  247. ,'Interface language':'Idioma de interfaz'
  248. ,'Less positions at the end of selects':'Menos elección en listas largas'
  249. ,'Gray design of buttons':'Diseño gris de botones'
  250. ,'Sites':'Sitios'
  251. }}; //if !lang, then no hints
  252. addRules('.hp .sfsbc,.sfsbc{display: inline-block}.siteList:hover button{display: block}'
  253. +'.gb_Ib >.gb_e{height:47px}.gb_Fb{z-index:1087}.tsf-p{z-index:203}'
  254. +'.lsbb .xButt,.sbibod .xButt,.lsbb >.siteList,.sbibod >.siteList{z-index: 2002; width:34px; height:17px;'
  255. +'padding:0 2px; line-height:14px; font-size:14px; border:1px solid transparent; border-radius:2px;'
  256. +'background-color:#dddae6; color:#eee; opacity: .07; transition: opacity .57s ease-in}'
  257. +'.lsbb .xButt:not(.xButt2),.sbibod .xButt:not(.xButt2),.lsbb >.siteList{background-color:#4889f1; color:#fff; opacity: 0.64}'
  258. +'.xButt2{padding:0 0 2px; background-color:#dad6e2; color:#eee; opacity: 1}'
  259. +'.lsbb .xButt:hover,.sbibod .xButt:hover,.xButt.xButt2:hover .xButt2,.xButt2:hover{background-color:#c3d4e1; color:#fff; opacity:1}'
  260. +'.sbibod .xButt:hover,.sbibod .xButt2:hover,.sbibod .xButt:hover .xButt2{background-color:#c3c6c7}.lsbb >.siteList:hover{background-color:#4889f1}'
  261. +'.lsbb >.siteList,.sbibod >.siteList{width:32px; height:auto; padding:1px 0 2px; text-align:center}'
  262. +'.lsbb >.siteList .lsb,.sbibod >.siteList .lsb{font-weight: normal; color:#d4d4d4}.lsbb .lsb:hover,.sbibod .lsb:hover{opacity: 1; color: #987b2b; cursor:default}'
  263. +'.sbibod >.siteList:hover,.lsbb >.siteList >div:not([class]):hover{background-color:#c2d4e0; color: #f7f7f7; opacity:.93}.lsbb > .siteList > div:not([class]):hover span{color: #aa6c1c}'
  264. +'.sbibod:not(.lsbb) >.siteList, .sbibod:not(.lsbb) > .xButt2{background-color:#dddae6; opacity:.45}'
  265. +'.sbibod:not(.lsbb) >.siteList:hover, .sbibod:not(.lsbb) > .xButt2:hover{background-color:#dddae6; opacity:.87}'
  266. +'.sbibod.lsbb{height:44px}'
  267. +'.sbibod >.siteList >.list{background-color:#e1deeb}'
  268. +'.sbibod >.siteList.fade:hover{opacity: 1; transition: opacity .1s ease-in}'
  269. +'.sbibod >.siteList.fade{opacity: 0.23}'
  270. +'.siteList .sett .txt{padding:2px 2px 4px; font-size: 14px}'
  271. +'.lsbb >.siteList .sett .txt{background-color:#4889f1}'
  272. +'.siteList .settIn{display: none; width: 250px; padding: 2px 4px; text-align:left; border:1px solid #48f; font-size: 14px;'
  273. +'background-color:#eef; color:#336}'
  274. +'.siteList .settIn hr{margin:2px 0}'
  275. +'.sbibtd .sfsbc .nojsb, .siteList .sett:hover .settIn, .siteList .settIn.changed,'
  276. +'.siteList .settIn.changed .reload{display: block}.siteList .settIn .reload, .siteList.hiddn{display: none}'
  277. +'div.gb_g[aria-label="promo"],.pdp-psy.og-pdp, .gb_Sc.gb_g .gb_ha, .gb_g.gb_ha:not(.xpdopen ){display: none}.xpdopen{display: block!important}.rhsvw{opacity:.16; transition:.4s}.rhsvw:hover{opacity:1}'
  278. +'.srp #sfdiv{overflow: inherit}'); //hide promo
  279. xLocStor({do:'get', key:'sett', val:setts, cB: function(prev,undef){
  280. S = prev || setts;
  281. S.dwmyh = S.dwmyh || setts.dwmyh; //temp. transitional expr.
  282. console.timeStamp = function(){};
  283.  
  284. CS({t:120, i:12, m: 1.6
  285. ,c: function(){
  286. return d && d.getElementsByName('q') && d.getElementsByName('q')[0];
  287. },
  288. o: function(dat){
  289. var lang = S.lang != null ? S.lang : setts.lang
  290. ,sites = S.sites && (S.sites.length && S.sites[0] || S.sites.length >1) && S.sites
  291. || typeof sites =='string'&& [sites] || !S.sites && setts.sites || null;
  292. var strSites = sites && sites.join('\n').replace(/^\n/,'\n\n') ||''
  293. ,$L = $l[lang] || $l.ru; //default template of lang
  294. if(!lang || !$l[lang] || lang =='en') for(var l in $L){ //replace 'en' lang for default or substitution
  295. if($L[l] instanceof Array) for(var l2 in $L[l])
  296. $L[l][l2] = l;
  297. else
  298. $L[l] = l;
  299. }
  300. var $LSettings = $L['Settings'];
  301. if(sites && sites.length)
  302. sites.push($LSettings)
  303. var mainPg = /\/search\?|&q=|#q=/.test(lh)
  304. ,inputSearch = dat
  305. ,design1612 = $q('#_fZl') || $q('.sbico-c')
  306. ,layout1811 = $q('.Tg7LZd') || $q('button[aria-label="Google Search"]')
  307. ,d16 = (design1612 || layout1811) && S.design1612
  308. ,buttSearch = d.getElementsByName("btnG") && d.getElementsByName('btnG')[0] || design1612 || layout1811
  309. ,buttS ={
  310. Srch:{url:'', txt:'search'}
  311. ,PDF:{url:'filetype:pdf', txt:$L['search in PDF files']}
  312. ,site:{url:'site:'+ S.sites[0], txt:$L['search in']+' '+ S.sites[0], one:'day'} //you may comment this line
  313. ,'.. : ..':{url:'', txt:$L['from / to']}
  314. ,'1D':{url:'&tbs=qdr:d', txt:$L['past'][1] +' '+ $L['day'], one:'day', up:13,lett:'D'}
  315. ,'1W':{url:'&tbs=qdr:w', txt:$L['past'][2] +' '+ $L['week'], one:'week', up:14,lett:'W'}
  316. ,'1M':{url:'&tbs=qdr:m', txt:$L['past'][0] +' '+ $L['month'], one:'month', up:20,lett:'M'}
  317. ,'1Y':{url:'&tbs=qdr:y', txt:$L['past'][0] +' '+ $L['year'], one:'year', up:10,lett:'Y'}
  318. ,'1H':{url:'&tbs=qdr:h', txt:$L['past'][0] +' '+ $L['hour'], one:'hour', up:23,lett:'H'}
  319. ,DOC:{url:'filetype:doc', txt:$L['search in PDF files'].replace(/PDF/,'DOC')}
  320. }, ii = 0, iD = -1;
  321. if((design1612 || layout1811) && !d16)
  322. buttSearch.parentNode.className +=' lsbb';
  323. !sites && delete buttS.site;
  324. buttSearch.parentNode.style.position ='relative';
  325. if(buttSearch && top == self) for(var i in buttS) if(i !='site'|| S.sites){ //buttons under search input line
  326. if(i.length ==2) iD++; else iD=-1;
  327. var bI = buttS[i]
  328. ,Gesch = ({m:'letzter',f:'letzte',n:'letztes'})['m,f,m,n,f'.split(',')[iD]]
  329. ,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]) }
  330. ,csLeft = function(ii,a){a = -127 + 37 * (ii-1 - (ii >2 && !mainPg)); return design1612 || layout1811 ?{right: -a+33+'px'}:{left: a+'px'}}
  331. ,butt2 = $e({clone: i =='site'|| i.length ==2
  332. ? $e({cl: 'siteList', cs: {cursor:'default'}, at: {site: S.sites[0], date: bI.url} })
  333. : i !='.. : ..'|| mainPg ? $e({el:'button', cl: 'xButt ' +(d16 ?'xButt2':'lsb')}) : $e({cl: 'siteList hiddn'})
  334. ,at: {value: iD !=-1 && S.dwmyh[iD] !=1 ? S.dwmyh[iD] + bI.lett : i
  335. ,innerHTML: '<div'+ (d16 ?' class=xButt2':'') +'><span class=txt onclick=this.parentNode.click();return!1 title="'
  336. +(lang || i=='site'|| i=='.. : ..'
  337. ? (iD==-1 || S.dwmyh[iD]==1 ? bI.txt : $L['past'][1] +' '+ hint(S.dwmyh[iD]-1)).replace(/letzte/,Gesch) :'')
  338. +'" itrvNum="'+ (i=='site'?'': bI.url + S.dwmyh[iD]) +'">'
  339. +(iD !=-1 && S.dwmyh[iD] !=1 ? S.dwmyh[iD] + bI.lett : i) +'</span></div>'}
  340. ,cs: $x({position:'absolute', top:'33px',wordSpacing:'-1px'}, csLeft(++ii))
  341. ,on: {click: (function(bI, i, iD){
  342. //console.log('clic0:', i, iD);
  343. return /Srch|PDF|DOC|site/.test(i)
  344. ? function(ev){
  345. var t = ev.target;
  346. console.log('cli-DocSite:',i,bI,ev, t.className, inputSearch.value, this.form, ', attr: ', t.getAttribute('site'), $LSettings, t.parentNode.getAttribute('site'), t.value);
  347. if(t.className =='defa')
  348. saveLocStor('','','remove'); $pd(ev);
  349. if(((t.getAttribute('site') ==null && t.parentNode.getAttribute('site') ==null)
  350. || t.getAttribute('site')==$LSettings || t.parentNode.getAttribute('site')==$LSettings)
  351. && !/Srch|PDF|DOC/.test(i)) return;
  352. inputSearch.value = inputSearch.value.replace(/ site\:[\w.]*$/ig, function(a){return i=='Srch'? a :''})
  353. .replace(/( |\+|&as_)filetype(:|%3A)[^\&]*/g,'') +' '+ (/Srch|PDF|DOC/.test(i) ? bI.url
  354. : 'site:'+ (t.getAttribute('site')|| t.parentNode.getAttribute('site')||''));
  355. if(/xButt|txt/.test(t.className) && !(i=='site'&& !(/list/.test(t.parentNode.className)
  356. || /list/.test(t.parentNode.parentNode.className))) || /Srch|PDF|DOC/.test(t.value))
  357. buttSearch.click();
  358. }: !bI.url ? function(ev){ //from-to date
  359. var el = $q('#cdrlnk'), o;
  360. el && el.dispatchEvent(((o = d.createEvent('Events')).initEvent('click', !0, !1), o));
  361. $pd(ev);
  362. }: function(ev){ //past interval
  363. var t = ev && ev.target, sbd = /,sbd:1/.test(lh),
  364. el2 = t && t.parentNode,
  365. date2 = el2.getAttribute('date');
  366. console.log('cli-Past:','/search?q='+ encodeURIComponent(inputSearch.value) +(date2 ||''), el2.className+','+t.className, el2.classList.contains('siteList'), t.classList.contains('list'));
  367. /* +((t.getAttribute('date') || t.parentNode.getAttribute('date'))
  368. + (t.value || t.parentNode.value).replace(/\D/g,'') || bI.url) );
  369. var locationhref = '/search?q='+ encodeURIComponent(inputSearch.value)
  370. +(el2.getAttribute('date')
  371. + el2.value.replace(/\D/g,'') || bI.url)
  372. +(/tbs=\w+(:|%3A)\w+(,|%2C)sbd(:|%3A)1/.test(lh) ?',sbd:1':'') //save "sort by date" option
  373. +(/[&?]tbm=/.test(lh) ? '&'+/tbm=[^&]* /.exec(lh)[0]:''); //saving type of page*/
  374. if(el2.classList.contains('siteList') && !t.classList.contains('list')){ //clicked by top button
  375. var elTop = $q('div:not(.list) >.txt', el2) ||''
  376. ,itrvNum = elTop && elTop.getAttribute('itrvNum') ||''
  377. ,newSrch = lh.replace(/(&|\?)q=([^&]+)(&|$)/g,'$1q='+ encodeURIComponent(inputSearch.value) +'$3');
  378. if(layout1811 && itrvNum !=='') location.href = /qdr(:|%3A)([dwmyh])\d*/.test(lh)
  379. ? newSrch.replace(/qdr(:|%3A)[dwmyh]\d*/, itrvNum)
  380. : newSrch + (/\?/.test(newSrch) ?'&':'?') + itrvNum;
  381. if(itrvNum != null) S.dwmyh[iD] = +(itrvNum ||'').replace(/\D/g,'');
  382. }else if(t.textContent || el2.textContent)
  383. S.dwmyh[iD] = +(t.textContent || el2.textContent ||'').replace(/\D/g,'');
  384. console.log('==1', el2.value, itrvNum);
  385. $pd(ev);
  386. ev.stopPropagation();
  387. saveLocStor();
  388. }
  389. })(bI, i, iD),
  390. mouseover: i =='site' || i.length ==2 ? (function(bI,i){return function(ev){
  391. clearTimeout(bI.ww);
  392. var t = ev.currentTarget;
  393. t.classList.add('fade');
  394. $q('.list', t).style.display ='block';
  395. }})(bI,i) :'',
  396. mouseout: i =='site' || i.length ==2 ? (function(bI,i){return function(ev){
  397. var t = ev.currentTarget;
  398. clearTimeout(bI.ww);
  399. bI.ww = setTimeout(function(){
  400. $q('.list',t).style.display ='none';
  401. t.classList.remove('fade');
  402. }, 570);
  403. }})(bI,i) :'',
  404. change: saveLocStor
  405. }
  406. ,apT: buttSearch.parentNode
  407. });
  408. bI.el = butt2;
  409. if(i =='site' || i.length ==2){ //dropdown lists under some buttons
  410. var siteList = $e({cl:'list',cs:{display:'none'}, apT: butt2}), arr =[];
  411. for(var j =0; j <= bI.up -1 -(i=='1W'&& S.lastHoursLess ?4:0) -(i=='1M'&& S.lastHoursLess ?9:0); j++)
  412. if(i !='1H' || !S.lastHoursLess || j < 8 || j % 2 )
  413. arr.push(hint(j));
  414. //console.log(S.sites,i, S.dwmyh);
  415. var list = i == 'site' ? sites||[] : i =='1D'&& !sites ? arr.concat([$LSettings]) : arr;
  416. for(var j in list) if(j !=0 || iD!=-1 && S.dwmyh[iD] !=1)
  417. var sI = list[j]
  418. ,butt3 = $e({clone: sI==$LSettings
  419. ? $e({cl: 'sett' +(d16 ?' xButt xButt2':' lsb')})
  420. : $e({el:'button', cl: 'xButt' +(d16 ?' xButt2':' lsb')})
  421. ,at:{value: sI
  422. ,site: sI
  423. ,date: bI.url
  424. ,title: sI==$LSettings || !lang ?'':(i =='site' ? $L['search in'] +' '+ sI
  425. : j==0 ? bI.txt : $L['past'][1] +' '+ sI).replace(/letzte/,Gesch)
  426. ,innerHTML:'<span class=txt>'+ sI +'</span>'+ (sI != $LSettings &&!(!S.sites && i =='1H')
  427. ?'':'<div class="settIn">'
  428. +$L.Settings +' '+ $L['of userscript'] +'<br/>"Google Search Extra Buttons"<hr/>'
  429. +$L['Interface language'] +': <select class="lang" style="width:70px">'
  430. +(function(){var s='<option'+ (lang=='en'?' selected':'') +'>en</option>';
  431. for(var i in $l)
  432. s+='<option'+ (lang==i ?' selected':'') +'>'+ i +'</option>';
  433. return s +'<option value=""'+ (lang==''?' selected':'') +'>en w/o hints</option>'})()
  434. +'</select><br/>'
  435. +'<input type="checkbox" class="less" id="hoursLess"'+ (S.lastHoursLess ?' checked':'') +'/>'
  436. +'<label for="hoursLess" id="hoursLessL">'+ $L['Less positions at the end of selects'] +'</label><br/>'
  437. +'<input type="checkbox" class="des16" id="design1612"'+ (S.design1612 ?' checked':'') +'/>'
  438. +'<label for="design1612" id="design1612L">'+ $L['Gray design of buttons'] +'</label><br/>'
  439. +'<i><a href="#" class="defa" style="float: right">Default settings</a></i>'
  440. +$L.Sites +': <br/><textarea class="sites" style="width:97%" rows=8>'
  441. + strSites +'</textarea><br/>'
  442. +'<a class="reload" href=# onclick="location.reload();return!1">'
  443. + $L['reload page for effect'] +'</a>'
  444. +'</div>')}
  445. ,cs: {position: sI != $LSettings || design1612 || layout1811 ?'static':'absolute',display:'block', width: sI != $LSettings ?'auto': /en|es/.test(lang)||!lang ?'4em':'6.2em', height: sI != $LSettings ?'18px':'16px'
  446. ,margin:'2px 0 -1px -13px', padding:'0 2px 0 1px', textAlign:'left', fontWeight:'normal', opacity:1, whiteSpace:'nowrap'}
  447. ,on:{click: function(ev){
  448. var less = $q('#hoursLess')
  449. ,des16 = $q('#design1612')
  450. ,itrv = ev.target.getAttribute('date')
  451. ,num = ev.target.getAttribute('site').replace(/\D/g,'');
  452. console.log('c3',ev.target, itrv, num);
  453. if(less && /hoursLess/.test(ev.target.id)){
  454. less.outerHTML = '<input type="checkbox" class="less" id="hoursLess"'
  455. +(less.getAttribute('checked')!=null ?'':' checked="checked"')+'/>';
  456. saveLocStor();}
  457. if(des16 && /design1612/.test(ev.target.id)){
  458. des16.outerHTML = '<input type="checkbox" class="des16" id="design1612"'
  459. +(des16.getAttribute('checked')!=null ?'':' checked="checked"')+'/>';
  460. saveLocStor();}
  461. var newSrch = lh.replace(/(&|\?)q=([^&]+)(&|$)/g,'$1q='+ encodeURIComponent(inputSearch.value) +'$3');
  462. if(layout1811 && num !=='') location.href = /qdr(:|%3A)([dwmyh])\d*/.test(lh)
  463. ? newSrch.replace(/qdr(:|%3A)[dwmyh]\d*/, itrv + num)
  464. : newSrch + (/\?/.test(newSrch) ?'&':'?') + itrv + num;
  465. $pd(ev);
  466. }}
  467. ,apT: siteList
  468. });
  469. siteList.style.height ='auto'; siteList.style.textAlign ='center';
  470. }
  471. }
  472. }
  473. });
  474.  
  475. }, el: d.body});
  476. var saveLocStor = function(ev, val, do2){ var aaa,aab,aac,aad, t = ev && ev.target.form || document.documentElement || document.body;
  477. xLocStor({do: do2 ||'set', key:'sett'
  478. , val:{lang: (aaa=d.querySelectorAll('.lang', t))[aaa.length-1].value
  479. ,sites: (aab=d.querySelectorAll('.sites', t))[aab.length-1].value.replace(/^[ \t]*|[ \n\t]*$/g,'')
  480. .split('\n')
  481. ,lastHoursLess: (aac=d.querySelectorAll('.less', t))[aac.length-1].checked
  482. ,design1612: (aad=d.querySelectorAll('.des16', t))[aad.length-1].checked
  483. ,dwmyh: S.dwmyh || setts.dwmyh
  484. }
  485. ,cB: function(prev){
  486. console.info('Settings are saved. prev=', prev);}
  487. });
  488. $q('.siteList .settIn').classList.add('changed');
  489. };
  490.  
  491. })({ //write "lang:''," to remove hints; 'en' for English hints (fr - Français, es - espagnol), 'ru' for Russian
  492. lang:''|| (navigator.languages && navigator.languages[1] || navigator.language.substr(0,2)) //='' if hide hints, or 2 letters from $l{}
  493. ,sites: [ //=array or one site in string
  494. '','slashdot.org','reddit.com','techcrunch.com','habr.com','geektimes.com'
  495. ,'smashingmagazine.com','engadget.com'] //write your favorite sites
  496. ,design1612: 1 //=boolean - new gray design
  497. ,lastHoursLess: 1 //=boolean - not show odd some values of hours after 8 h
  498. ,dwmyh: [1,1,1,1,1] //=array of numbers - current vals of days, weeks, months, years, hours
  499. });