Advertisement
Guest User

Untitled

a guest
Jul 14th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.26 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Thread Page Finder
  3. // @namespace tpf
  4. // @description Find's the thread's page number. Can also auto-update.
  5. // @include http://boards.4chan.org/*/res/*
  6. // @version 1.4.9.05132011
  7. // @copyright 05092011, tpf
  8. // @compatibility Firefox 4, Chrome 11 (with Tampermonkey 2.0)
  9. // ==/UserScript==
  10. (function(){
  11. //Please use the GM registered menus if present
  12. //clearSettings();//Reset defaults
  13. //toggleTitles(false);//Turn off titles/hover messages
  14.  
  15. var Frontpage = {
  16. url: location.href.match(/(^.*\/)res\//i)[1],
  17. board: null,
  18. lastmodify: null,
  19.  
  20. is_f: false,
  21. rx_threadnos: null,
  22. rx_pages: null,
  23.  
  24. init: function(){
  25. this.is_f = /\.org\/f\//i.test(this.url);
  26. this.board = Frontpage.url.replace(/.*\.org/i,'');
  27. this.rx_threadnos = (this.is_f ?
  28. /<a[^>]*href=(?:["']|)res\/(\d+)(?:["']|)(?:[^>]*|)>/gi : //f
  29. /<span[^>]*id=(?:["']|)nothread(\d+)(?:["']|)(?:[^>]*|)>/gi );
  30. this.rx_pages = /\[<a\shref=(?:["']|)\d+(?:["']|)>\d+<\/a>\]/gi;
  31. this.check(); //Initialize lastmodify
  32. },
  33.  
  34. check:function(chklastdate, callfunc){
  35. function chkStatus(res){
  36. if(res.status == 200)
  37. Frontpage.lastmodify = new Date(
  38. res.getResponseHeader('Last-Modified')
  39. );
  40. if(callfunc)
  41. callfunc(res);
  42. }
  43. xhr(
  44. this.url,
  45. chkStatus,
  46. 'head',
  47. (chklastdate? this.lastmodify.toUTCString() : null)
  48. );
  49. }
  50. }//Frontpage
  51.  
  52. var Thread = {
  53. id: location.href.match(/\/res\/(\d+)/i)[1],
  54. rx_id: null,
  55. init: function(){
  56. this.rx_id = RegExp('((nothread|res\/)'+this.id+')[^\d]')
  57. },
  58.  
  59. check: function(callfunc){
  60. xhr(Frontpage.url+'res/'+this.id, callfunc, 'head');
  61. }
  62. }//Thread
  63.  
  64. function container(outer){
  65. this.outer = outer;
  66.  
  67. this.add = function(id, element, title, parent){
  68. this[id] = document.createElement(element);
  69. this[id].id = id;
  70. if(title){
  71. if(Box.showTitles) this[id].title = title;
  72. this[id].temptitle = title;
  73. }
  74. if(parent)
  75. this[parent].appendChild(this[id]);
  76. else
  77. this.outer.appendChild(this[id]);
  78. }
  79. }
  80.  
  81. function createContainer(){
  82. var con = new container(document.createElement('div'));
  83. con.outer.id = Box.uid;
  84. con.add('msg', 'span');
  85. con.add('pin', 'a', 'Pin/Unpin');
  86. con.add('drag', 'a', 'Move');
  87. con.add('mini', 'a', 'Full/Mini');
  88. con.add('upd', 'a', 'Update Now');
  89. con.add('af', 'span');
  90. //<!--af
  91. con.add('auto', 'a', 'Enable Auto-update', 'af');
  92. //<!--uif
  93. con.add('uif', 'span', null, 'af');
  94. con.add('set', 'span', null, 'uif');
  95. con.add('inp', 'input', 'Update interval [enter]', 'uif');
  96. con.inp.type = 'text';
  97. //form-->
  98. //af-->
  99. con.add('stat', 'span');
  100. document.body.insertBefore(con.outer, document.body.firstChild);
  101. return con;
  102. }//createContainer
  103.  
  104. function setCustomStyle(css){
  105. var customStyle = [
  106. ' #', Box.uid, ' { ',
  107. (Box.isMini?'':'border: 1px solid black; '),
  108. (Box.isMini?'':'padding: 5px 8px 5px 8px; '),
  109. 'z-index: ', (Math.pow(2, 31)-1), '; ',
  110. ' }',
  111. ' #', Box.uid, ' > * { ',//defaults
  112. 'clear: none; ',
  113. 'white-space: nowrap; ',
  114. 'margin: 0 0; ',
  115. 'border: 0 none; ',
  116. 'padding: 0 0; ',
  117. ' }',
  118. //p,d,m
  119. '\n #', Box.uid, '> #pin, ',
  120. ' #', Box.uid, '> #drag, ',
  121. ' #', Box.uid, '> #mini { ',
  122. 'position:', (Box.isMini?'static; ':'absolute; '),
  123. (Box.isMini?'margin: 0 2px; ':''),
  124. 'top: -5px; ',
  125. 'font-weight: bold; ',
  126. 'font-size: 1.1em; ',
  127. 'cursor: pointer; ',
  128. 'background: none; ',
  129. 'display: none; ',
  130. ' }',
  131. '\n #', Box.uid, '> #mini { right:1px; }',
  132. '\n #', Box.uid, '> #drag { ',
  133. 'left: 10px; ',
  134. 'cursor: move; ',
  135. 'width: 80%; ',
  136. ' }',
  137. '\n #', Box.uid, '> #pin { ',
  138. 'left: 1px; ',
  139. 'top: -2px; ',
  140. 'font-size: 0.8em; ',
  141. ' }',
  142. '\n #', Box.uid, ':hover > #pin, ',
  143. ' #', Box.uid, ':hover > #drag, ',
  144. ' #', Box.uid, ':hover > #mini { display: inline; }',
  145. //ms,st
  146. '\n #', Box.uid, '> #msg { ',
  147. 'display:', (Box.isMini?'inline; ':'block; '),
  148. 'font-size:', (Box.isMini?'1.01em; ':'1.2em; '),
  149. 'font-variant: small-caps; ',
  150. (Box.isMini?'margin: 0 5px; ':''),
  151. (Box.isMini ?'':'clear: both; '),
  152. ' }',
  153. '\n #', Box.uid, '> #stat { ',
  154. 'font-size: 0.9em; ',
  155. 'font-style: italic; ',
  156. 'color: #555555; ',
  157. 'display:', (Box.isMini?'none; ':'block; '),
  158. 'clear: both; ',
  159. ' }',
  160. '\n #', Box.uid, '.left > #msg, ',
  161. ' #', Box.uid, '.left > #stat { ',
  162. 'text-align: left; ', //(Box.isMini ?'float: left; ':''),
  163. ' }',
  164. '\n #', Box.uid, '.right > #msg, ',
  165. ' #', Box.uid, '.right > #stat { ',
  166. 'text-align: right; ', //(Box.isMini ?'float: right; ':''),
  167. ' }',
  168. //up,af
  169. '\n #', Box.uid, '> #upd, ',
  170. ' #', Box.uid, '> #af > #auto { ',
  171. 'margin: 0 ', (Box.isMini?'2':'1'), 'px; ',
  172. 'cursor: pointer; ',
  173. 'font-size: 1em; ',
  174. 'font-variant: small-caps; ',
  175. 'font-weight: bold; ',
  176. 'display: none; ',
  177. ' }',
  178. '\n #', Box.uid, '> #af > #uif { ',
  179. 'clear: none; ',
  180. 'position: relative; ', //(Box.isMini?'':'top: 3px; '),
  181. ' }',
  182. '\n #', Box.uid, '> #af > #uif > #inp { ',
  183. 'font-size: 0.9em; ',
  184. 'text-align: right; ',
  185. 'width: 40px; ',
  186. 'padding: 0 0; ',//'margin: 0 2px; ',
  187. ' }',
  188. '\n #', Box.uid, '> #af > #uif > #set { ',
  189. 'font-size: 0.9em; ',
  190. 'color: #555555; ',
  191. 'margin: 0 3px; ',
  192. 'position: relative; ',
  193. (Box.isMini?'':'top: 2px; '),
  194. ' }',
  195. '\n #', Box.uid, '> #af > #uif { ',
  196. 'display: none; ',
  197. 'margin: 2px 0; ',
  198. 'clear: none; ',
  199. ' }',
  200. '\n #', Box.uid, ':hover > #upd, ',
  201. ' #', Box.uid, ':hover > #af > #auto { display: inline; }',
  202. '\n #', Box.uid, '> #af:hover > #uif { display: inline; }',
  203.  
  204. '\n #', Box.uid, '.left > #upd, ', //' #', Box.uid, '.left > #af, ',
  205. ' #', Box.uid, '.left > #af > *, ',
  206. ' #', Box.uid, '.left > #af > #uif > * { float: left; }',
  207. '\n #', Box.uid, '.right > #upd, ', //' #', Box.uid, '.right > #af, ',
  208. ' #', Box.uid, '.right > #af > *, ',
  209. ' #', Box.uid, '.right > #af > #uif > * { float: right; }',
  210. ].join('');
  211.  
  212. if(!css){
  213. var css = document.createElement('style');
  214. css.id = Box.uid+'_css';
  215. css.type = 'text/css';
  216. document.getElementsByTagName('head')[0].appendChild(css);
  217. }
  218. css.innerHTML = customStyle;
  219. }
  220.  
  221. var Box = {
  222. uid:'thread_page_finder',
  223. con:null, //container
  224. toh:null,
  225. lastdetails:null,
  226. pagelastfound:0,
  227. interval:60, //In seconds
  228. isMini:false,
  229. isPinned:true,
  230. isAuto:false,
  231. showTitles: true,
  232.  
  233. init: function(){
  234. this.isMini = GM_getValue('_isMini', this.isMini);
  235. this.interval = GM_getValue('_interval', this.interval);
  236. this.isPinned = GM_getValue('_isPinned', this.isPinned);
  237. this.showTitles = GM_getValue('_showTitles', this.showTitles);
  238. setCustomStyle();
  239. this.con = createContainer();
  240. var tc = this.con;
  241. var tcos = tc.outer.style;
  242. document.body.style.position = 'relative';
  243. tcos.position = this.isPinned?'fixed':'absolute',
  244. tcos.left = GM_getValue('_offset_left', null);
  245. tcos.top = GM_getValue('_offset_top', null);
  246. tcos.right = GM_getValue('_offset_right', '0px');
  247. tcos.bottom = GM_getValue('_offset_bottom', '0px');
  248.  
  249. this.setLabels();
  250. tc.msg.innerHTML = [
  251. '<span style="font-variant:normal;">',
  252. Frontpage.url, '</span>',
  253. '<b>', Thread.id, '</b>',
  254. ].join('');
  255.  
  256. listen(tc.pin, 'click', Box.togglePin);
  257. listen(tc.mini, 'click', Box.toggleMinimal);
  258. listen(tc.upd, 'click', Box.forceUpdate);
  259. listen(tc.auto, 'click', Box.toggleAuto);
  260. //listen(tc.uif, 'submit', function(e){ Box.setInterval(e); });
  261. listen(tc.inp, 'keypress', function(e){ Box.validateInput(e); });
  262. listen(tc.drag, 'mousedown', Box.dragStart);
  263. },
  264.  
  265. saveValues: function(){
  266. GM_setValue('_isPinned', Box.isPinned);
  267. GM_setValue('_interval', Box.interval);
  268. GM_setValue('_isMini', Box.isMini);
  269. var bcos = Box.con.outer.style;
  270. GM_setValue('_offset_left', bcos.left);
  271. GM_setValue('_offset_top', bcos.top);
  272. GM_setValue('_offset_right', bcos.right);
  273. GM_setValue('_offset_bottom', bcos.bottom);
  274. },
  275.  
  276. setLabels: function(opt){
  277. opt = opt?opt:'111'; //If opt is omitted/null, do all;
  278. var bc = Box.con;
  279. var bim = Box.isMini;
  280. var align = bc.outer.style.left?'left':'right';
  281. bc.outer.className = bim?'':'reply ' + align;
  282. if(opt[0]){//Full/mini
  283. bc.upd.innerHTML = bim?'U':'[update]';
  284. bc.auto.innerHTML = bim?'A':'[auto]';
  285. bc.drag.innerHTML = bim?'+':'&nbsp;';
  286. bc.mini.innerHTML = bim?'\u53E3':'\u2013';//\u039e
  287. bc.mini.temptitle = bim?'Full':'Mini';
  288. if(Box.showTitles) bc.mini.title = bc.mini.temptitle;
  289. }//
  290. if(opt[1]){//Pinned/unpinned
  291. bc.pin.innerHTML = Box.isPinned?'\u51fa':'\u4e2d';//\u00a4':'\u00f8';//d7';
  292. bc.pin.temptitle = Box.isPinned?'Unpin':'Pin';
  293. if(Box.showTitles) bc.pin.title = bc.pin.temptitle;
  294. }
  295. if(opt[2]){//Update interval
  296. bc.inp.value = Box.interval;
  297. bc.set.innerHTML = Box.interval+'sec'+
  298. ((Box.interval>1)?'s':null);
  299. }
  300. },
  301. //Buttons/input
  302. toggleMinimal: function(){
  303. Box.isMini = !Box.isMini;
  304. Box.saveValues();
  305. setCustomStyle(document.getElementById(Box.uid+'_css'));
  306. Box.setLabels('1');
  307. Box.updateMsg();
  308. },
  309. recalcYOffset: function(){//fixed(px)/absolute(%) offset conversion
  310. var bco = Box.con.outer;
  311. var bcos = bco.style;
  312. var wih = window.innerHeight;
  313. var wpyo = window.pageYOffset;
  314. var pageh = document.documentElement.scrollHeight; //wsmy + wih
  315. var wsmy = pageh - wih; //window.scrollMaxY
  316. var fixedoffset = Box.isPinned;
  317. var top, btm;
  318. function cvt(val, offset){
  319. return fixedoffset?
  320. parseInt(val) + offset:
  321. Math.round(pageh * parseFloat(val)/100) - offset;
  322. }
  323. if(bcos.top){
  324. top = cvt(bcos.top, wpyo);
  325. btm = (fixedoffset?pageh:wih) - top - bco.offsetHeight;
  326. }else{
  327. btm = cvt(bcos.bottom, wsmy - wpyo);
  328. top = (fixedoffset?pageh:wih) - btm - bco.offsetHeight;
  329. }
  330. function suffix(val){
  331. val = val<10?0:val;
  332. return fixedoffset?
  333. Math.round(((val/pageh) * 100)) + '%' :
  334. val + 'px';
  335. }
  336. bcos.top = (top<=btm)? suffix(top) :null;
  337. bcos.bottom = (top<=btm)? null: suffix(btm);
  338. },
  339. togglePin: function(){
  340. Box.recalcYOffset();
  341. Box.isPinned = !Box.isPinned;
  342. Box.con.outer.style.position = Box.isPinned?'fixed':'absolute';
  343. Box.saveValues();
  344. Box.setLabels('01');
  345. },
  346. setInterval: function(evt){
  347. //evt.preventDefault();
  348. Box.interval = parseInt(Box.con.inp.value);
  349. Box.saveValues();
  350. Box.setLabels('001');
  351. },
  352. validateInput: function(evt){
  353. if(evt.keyCode == 13) //Enter
  354. Box.setInterval(evt);
  355. if(!evt.charCode) return;
  356. if(
  357. evt.charCode < 48 ||
  358. evt.charCode > 57 ||
  359. evt.target.value.toString().length >= 5
  360. )
  361. evt.preventDefault();
  362. },
  363. toggleAuto: function(set){
  364. Box.isAuto = ((set == 'off')? false : !Box.isAuto);
  365. var bca = Box.con.auto;
  366. bca.style.color = Box.isAuto? '#119911':'';
  367. bca.temptitle = (Box.isAuto?'Disable':'Enable') +' Auto-update';
  368. if(Box.showTitles) bca.title = bca.temptitle;
  369. if(Box.isAuto) Box.searchProcess(0);
  370. },
  371. //Move/drag
  372. offset:{ left:0, top:0, unpin: false,
  373. tempShow:function(dis){
  374. var el = ['pin', 'mini', 'drag', 'upd', 'af'];
  375. for(i in el)
  376. Box.con[el[i]].style.display = dis?'inline':'';
  377. }
  378. },
  379. dragStart: function(evt){
  380. if(!Box.isPinned){ //Pin temporarily (Todo: Full page dragging.)
  381. Box.togglePin();
  382. Box.offset.unpin = true;;
  383. }
  384. Box.offset.tempShow(true);
  385. var bco = Box.con.outer
  386. var bcos = bco.style;
  387. Box.offset.left = evt.clientX -
  388. (bcos.left? parseInt(bcos.left) :
  389. (window.innerWidth -
  390. parseInt(bcos.right) -
  391. bco.offsetWidth));
  392. Box.offset.top = evt.clientY -
  393. (bcos.top? parseInt(bcos.top) :
  394. (window.innerHeight -
  395. parseInt(bcos.bottom) -
  396. bco.offsetHeight));
  397. listen(document, 'mousemove', Box.doDrag);
  398. listen(document, 'mouseup', Box.dragStop);
  399. document.body.focus();
  400. },
  401. doDrag: function(evt){
  402. var bco = Box.con.outer;
  403. var bcos = bco.style;
  404. var left = evt.clientX - Box.offset.left;
  405. var right = window.innerWidth - left - bco.offsetWidth;
  406. var top = evt.clientY - Box.offset.top;
  407. var bottom = window.innerHeight - top - bco.offsetHeight;
  408. bcos.left = (left<=right)? ((left<10?0:left)+'px') :null;
  409. bcos.right = (left<=right)? null: ((right<10?0:right)+'px');
  410. bcos.top = (top<=bottom)? ((top<10?0:top)+'px') :null;
  411. bcos.bottom = (top<=bottom)? null: ((bottom<10?0:bottom)+'px');
  412. },
  413. dragStop: function(evt){
  414. if(Box.offset.unpin){ //Return pin-state (Todo)
  415. Box.togglePin();
  416. Box.offset.unpin = false;
  417. }
  418. Box.offset.tempShow(false);
  419. listen(document, 'mousemove', Box.doDrag, 'remove');
  420. listen(document, 'mouseup', Box.dragStop, 'remove');
  421. Box.setLabels('000');
  422. Box.saveValues();
  423. },
  424. //Text display
  425. updateStat: function(msg, clear){
  426. if(clear) this.con.stat.innerHTML = '';
  427. this.con.stat.innerHTML += msg;
  428. },
  429. updateMsg: function(details){
  430. if(!details){
  431. if(!Box.lastdetails) return;
  432. else details = Box.lastdetails;
  433. }else Box.lastdetails = details;
  434.  
  435. if(Box.isMini)
  436. this.con.msg.innerHTML = [
  437. 'Pg ', details.page,
  438. '/', details.lastpage,
  439. ' Th ', details.threadpos,
  440. '/', details.threadtotal
  441. ].join('');
  442. else
  443. this.con.msg.innerHTML = [
  444. 'Page: <b>', details.page,
  445. '</b>/', details.lastpage,
  446. '<br>Thread: <b>', details.threadpos,
  447. '</b>/', details.threadtotal
  448. ].join('');
  449.  
  450. if(!details) return;
  451. var suff = 'th';
  452. if(details.threadpos == 1) suff = 'st';
  453. if(details.threadpos == 2) suff = 'nd';
  454. if(details.threadpos == 3) suff = 'rd';
  455. var tcm = this.con.msg;
  456. tcm.temptitle = [
  457. Thread.id,
  458. ' is the ', details.threadpos, suff,
  459. ' of ', details.threadtotal,
  460. ' thread', ((details.threadtotal>1)?'s':''),
  461. ' on page ', details.page,
  462. ' of ', (details.lastpage?
  463. ('all '+ (parseInt(details.lastpage)+1) + ' pages'):
  464. 'a page'),
  465. ' on ', Frontpage.board, '.',
  466. ].join('');
  467. if(Box.showTitles) tcm.title = tcm.temptitle;
  468. },
  469. //Searching
  470. forceUpdate: function(){
  471. Box.updateStat('', true);
  472. Box.searchProcess(2);
  473. },
  474. searchProcess: function(stage){
  475. switch(stage){
  476. case 0:
  477. var count = Box.interval;
  478. function countDown(){
  479. //if(!Box.isAuto) return;
  480. if(!count)
  481. Box.searchProcess(1);
  482. else {
  483. Box.updateStat([
  484. 'Updating in ',
  485. count, 'sec', (count>1?'s':'')].join(''),
  486. true);
  487. count--;
  488. clearTimeout(Box.toh);
  489. Box.toh = window.setTimeout(countDown, 1000);
  490. }
  491. }
  492. countDown();
  493. break;
  494. case 1:
  495. Box.updateStat('Checking frontpage... ', true);
  496. Frontpage.check(true, function(res){
  497. Box.updateStat(res.statusText);
  498. switch(res.status){
  499. case 200: //Frontpage changed. Do next stage
  500. Box.updateStat('<br>');
  501. Box.searchProcess(2);
  502. break;
  503. case 304: //No change on frontpage. Restart.
  504. if(Box.isAuto){
  505. window.setTimeout(function(){
  506. Box.searchProcess(0);
  507. }, 1500); //Show status message for 1.5sec
  508. }
  509. break;
  510. default: Box.toggleAuto('off');
  511. }
  512. });
  513. break;
  514. case 2:
  515. Box.updateStat('Checking thread... ');
  516. Thread.check(function(res){
  517. Box.updateStat(res.statusText);
  518. if(res.status == 200){ //Thread still up. Do next stage.
  519. Box.updateStat('<br>');
  520. Box.searchProcess(3);
  521. }else Box.toggleAuto('off');
  522. });
  523. break;
  524. case 3:
  525. Box.updateStat('Finding thread\'s page... ');
  526. clearTimeout(Box.toh);
  527. findThread(Box.pagelastfound, function(details){
  528. if(details){
  529. Box.updateStat('', true); //Clear status message
  530. Box.updateMsg(details);
  531. Box.pagelastfound = details.page;
  532. if(Box.isAuto) Box.searchProcess(0);
  533. }else{
  534. Box.updateStat('Can\'t find thread');
  535. if(!Frontpage.is_f){
  536. Box.updateStat('<br>');
  537. Box.searchProcess(2);
  538. }else{
  539. Box.updateStat('<br>(Marked for deletion?)');
  540. Box.toggleAuto('off');
  541. }
  542. }
  543. });
  544. }
  545. }
  546. }//Box
  547. function findThread(lastfound, callfunc){
  548. var nextpage = lastfound;
  549. var lastpage = 15;
  550. if(Frontpage.is_f){
  551. lastpage = 0;
  552. searchPages();
  553. }
  554. else
  555. xhr(Frontpage.url, function(res){
  556. var pages = res.responseText.match(Frontpage.rx_pages);
  557. lastpage = pages.length || 0;
  558. searchPages();
  559. });
  560. /*function getLastpage(res){
  561. if(!res){
  562. xhr(Frontpage.url+lastpage, getLastpage, 'head');
  563. }else{
  564. if(res.status == 200 || !lastpage){
  565. searchPages();
  566. }else{
  567. lastpage--;
  568. getLastpage(null);
  569. }}}*/
  570. function searchPages(res){
  571. if(res && res.status == 200){
  572. var threadnos = res.responseText.match(Frontpage.rx_threadnos);
  573. for(var i = 0; i < threadnos.length; i++){
  574. if(Thread.rx_id.test(threadnos[i])){
  575. var details = {
  576. page: res.url.replace(Frontpage.url, ''),
  577. lastpage: lastpage,
  578. threadpos: (i+1),
  579. threadtotal: threadnos.length
  580. }
  581. callfunc(details);
  582. return;
  583. }
  584. }
  585. if(nextpage >= lastpage) nextpage = 0;
  586. else nextpage++;
  587. if(nextpage == lastfound || !lastpage){
  588. callfunc(null);
  589. return;
  590. }
  591. }
  592. xhr(Frontpage.url+nextpage, searchPages);
  593. }
  594. }
  595. function clearSettings(){
  596. GM_deleteValue('_isMini');
  597. GM_deleteValue('_interval');
  598. GM_deleteValue('_isPinned');
  599. GM_deleteValue('_offset_left');
  600. GM_deleteValue('_offset_top');
  601. GM_deleteValue('_offset_right');
  602. GM_deleteValue('_offset_bottom');
  603. GM_deleteValue('_showTitles');
  604. try{
  605. var ui = document.getElementById(Box.uid);
  606. ui.parentNode.removeChild(ui);
  607. }catch(e){console.log(e);}
  608. init();
  609. }
  610. function toggleTitles(off){
  611. var bc = Box.con;
  612. var show = (typeof off === 'boolean')? off : !Box.showTitles;
  613. for(i in bc){
  614. var title = bc[i].temptitle;
  615. if( title ) bc[i].title = show?title:'';
  616. }
  617. Box.showTitles = show;
  618. GM_setValue('_showTitles', show);
  619. alert(Box.uid+':\nTitles/hover messages '+(show?'enabled':'disabled'));
  620. }
  621. try{
  622. GM_registerMenuCommand(
  623. 'ThreadPageFinder: Reset/restore settings',
  624. clearSettings, 'R');
  625. GM_registerMenuCommand(
  626. 'ThreadPageFinder: Enable/disable titles (hover messages)',
  627. toggleTitles, 'E');
  628. }catch(e){console.log(e);}
  629. //Utilities
  630. if(GM_setValue === undefined){
  631. GM_setValue = function(key, val){
  632. val = (typeof val)[0] + val;
  633. localStorage.setItem(Box.uid+key, val);
  634. }
  635. GM_getValue = function(key, defval){
  636. var val = localStorage.getItem(Box.uid+key);
  637. if(!val) return defval;
  638. var type = val[0];
  639. val = val.substring(1);
  640. if(type == 'b') return val == 'true';
  641. if(type == 'n') return parseInt(val);
  642. return val;
  643. }
  644. GM_deleteValue = function(key){
  645. localStorage.removeItem(Box.uid+key);
  646. }
  647. }
  648. function listen(item, type, func, remove){
  649. if(remove) item.removeEventListener(type, func, false);
  650. else item.addEventListener(type, func, false);
  651. }
  652. function xhr(url, callfunc, type, lastdate){
  653. type = type || 'get';
  654. var xhr = new XMLHttpRequest();
  655. xhr.url = url; //For page checking.
  656. xhr.onreadystatechange = function(){
  657. if(xhr.readyState == 4)
  658. callfunc(xhr);
  659. }
  660. xhr.open(type, url, true);
  661. if(lastdate)
  662. xhr.setRequestHeader('If-Modified-Since', lastdate);
  663. xhr.send();
  664. }
  665. //Begin
  666. function init(){
  667. Box.init();
  668. Thread.init();
  669. Frontpage.init();
  670.  
  671. Box.searchProcess(3);
  672. }
  673. if (document.addEventListener)
  674. document.addEventListener('DOMContentLoaded', init, false);
  675. else window.addEventListener('load', init, false);
  676. //
  677. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement