Gazelle: Toggle Format Visibility

Hide formats with your discretion.

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

  1. // ==UserScript==
  2. // @id what-toggle-formats
  3. // @name Gazelle: Toggle Format Visibility
  4. // @namespace hateradio)))
  5. // @author hateradio
  6. // @version 3
  7. // @description Hide formats with your discretion.
  8. // @include http*://*what.cd/torrents.php*
  9. // @include http*://*what.cd/artist.php?id=*
  10. // @include http*://*what.cd/bookmarks.php*
  11. // @include http*://*what.cd/collages.php*
  12.  
  13. // @match *://*.what.cd/torrents.php*
  14. // @match *://*.what.cd/artist.php?id=*
  15. // @match *://*.what.cd/bookmarks.php*
  16. // @match *://*.what.cd/collages.php?*
  17.  
  18. // @include http*://*apollo.rip/torrents.php*
  19. // @include http*://*apollo.rip/artist.php?id=*
  20. // @include http*://*apollo.rip/bookmarks.php*
  21. // @include http*://*apollo.rip/collages.php*
  22.  
  23. // @match *://*.apollo.rip/torrents.php*
  24. // @match *://*.apollo.rip/artist.php?id=*
  25. // @match *://*.apollo.rip/bookmarks.php*
  26. // @match *://*.apollo.rip/collages.php?*
  27.  
  28. // @grant none
  29. // @updated 24 SEP 2011
  30. // @since 28 OCT 2010
  31. // ==/UserScript==
  32.  
  33. // S T O R A G E HANDLE
  34. var strg = {
  35. init:function(){ this.on = this.work(); },
  36. work:function(){ try { return 'localStorage' in window && window['localStorage'] !== null; } catch(e) { return false; } },
  37. read:function(key){ return this.on ? JSON.parse(window.localStorage.getItem(key)) : false; },
  38. save:function(key,dat){ return this.on ? !window.localStorage.setItem(key, JSON.stringify(dat)) : false; },
  39. wipe:function(key){ return this.on ? !window.localStorage.removeItem(key) : false; }
  40. };
  41. strg.init();
  42.  
  43. var hide = {
  44. loc:document.querySelector('.sidebar') || document.querySelector('.linkbox'),
  45. anc:(document.getElementById('discog_table') || document.querySelector('.torrent_table')).querySelectorAll('a[href^="torrents.php?id="],a[onclick]'),
  46. str:document.querySelectorAll('.edition_info > strong'),
  47. typ:['CD','Vinyl','WEB','SACD','DVD','DAT','Cassette','Blu-ray','Soundboard'],
  48. cod:['FLAC','Ogg','AAC','AC3','DTS','MP3'],
  49. enc:['192','APS','V2','V1','256','APX','V0','320','/ Lossless','24bit Lossless'],
  50. lch:['Scene','Freeleech','Neutral Leech','Reported','Bad'],
  51. hid:strg.read('togglesettings2') || [],
  52. div:document.createElement('div'),
  53. init:function(){
  54. var tog = this, s = document.createElement('style'), top = document.getElementsByTagName('head')[0],
  55. css = '.hider-f { text-decoration: line-through } #format-hide { text-align: center; margin: 3px 0px }';
  56. s.type = 'text/css'; s.textContent = css; top.appendChild(s);
  57. // run!
  58. this.bond = function(m,b){ var c = function(e){ if(b !== true && e){e = e.currentTarget;} m.call(tog,e); }; return c; };
  59. this.location();
  60. this.generate();
  61. this.toggle(this.hid);
  62. this.toggle(this.hid,true);
  63. this.mark();
  64. },
  65. location:function(){
  66. this.div.id = 'format-hide';
  67. this.div.className = 'box box_artists';
  68. this.loc.parentNode.insertBefore(this.div,this.loc);
  69. },
  70. slink:function(t){
  71. var S = document.createElement('span');
  72. S.data = t;
  73. S.textContent = t.replace(/(?:\/|\\)/,'');
  74. S.id = 'togformatvis_'+S.textContent.replace(/(?:\s)/,'');
  75. S.style.cursor = 'pointer';
  76. S.addEventListener('click',this.bond(this.change), false);
  77. S.setAttribute('onmousedown','return false;');
  78. this.div.appendChild(S);
  79. this.div.appendChild(document.createTextNode(' '));
  80. },
  81. proc:function(a,b){
  82. var x = -1, y = a.length;
  83. while(++x<y){ this.slink(a[x]); }
  84. switch(b){
  85. case 1 : this.div.appendChild(document.createElement('br')); break;
  86. case 2 : this.div.appendChild(document.createTextNode(' \u00D7 ')); break;
  87. default : break;
  88. }
  89. },
  90. generate:function(){
  91. this.proc(this.typ,1);
  92. this.proc(this.cod,2);
  93. this.proc(this.enc,2);
  94. this.proc(this.lch);
  95. },
  96. change:function(el){
  97. var idx = this.hid.indexOf(el.data), idz = (this.typ.indexOf(el.data) !== -1);
  98. el.className = el.className === 'hider-f' ? 'hider-o' : 'hider-f';
  99. if(idx === -1){
  100. this.hid.push(el.data);
  101. this.show = false;
  102. this.toggle(this.hid,idz);
  103. }else{
  104. this.hid.splice(idx,1);
  105. this.show = true;
  106. this.toggle([el.data],idz);
  107. }
  108. },
  109. toggle:function(a,b){
  110. var p, q, r = a.length > 0 ? '(?:'+a.join('|')+')\\b' : false, x = -1, y = !b ? this.anc : this.str, z = y.length;
  111. if(r){
  112. strg.save('togglesettings2',this.hid);
  113. r = new RegExp(r,'i');
  114. while(++x<z){ q = y[x];
  115. if(r.test(q.textContent)){
  116. if(b){
  117. p = q.querySelector('a'); this.show ? p.textContent === '-' ? false : this.click(p) : p.textContent === '+' ? false : this.click(p);
  118. }else{
  119. this.show ? q.parentNode.parentNode.removeAttribute('style') : q.parentNode.parentNode.setAttribute('style','display:none');
  120. }
  121. }
  122. }
  123. }
  124. },
  125. mark:function(){
  126. var x = -1, y = this.hid.length, z;
  127. while(++x<y){ z = this.hid[x];
  128. z = document.getElementById('togformatvis_'+z.replace(/(?:\/|\\|\s)/g,'')); z.className = 'hider-f';
  129. }
  130. },
  131. click:function(el){
  132. var evt;
  133. if(el.click){ el.click(); }
  134. else{ evt = document.createEvent('MouseEvents'); evt.initEvent('click', true, true); el.dispatchEvent(evt); }
  135. }
  136. };
  137.  
  138. hide.init();