Greasy Fork 还支持 简体中文。

What.CD: Toggle Format Visibility

Hide formats with your discretion.

目前為 2014-05-16 提交的版本,檢視 最新版本

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