Google Search Extra Buttons

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

Per 13-11-2017. Zie de nieuwste versie.

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