greatest.deepsurf.us langfilter

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

Fra 10.10.2014. Se den seneste versjonen.

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