Yandex Extra Buttons

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

当前为 2016-01-19 提交的版本,查看 最新版本

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