Greasyfork Search with Sleazyfork Results include

Merge adult results of sleazyfork into greasyfork when the script is no longer anonymously available, add rating score and version for scripts then

2022-01-07 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Greasyfork Search with Sleazyfork Results include
  3. // @name:zh-CN 大人的Greasyfork
  4. // @name:zh-TW 大人的Greasyfork
  5. // @name:ja 大人のGreasyfork
  6. // @namespace hoothin
  7. // @version 1.2
  8. // @description Merge adult results of sleazyfork into greasyfork when the script is no longer anonymously available, add rating score and version for scripts then
  9. // @description:zh-CN 在Greasyfork的搜索结果中添加Sleazyfork上的成人脚本,增加评分与版本号,并在访问匿名不可用脚本时跳转至Sleazyfork
  10. // @description:zh-TW 在Greasyfork的搜索結果中添加Sleazyfork上的成人腳本,增加評分與版本號,並在訪問匿名不可用腳本時跳轉至Sleazyfork
  11. // @description:ja 脚本付けるSleazyfork上の成人脚本検索結果からGreasyfork、脚本付ける採点とバージョン番号を訪問匿名利用できない脚本にジャンプからSleazyfork
  12. // @author hoothin
  13. // @include http*://greatest.deepsurf.us/*
  14. // @include http*://www.greatest.deepsurf.us/*
  15. // @include http*://sleazyfork.org/*
  16. // @include http*://www.sleazyfork.org/*
  17. // @grant GM_xmlhttpRequest
  18. // @grant GM_setValue
  19. // @grant GM_getValue
  20. // @grant GM_registerMenuCommand
  21. // @grant GM_notification
  22. // @grant GM.xmlhttpRequest
  23. // @grant GM.setValue
  24. // @grant GM.getValue
  25. // @grant GM.registerMenuCommand
  26. // @grant GM.notification
  27. // @connect greatest.deepsurf.us
  28. // @connect sleazyfork.org
  29. // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=rixixi@sina.com&item_name=Greasy+Fork+donation
  30. // @contributionAmount 1
  31. // ==/UserScript==
  32.  
  33. (async function() {
  34. 'use strict';
  35. if(typeof GM_getValue=='undefined' && GM && GM.getValue){
  36. var GM_getValue=GM.getValue;
  37. var GM_setValue=GM.setValue;
  38. var GM_xmlhttpRequest=GM.xmlhttpRequest;
  39. var GM_registerMenuCommand=GM.registerMenuCommand;
  40. var GM_notification=GM.notification;
  41. }
  42. if(typeof GM_xmlhttpRequest=='undefined')GM_xmlhttpRequest=(f)=>{};
  43. if(typeof GM_registerMenuCommand=='undefined')GM_registerMenuCommand=(s,f)=>{};
  44. if(typeof GM_notification=='undefined')GM_notification=(s)=>{};
  45. var storage={
  46. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  47. mxAppStorage:(function(){
  48. try{
  49. return window.external.mxGetRuntime().storage;
  50. }catch(e){
  51. };
  52. })(),
  53. operaUJSStorage:(function(){
  54. try{
  55. return window.opera.scriptStorage;
  56. }catch(e){
  57. };
  58. })(),
  59. setItem:function(key,value){
  60. if(this.operaUJSStorage){
  61. this.operaUJSStorage.setItem(key,value);
  62. }else if(this.mxAppStorage){
  63. this.mxAppStorage.setConfig(key,value);
  64. }else if(this.supportGM){
  65. GM_setValue(key,value);
  66. }else if(window.localStorage){
  67. window.localStorage.setItem(key,value);
  68. };
  69. },
  70. getItem:function(key){
  71. var value;
  72. if(this.operaUJSStorage){
  73. value=this.operaUJSStorage.getItem(key);
  74. }else if(this.mxAppStorage){
  75. value=this.mxAppStorage.getConfig(key);
  76. }else if(this.supportGM){
  77. value=GM_getValue(key);
  78. }else if(window.localStorage){
  79. value=window.localStorage.getItem(key);
  80. };
  81. return value;
  82. },
  83. };
  84. if(document.querySelector('span.sign-in-link')){
  85. var otherSite=/greasyfork\.org/.test(location.hostname)?"sleazyfork":"greasyfork";
  86. if(/scripts\/\d+/.test(location.href)){
  87. if(!document.querySelector("#script-info") && (otherSite == "greasyfork" || document.querySelector("div.width-constraint>section>p>a").href.indexOf("sign_in")!=-1)){
  88. location.href=location.href.replace(/\/\/([^\.]+\.)?(greasyfork|sleazyfork)\.org/,"//$1"+otherSite+"\.org");
  89. }
  90. }else if(/\/(scripts|users)(\/|.*(\?|&)q=|.*\?set=)/.test(location.href)){
  91. GM_xmlhttpRequest({
  92. method: 'GET',
  93. url: location.href.replace(/\/\/([^\.]+\.)?(greasyfork|sleazyfork)\.org/,"//$1"+otherSite+"\.org"),
  94. onload: function(result) {
  95. var doc = null;
  96. try {
  97. doc = document.implementation.createHTMLDocument('');
  98. doc.documentElement.innerHTML = result.responseText;
  99. }
  100. catch (e) {
  101. console.log('parse error');
  102. }
  103. if (!doc) {
  104. return;
  105. }
  106. var l = doc.querySelector('ol.script-list');
  107. if (l) {
  108. var ml = document.querySelector('ol.script-list');
  109. if(!ml){
  110. ml=document.createElement("ol");
  111. ml.setAttribute("class","script-list");
  112. var list=document.querySelector('.sidebarred-main-content');
  113. var ps=list.querySelectorAll("p");
  114. for(let i=0;i<ps.length;i++){
  115. let p=ps[i];
  116. list.removeChild(p);
  117. }
  118. list.appendChild(ml);
  119. }
  120. var scs=l.querySelectorAll("li");
  121. if(scs){
  122. for(let i=0;i<scs.length;i++){
  123. let sc=scs[i];
  124. if(!ml.querySelector("li[data-script-id='"+sc.dataset.scriptId+"']")){
  125. //addScore(sc);
  126. ml.appendChild(sc);
  127. }
  128. }
  129. }
  130. }
  131. },
  132. onerror: function(e) {
  133. console.log(e);
  134. }
  135. });
  136. }
  137. }
  138. var bullshit=await storage.getItem("GeasyforkBullshit"),bullshit_o=`vip.*视频|网课|刷课|(mooc|考试|学习).*(答题|挂机)|(网盘|網盤|云盘).*(vip|直链)|优惠劵|AntiGame|split|Agar|\\.io(\\b|:|\\/|\\.|$)|ExtencionRipXChetoMalo|AposBot|DFxLite|ZTx-Lite|AposFeedingBot|AposLoader|Blah Blah|Orc Clan Script|Astro\\s*Empires|^\\s*Attack|^\\s*Battle|BiteFight|Blood\\s*Wars|Bots|Bots4|Brawler|\\bBvS\\b|Business\\s*Tycoon|Castle\\s*Age|City\\s*Ville|Comunio|Conquer\\s*Club|CosmoPulse|Dark\\s*Orbit|Dead\\s*Frontier|\\bDOA\\b|DotD|Dossergame|Dragons\\s*of\\s*Atlantis|Dugout|\\bDS[a-z]+\\n|Empire\\s*Board|eRep(ublik)?|Epic.*War|ExoPlanet|Falcon Tools|Feuerwache|Farming|FarmVille|Fightinfo|Frontier\\s*Ville|Ghost\\s*Trapper|Gladiatus|Goalline|Gondal|Grepolis|Hobopolis|\\bhwm(\\b|_)|Ikariam|\\bIT2\\b|Jellyneo|Kapi\\s*Hospital|Kings\\s*Age|Kingdoms?\\s*of|knastv(ö|oe)gel|Knight\\s*Fight|\\b(Power)?KoC(Atta?ck)?\\b|\\bKOL\\b|Kongregate|Last\\s*Emperor|Legends?\\s*of|Light\\s*Rising|Lockerz|\\bLoU\\b|Mafia\\s*(Wars|Mofo)|Menelgame|Mob\\s*Wars|Mouse\\s*Hunt|Molehill\\s*Empire|NeoQuest|MyFreeFarm|Neopets|Nemexia|\\bOGame\\b|Ogar(io)?|Pardus|Pennergame|Pigskin\\s*Empire|PlayerScripts|Popmundo|Po?we?r\\s*(Bot|Tools)|PsicoTSI|Ravenwood|Schulterglatze|slitheriogameplay|SpaceWars|\\bSW_[a-z]+\\n|\\bSnP\\b|The\\s*Crims|The\\s*West|Travian|Treasure\\s*Isl(and|e)|Tribal\\s*Wars|TW.?PRO|Vampire\\s*Wars|War\\s*of\\s*Ninja|West\\s*Wars|\\bWoD\\b|World\\s*of\\s*Dungeons|wtf\\s*battles|Wurzelimperium`;
  139. if(!bullshit)bullshit=bullshit_o;
  140. if(/greasyfork\.org\/.*\/scripts\/23840[^\/]*$/.test(location.href)){
  141. var p=document.createElement("p"),_bullshit;
  142. p.style.width="90%";
  143. p.innerHTML="<b>Filter RegExp string Config</b><button id='ok' style='margin-left: 20px;'>OK</button><button id='reset' style='margin-left: 20px;'>Reset</button>";
  144. var okBtn=p.querySelector("#ok");
  145. var resetBtn=p.querySelector("#reset");
  146. var filterTextarea=document.createElement("pre");
  147. var prettifyScript=document.createElement("script");
  148. prettifyScript.src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?lang=js&skin=sunburst";
  149. document.head.appendChild(prettifyScript);
  150. filterTextarea.contentEditable="true";
  151. filterTextarea.className="prettyprint lang-js";
  152. filterTextarea.style.whiteSpace="pre-wrap";
  153. filterTextarea.style.overflowWrap="break-word";
  154. filterTextarea.innerHTML=bullshit;
  155. var additionalInfo=document.querySelector("#additional-info");
  156. p.appendChild(filterTextarea);
  157. additionalInfo.insertBefore(p,additionalInfo.firstChild);
  158. prettifyScript.onload=()=>{PR.prettyPrint();};
  159. okBtn.onclick=()=>{
  160. _bullshit=filterTextarea.innerText;
  161. storage.setItem("GeasyforkBullshit", _bullshit);
  162. alert("Saved");
  163. //GM_notification("Saved");
  164. };
  165. resetBtn.onclick=()=>{
  166. storage.setItem("GeasyforkBullshit", bullshit_o);
  167. alert("Reset over");
  168. location.reload();
  169. //GM_notification("Reset over");
  170. };
  171. }
  172.  
  173. function addScore(script){
  174. var separator=script.querySelector('h2>span.name-description-separator');
  175. var description=script.querySelector('h2>span.description');
  176. if(separator){
  177. var score=document.createElement("strong");
  178. score.style.color="#e09015";
  179. score.innerHTML=script.dataset.scriptRatingScore;
  180. separator.parentNode.insertBefore(score,separator);
  181. }
  182. if(description){
  183. count(script);
  184. var scriptHref=script.querySelector('h2>a').href;
  185. let version=script.dataset.scriptVersion;
  186. let format=script.dataset.scriptLanguage;
  187. description.innerHTML+=`<strong>Ver.${version}</strong>
  188. <div id="install-area" class="list-install-area">
  189. <a class="install-link" data-install-format="${format}" data-ping-url href="${scriptHref.replace(/\.org\/.*\/scripts\//,".org/scripts/")}/code/script.user.js">Install</a><a style="cursor:pointer;" class="install-help-link refresh-info" title="Check status" rel="nofollow"></a>
  190. </div><div id="installation-instructions-modal-js" aria-hidden="true"><p class="installation-instructions-modal-content-bypass"><a href="#"></a></p></div><div id="installation-instructions-modal-css" aria-hidden="true"><p class="installation-instructions-modal-content-bypass"><a href="#"></a></p></div>`;
  191. var installArea=description.querySelector("#install-area");
  192. let installLink=installArea.querySelector(".install-link");
  193. let checkInfo=installArea.querySelector(".install-help-link");
  194. script.onmouseenter=e=>{
  195. checkInfo.appendChild(refreshIcon);
  196. };
  197. script.onmouseleave=e=>{
  198. checkInfo.removeChild(refreshIcon);
  199. };
  200. checkInfo.onclick=()=>{
  201. GM_xmlhttpRequest({
  202. method: 'GET',
  203. url: scriptHref.replace(/(.*)-.*/,"$1.json"),
  204. onload: function(result) {
  205. var data = null;
  206. try {
  207. data = JSON.parse(result.responseText);
  208. }
  209. catch (e) {
  210. console.log('parse error');
  211. }
  212. if(data){
  213. let setInfo=info=>{
  214. if(info.installed){
  215. if(parseFloat(info.version) < parseFloat(version)){
  216. installLink.innerHTML="Update to version "+version;
  217. }else if(parseFloat(info.version) > parseFloat(version)){
  218. installLink.innerHTML="Downgrade to version "+version;
  219. }else{
  220. installLink.innerHTML="Reinstall version "+version;
  221. }
  222.  
  223. if(!info.enabled){
  224. installLink.style.backgroundColor="#6a6a6a";
  225. }else{
  226. installLink.style.backgroundColor="";
  227. }
  228. }else{
  229. installLink.innerHTML="Install version "+version;
  230. }
  231. };
  232. if(window.external.Tampermonkey){
  233. window.external.Tampermonkey.isInstalled(data.name, data.namespace, e=>{
  234. setInfo(e);
  235. });
  236. }else if(window.external.Violentmonkey){
  237. window.external.Violentmonkey.isInstalled(data.name, data.namespace).then(e=>{
  238. setInfo(e);
  239. });
  240. }
  241. }
  242. }
  243. });
  244. };
  245. if(!window.external.Tampermonkey && !window.external.Violentmonkey){
  246. checkInfo.style.display="none";
  247. }
  248. }
  249. }
  250.  
  251. function count(script){
  252. if(!inUserPage)return;
  253. var dailySpan=script.querySelector("dd.script-list-daily-installs>span");
  254. if(!dailySpan)return;
  255. var dailyCount=parseInt(dailySpan.innerHTML.replace(/[^\d\.\-]/g,""));
  256. var totalCount=parseInt(script.querySelector("dd.script-list-total-installs>span").innerHTML.replace(/[^\d]/g,""));
  257. var goodCount=parseInt(script.querySelector("dd.script-list-ratings>span>.good-rating-count").innerHTML.replace(/[^\d]/g,""));
  258. var okCount=parseInt(script.querySelector("dd.script-list-ratings>span>.ok-rating-count").innerHTML.replace(/[^\d]/g,""));
  259. var badCount=parseInt(script.querySelector("dd.script-list-ratings>span>.bad-rating-count").innerHTML.replace(/[^\d]/g,""));
  260. goodRating.innerHTML=parseInt(goodRating.innerHTML)+goodCount;
  261. okRating.innerHTML=parseInt(okRating.innerHTML)+okCount;
  262. badRating.innerHTML=parseInt(badRating.innerHTML)+badCount;
  263. totalInstalls.innerHTML=parseInt(totalInstalls.innerHTML)+totalCount;
  264. dailyInstalls.innerHTML=parseInt(dailyInstalls.innerHTML)+dailyCount;
  265. ratingSpan.style.display=totalInstalls.style.display=dailyInstalls.style.display="";
  266. }
  267.  
  268. GM_registerMenuCommand("Configure the Filter", ()=>{
  269. location.href="https://greatest.deepsurf.us/scripts/23840#additional-info";
  270. /*var _bullshit=window.prompt("Configure the Filter", bullshit);
  271. if(_bullshit == ""){
  272. bullshit=bullshit_o;
  273. storage.setItem("GeasyforkBullshit", bullshit);
  274. location.reload();
  275. }else if(_bullshit != null){
  276. bullshit=_bullshit;
  277. storage.setItem("GeasyforkBullshit", bullshit);
  278. location.reload();
  279. }*/
  280. });
  281. var sortDiv=document.querySelector("#script-list-sort"),refreshIcon=document.createElement("span"),inUserPage=document.querySelector("#user-script-list")!=null,goodRating,okRating,badRating,totalInstalls,dailyInstalls;
  282. refreshIcon.innerHTML=`<svg class="icon" style="width: 1em;height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2274"><path d="M981.314663 554.296783a681.276879 681.276879 0 0 1-46.986468 152.746388q-105.706098 230.734238-360.983096 242.19829a593.06288 593.06288 0 0 1-228.689008-33.853939v-1.022615l-31.808709 79.979258a55.759429 55.759429 0 0 1-20.506122 22.551352 40.043451 40.043451 0 0 1-21.04434 5.382184 51.076928 51.076928 0 0 1-19.483507-5.382184 95.210839 95.210839 0 0 1-13.347817-7.158305 52.314831 52.314831 0 0 1-5.382184-4.628679L71.671707 731.908862a57.427906 57.427906 0 0 1-7.158305-21.528737 46.932646 46.932646 0 0 1 1.022615-17.438277 35.952991 35.952991 0 0 1 7.158305-13.347816 74.435608 74.435608 0 0 1 10.279972-10.279972 60.495751 60.495751 0 0 1 11.248765-7.373593 50.431066 50.431066 0 0 1 8.18092-3.606063 6.189512 6.189512 0 0 0 3.067845-1.776121l281.003839-74.866183a91.497132 91.497132 0 0 1 35.899168-2.583448 122.337047 122.337047 0 0 1 22.174599 6.404799 21.528737 21.528737 0 0 1 12.325202 12.325202 76.157907 76.157907 0 0 1 4.628679 14.854829 47.63233 47.63233 0 0 1 0 14.370431 55.167388 55.167388 0 0 1-2.04523 10.764369 10.764368 10.764368 0 0 0-1.022615 3.606063l-32.831324 79.979258a677.50935 677.50935 0 0 0 164.264262 39.505232q77.395809 7.696523 131.809692-3.606063a358.507291 358.507291 0 0 0 101.023598-36.921784 381.27393 381.27393 0 0 0 73.951211-50.753997 352.64071 352.64071 0 0 0 48.708767-55.382676 410.391547 410.391547 0 0 0 26.910921-41.550462c3.767529-7.481236 6.673908-13.616926 8.719139-18.460892zM40.885614 449.667121a685.69027 685.69027 0 0 1 63.563595-176.427998q118.0313-212.273346 374.330913-207.160271a571.803252 571.803252 0 0 1 207.160271 39.989629l33.853939-78.956643A75.619688 75.619688 0 0 1 735.187378 9.189165a37.67529 37.67529 0 0 1 15.393047-8.234742 42.303968 42.303968 0 0 1 14.854829-0.538219 47.578509 47.578509 0 0 1 13.347817 3.606064 102.907362 102.907362 0 0 1 11.302586 6.13569 49.569917 49.569917 0 0 1 6.673909 4.628678l3.067845 3.067845 154.84544 276.913379a81.970666 81.970666 0 0 1 6.13569 22.712817 46.986468 46.986468 0 0 1-1.022615 17.438277 32.293105 32.293105 0 0 1-7.696523 13.347817 69.322533 69.322533 0 0 1-10.764369 9.741753 92.142994 92.142994 0 0 1-11.302587 6.673909l-8.18092 4.09046a7.104483 7.104483 0 0 1-3.067845 1.022615l-283.049068 67.546412a112.003254 112.003254 0 0 1-46.125319-1.022615c-11.571696-3.390776-19.160576-8.019454-22.551352-13.832214a41.173709 41.173709 0 0 1-5.382184-21.04434 97.256069 97.256069 0 0 1 1.291724-17.438277 24.381295 24.381295 0 0 1 3.067845-8.234742L600.632773 296.81309a663.730958 663.730958 0 0 0-164.102797-43.057474q-77.987849-9.203535-131.809692 0a348.227319 348.227319 0 0 0-101.292707 33.853938 368.571976 368.571976 0 0 0-75.350579 49.246986 383.31916 383.31916 0 0 0-50.269601 54.360061 408.507783 408.507783 0 0 0-28.740863 41.012244A113.025869 113.025869 0 0 0 40.885614 449.667121z m0 0" fill="#ffffff" p-id="2275"></path></svg>`;
  283. if(inUserPage){
  284. var ratingSpan=document.createElement("span");
  285. goodRating=document.createElement("span");
  286. okRating=document.createElement("span");
  287. badRating=document.createElement("span");
  288. totalInstalls=document.createElement("span");
  289. dailyInstalls=document.createElement("span");
  290. goodRating.className="good-rating-count";
  291. okRating.className="ok-rating-count";
  292. badRating.className="bad-rating-count";
  293. totalInstalls.className="good-rating-count";
  294. dailyInstalls.className="good-rating-count";
  295. ratingSpan.appendChild(goodRating);
  296. ratingSpan.appendChild(okRating);
  297. ratingSpan.appendChild(badRating);
  298. document.querySelector("#script-list-sort ul>li:nth-child(1)").appendChild(dailyInstalls);
  299. document.querySelector("#script-list-sort ul>li:nth-child(2)").appendChild(totalInstalls);
  300. document.querySelector("#script-list-sort ul>li:nth-child(3)").appendChild(ratingSpan);
  301. ratingSpan.style.display=totalInstalls.style.display=dailyInstalls.style.display="none";
  302. goodRating.innerHTML=okRating.innerHTML=badRating.innerHTML=totalInstalls.innerHTML=dailyInstalls.innerHTML="0";
  303. }
  304. if(sortDiv){
  305. var switchFilter=document.createElement("div"),enableFilter=!storage.getItem("disableFilter");
  306. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  307. var observer = new MutationObserver(function(records){
  308. records.map(function(record) {
  309. for(var i=0;i<record.addedNodes.length;i++){
  310. var curNode=record.addedNodes[i];
  311. if(curNode.className=="script-list"){
  312. var scripts=curNode.querySelectorAll('li');
  313. for(let i=0;i<scripts.length;i++){
  314. let script=scripts[i];
  315. addScore(script);
  316. }
  317. if(enableFilter)filter(curNode);
  318. }else if(curNode.tagName=="LI"){
  319. addScore(curNode);
  320. if(enableFilter)filter(curNode);
  321. }
  322. }
  323. });
  324. });
  325. var option = {
  326. 'childList': true
  327. };
  328. observer.observe(document.querySelector("body>.width-constraint .sidebarred-main-content"), option);
  329. var scriptList=document.querySelector("#browse-script-list,#user-script-list,ol.script-list");
  330. if(scriptList)observer.observe(scriptList, option);
  331. var scripts=document.querySelectorAll('ol.script-list>li');
  332. for(let i=0;i<scripts.length;i++){
  333. let script=scripts[i];
  334. addScore(script);
  335. }
  336. //Modify from GreasyFork Bullshit Filter,Thanks to darkred
  337. var style = document.createElement('style');
  338. style.textContent = `
  339. li.filtered {
  340. display: none !important;
  341. }
  342. .list-option{
  343. position: relative;
  344. }
  345. #script-list-sort li>span{
  346. position: absolute;
  347. top: 4px;
  348. right: 2px;
  349. pointer-events: none;
  350. font-weight: 500;
  351. }
  352. #script-list-sort li>span:lang(ar), #script-list-sort li>span:lang(he), #script-list-sort li>span:lang(ug){
  353. right: unset;
  354. left: 2px;
  355. }
  356. #script-list-sort li>span>span{
  357. margin: 0 0 0 2px;
  358. }
  359. .script-list>li .list-install-area{
  360. display: none;
  361. float: right;
  362. position: relative;
  363. }
  364. .script-list>li:hover .list-install-area {
  365. display: block;
  366. }
  367. @-webkit-keyframes spin {
  368. from {
  369. -webkit-transform: rotate(0deg);
  370. }
  371. to {
  372. -webkit-transform: rotate(360deg);
  373. }
  374. }
  375. @keyframes spin {
  376. from {
  377. transform: rotate(0deg);
  378. }
  379. to {
  380. transform: rotate(360deg);
  381. }
  382. }
  383. .refresh-info:hover>span {
  384. display: block;
  385. -webkit-animation: spin 1s linear 1s 5 alternate;
  386. animation: spin 1s linear infinite;
  387. }`;
  388. style.type = 'text/css';
  389. document.querySelector('head').appendChild(style);
  390. var bullshitReg=new RegExp(bullshit,"i");
  391. var filterName="Enable Filter",filteredNum=0;
  392. var filter=function(t){
  393. [].forEach.call(t.querySelectorAll('article>h2'), function(item) {
  394. if(bullshitReg.test(item.innerText.replace("\n"," "))){
  395. item.parentNode.parentNode.classList.add('filtered');
  396. filteredNum++;
  397. }
  398. });
  399. };
  400. if(enableFilter)filter(document);
  401. switchFilter.innerHTML='<input type="checkBox" name="switchFilter" id="switchFilter"/><label for="switchFilter">'+filterName+(filteredNum?' ('+filteredNum+' filtered)':'')+'</label>';
  402. var switchFilterCheckbox=switchFilter.querySelector('#switchFilter');
  403. var switchFilterLabel=switchFilterCheckbox.nextSibling;
  404. switchFilterCheckbox.checked=enableFilter;
  405. switchFilterCheckbox.onclick=function(){
  406. if(enableFilter){
  407. [].forEach.call(document.querySelectorAll('li.filtered'), function(item) {
  408. item.classList.remove('filtered');
  409. });
  410. switchFilterLabel.innerHTML=filterName;
  411. }else{
  412. filteredNum=0;
  413. filter(document);
  414. switchFilterLabel.innerHTML=filterName+' ('+filteredNum+' filtered)';
  415. }
  416. storage.setItem("disableFilter",enableFilter);
  417. enableFilter=!enableFilter;
  418. };
  419. sortDiv.insertBefore(switchFilter,sortDiv.firstChild);
  420. }
  421. })();