Greasy Fork 支持简体中文。

greasyfork.org langfilter

filters out scripts and posts containing non-latin letters in title

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

  1. // ==UserScript==
  2. // @name greasyfork.org langfilter
  3. // @namespace trespassersW
  4. // @include http*://greasyfork.org/scripts*
  5. // @include http*://greasyfork.org/forum*
  6. // @description filters out scripts and posts containing non-latin letters in title
  7. // @version 2.014.0705.2
  8. // @created 2014-07-05
  9. // @updated 2014-07-05
  10. // @run-at document-end
  11. // @grant GM_none
  12. // ==/UserScript==
  13. (function(){
  14. // either 'string' or /RegEx/ in title
  15. var filterz = [
  16. /[^\u0000-\u2FFF]/
  17. /* * /
  18. ,/\//
  19. /* */
  20. ];
  21.  
  22. var C=0,S,E;
  23. var inForum=location.href.indexOf(".org/forum")>-1;
  24. var locStor=null;
  25.  
  26. function toggleV(x){
  27. var t = ('N'===x)? false: ('Y'===x)? true: !S.disabled;
  28. S.disabled = t;
  29. E.innerHTML= (t?'hide':'show')+' ['+C+']';
  30. locStor && locStor.setItem("langfilter",t?'Y':'N');
  31. }
  32.  
  33. function stickStyle(css){
  34. var s=document.createElement("style"); s.type="text/css";
  35. s.appendChild(document.createTextNode(css));
  36. return (document.head||document.documentElement).appendChild(s);
  37. }
  38.  
  39. function isListed(tc, bl){
  40. if(tc) try{
  41. for(var j=0,lj=bl.length; j<lj; j++) {
  42. if( typeof bl[j] === "string" ) {
  43. if( (tc.indexOf(bl[j])>-1) ) return true;
  44. }else if( typeof bl[j].test === "function" ) { // regex ?
  45. if( bl[j].test(tc) ){
  46. return true;
  47. }
  48. }else throw "bad filterz";
  49. };
  50. } catch(e){ console.log(e+'\n j:'+j+'; tc:'+tc+'; bl:'+bl); undefined_function(); };
  51. return false;
  52. }
  53.  
  54. var listSel, titlSel;
  55. if(inForum)
  56. listSel='#Content .DataList > li.Item',
  57. titlSel=".Title";
  58. else
  59. listSel='#browse-script-list > li[data-script-type]',
  60. titlSel="h2>span.description";
  61.  
  62. var a;
  63. a = document.querySelectorAll(listSel);
  64.  
  65. if(a)
  66. for (var i=0, li=a.length, t; i<li; i++) {
  67. t=a[i].querySelector(titlSel);
  68. if(t && isListed(t.textContent, filterz)){
  69. a[i].classList.add('greazy-forq-hiden'); C++;
  70. continue;
  71. }
  72. }
  73. if(!C){
  74. return; // all clear
  75. }
  76. E=document.createElement('div');
  77. E.id="greazy-forq-info";
  78. E.style.cssText = '\
  79. position:fixed;\
  80. left:2px;top:2px;\
  81. background:rgba(255,255,255,.55);\
  82. color:#670000;border:thin dotted 0xA40;\
  83. text-shadow: #311 2px 2px 4px, #F73 -2px -2px 4px;\
  84. cursor:pointer;\
  85. ';
  86. E.addEventListener('click',toggleV,false);
  87. document.body.appendChild(E);
  88. stickStyle('\
  89. .greazy-forq-hiden{border:thin dotted #A40 !important;\
  90. background-color:#FFFCF4}\
  91. ');
  92. S=stickStyle('\
  93. li.greazy-forq-hiden *{display:none!important;}\
  94. li.greazy-forq-hiden {padding:0!important;margin:0!important;\
  95. }\
  96. ');
  97.  
  98. var sh;
  99. try {
  100. locStor = window.localStorage;
  101. sh=locStor.getItem("langfilter");
  102. } catch(e){ locStor=null; }
  103. toggleV(sh||'N');
  104.  
  105. })();