// ==UserScript==
// @name The Pirate Bay Cleaner
// @description Release 2024 Build 1
// @author BoKu
// @version 2024.1
// @namespace https://greasyfork.org/scripts/1573-the-pirate-bay-cleaner
// @icon https://i.imgur.com/jsBhOii.gif
// @license The Pirate Bay Cleaner is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
// @match *://thepiratebay.org/*
// @noframes
// @run-at document-body
// @resource bootstrapCss https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css#sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH
// @require https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js#sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.openInTab
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant unsafeWindow
// @downloadURL https://update.greasyfork.icu/scripts/1573/The%20Pirate%20Bay%20Cleaner.user.js
// @updateURL https://update.greasyfork.icu/scripts/1573/The%20Pirate%20Bay%20Cleaner.meta.js
// ==/UserScript==
"use strict";window.stop();const bootstrapCss=GM_getResourceText("bootstrapCss");GM_addStyle(bootstrapCss);const tpb=unsafeWindow,tpbApi="https://apibay.org",tpbServer="https://torrindex.net",FixJsRedirect=t=>{if(console.debug(`FixJsRedirect: ${t}`),GM.setValue("FixJsRedirect",!0),(!0===t||!1===t)&&"thepiratebay.org"==tpb.location.hostname&&"/browse.php"!=tpb.location.pathname){let t=tpb.location.origin+"/browse.php";tpb.location.href=t}},guiAccent="success",NewGui=async(t,e)=>{console.debug(`NewGui: ${t}`),GM.setValue("NewGui",t),console.debug(`NewGuiDarkmode: ${e}`),GM.setValue("NewGuiDarkmode",e);const a=await GM.getValue("RemovePorn",!0)?"d-none":"",o=e?"dark":"light";if(!0===t){const t=document.getElementsByTagName("html")[0];t.setAttribute("data-bs-theme",`${o}`),t.style.scrollbarColor=e?"var(--bs-success) #212529":"auto";document.getElementsByTagName("body")[0].remove();const n=document.getElementsByTagName("head")[0],s=document.createElement("style");s.setAttribute("id","tpbcStyle"),s.append("\n a, a:link, a:visited, a:focus {border-bottom:initial; color: initial}\n a:hover {--bs-link-color-rgb: var(--bs-link-hover-color-rgb);} .nav-link:focus, .nav-link:hover {color: var(--bs-nav-link-hover-color);}\n .bi::before {display: inline-block; content: \"\"; vertical-align: -.125em; background-repeat: no-repeat; background-size: 1rem 1rem;} .bi{display:inline-block;vertical-align: -.125em; width: 1em; height: 1em;}\n .form-check-input:checked {background-color: var(--bs-success); border-color: var(--bs-success);}\n .form-check-input:focus, .form-control:focus {border-color: var(--bs-success); box-shadow: 0 0 0 .25rem rgba(var(--bs-success-rgb),.25);}\n .form-switch .form-check-input:focus {background-image: url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill=\"%23ffffff\" xfill='%23db8790' /%3e%3c/svg%3e\");}\n .skull-trusted{color:#ff00ff;} .skull-vip{color:#04ec04;} .skull-helper{color:#0000ff;} .no-pointer-event{pointer-events: none;}\n .pagination { --bs-pagination-active-bg: var(--bs-success); --bs-pagination-active-border-color: var(--bs-success);}\n .shake { -webkit-animation: kf_shake 0.4s 1 linear; -moz-animation: kf_shake 0.4s 1 linear; -o-animation: kf_shake 0.4s 1 linear;}\n\t\t @-webkit-keyframes kf_shake { 0% { -webkit-transform: translate(8px); } 20% { -webkit-transform: translate(-8px); } 40% { -webkit-transform: translate(4px);}\n 60% { -webkit-transform: translate(-4px); } 80% { -webkit-transform: translate(2px); }100% {-webkit-transform: translate(0px);}}\n .fixed-bottom-left {position:fixed; bottom:10px; left:10px; opacity: 0; transition: opacity 0.4s}\n "),n.append(s);const r=document.createElement("body");r.setAttribute("id","tpbcBody"),r.classList.add(`bg-${o}`),r.style="padding-top: 3.5rem; scroll-behavior: smooth;";const l=document.createElement("nav");l.classList.add("navbar","navbar-expand-md","fixed-top","border-bottom",`bg-${o}`),l.innerHTML=`\n
\n
The Pirate Bay Cleaner \n
\n \n \n
\n
`,r.append(l);const i=document.createElement("main");i.classList.add("container-fluid","p-2",`bg-${o}`),i.style=`min-height: 311px; /*background: url("${tpbServer}/images/tpb.jpg") no-repeat top center*/; background-blend-mode: multiply; background-position-y: center;`;const c=document.createElement("div");c.classList.add("container-fluid","py-2"),c.innerHTML=`\n \n
\n
\n
BROWSE TORRENTS \n
\n\n
\n\n
\n
\n Application \n
\n \n
\n\n
\n\n
\n\n
\n\n
\n\n
\n
\n
\n
\n
\n
`,i.append(c),r.append(i),r.innerHTML+='\n \n \n
\n \n \n
\n ';let d=await GM.getValue("ShrinkDescription",!0)?"":"show";let p=await GM.getValue("ShrinkFileList",!0)?"":"show";r.innerHTML+=`\n \n \n `,r.innerHTML+=' Top ',t.append(r),loadSettings(),await getData("top100:recent");document.querySelectorAll('[data-tpbc="form"]').forEach((t=>{t.addEventListener("submit",(t=>{t.preventDefault(),getData(`search:${t.target[0].value.trim()}`)}))}));document.querySelectorAll('[data-tpbc="button"]').forEach((t=>{t.addEventListener("click",(async t=>{t.preventDefault(),t.target.dataset.cat,setActiveMenu(t.target),await getData(t.target.dataset.cat)}))}));document.querySelectorAll('[data-tpbc="saveSettings"]').forEach((t=>{t.addEventListener("click",(t=>{t.preventDefault(),setTimeout((()=>{location.reload()}),300)}))}));document.querySelectorAll('[data-tpbc="a"]').forEach((t=>{t.addEventListener("click",(async e=>{e.preventDefault();const a=e.target.attributes.href.value;if("refresh"===a)location.reload();else setActiveMenu(t),await getData(a.split("=")[1])}))}))}window.onscroll=function(){var t=window.pageYOffset||document.documentElement.scrollTop,e=document.getElementById("scrollButton");e.style.opacity=t>0?"1":"0"},document.getElementById("scrollButton").addEventListener("click",(function(){window.scrollTo({top:0,behavior:"smooth"})}))},setActiveMenu=async(t=!1)=>new Promise((e=>{t||e(!1);try{const t=document.querySelectorAll('a[class~="nav-link"]');for(let e=0;enew Promise((a=>{try{const o=document.getElementById("tpbcContent");0===e?o.innerHTML=t:o.innerHTML+=t,a(!0)}catch{a(!1)}})),formatBytes=async(t,e)=>new Promise((a=>{0==t&&a("0 Bytes");let o=e||2,n=Math.floor(Math.log(t)/Math.log(1024));a(parseFloat((t/Math.pow(1024,n)).toFixed(o))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][n])})),getIcon=async t=>new Promise((e=>{let a=t;switch(t=parseInt(t)||t){case 100:a="Audio";break;case 101:a="Music - Audio";break;case 199:a="Other - Audio";break;case 200:a="Video";break;case 201:a="Movie - Video";break;case 202:a="Movie DVDR - Video";break;case 203:a="Music - Video";break;case 204:a="Movie Clip - Video";break;case 206:a="Handheld - Video";break;case 207:a="HD Movie - Video";break;case 208:a="HD TV Shows - Video";break;case 211:a="UHD/4k Movie - Video";break;case 212:a="UHD/4k TV Shows - Video";break;case 300:a="Applications";break;case 301:a="Windows - Application";break;case 302:a="Mac - Application";break;case 303:a="UNIX - Application";break;case 304:a="Handheld - Application";break;case 305:a="iOS (iPad/iPhone) - Application";break;case 306:a="Android - Application";break;case 399:a="Other - Application";break;case 400:a="Games";break;case 401:a="PC - Game";break;case 402:a="Mac - Game";break;case 403:a="PSx - Game";break;case 404:a="XBOX360 - Game";break;case 405:a="Wii - Game";break;case 406:a="Handheld - Game";break;case 407:a="iOS (iPad/iPhone) - Game";break;case 408:a="Android - Game";break;case 499:a="Other - Game";break;case 500:a="Porn";break;case 501:a="Movie - Porn";break;case 502:a="Movie DVDR - Porn";break;case 503:a="Pictures - Porn";break;case 504:a="Games - Porn";break;case 505:a="HD Movie - Porn";break;case 506:a="Movie Clips - Porn";break;case 507:a="UHD/4k Movie - Porn";break;case 599:a="Other - Porn";break;case 600:a="Other";break;case 601:a="eBooks - Other";break;case 602:a="Comics - Other";break;case 603:a="Pictures - Other";break;case 604:a="Covers - Other";break;case 605:a="Physibles - Other";break;case 699:a="Other - Other"}switch(!0){case 102==t:e('Book - Audio ');break;case 103==t:e('Sound Clip - Audio ');break;case 104==t:e('FLAC - Audio ');break;case 205==t:e('TV Show - Video ');break;case 207==t:case 208==t:case 505==t:e(`${a} `);break;case 209==t:e('3D - Video ');break;case 211==t:case 212==t:case 507==t:e(`${a} `);break;case 302==t:case 305==t:case 402==t:case 407==t:e(`${a} `);break;case 306==t:case 408==t:e(`${a} `);break;case 601==t:case 602==t:e(`${a} `);break;case 503==t:case 603==t:case 604==t:e(`${a} `);break;case 605==t:e(`${a} `);break;case 699==t:e(`${a} `);break;case 99999==t:e("");break;case t>=100&&t<200:e(`${a} `);break;case t>=200&&t<300:e(`${a} `);break;case t>=300&&t<400:e(`${a} `);break;case t>=400&&t<500:case 504==t:e(`${a} `);break;case t>=500&&t<600:e(`${a} `);break;case t>=600&&t<700:e(`${a} `);break;case"trusted"==t||"vip"==t||"helper"==t:e(`${a} \n \n \n \n \n `);break;case"moderator"==t:e(` `);break;case"supermod"==t:e(` `);break;case"truadminsted"==t:e(` `);break;case"imdb"==t:e('\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ');break;case"magnet"==t:e('\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ');break;default:e("")}})),filterList=()=>{let t,e,a,o,n,s,r,l,i,c,d,p,b,h,u,g,m,w,v,f,y,C=1;for(r="",l=document.getElementById("720p").checked?"720P":"",i=document.getElementById("1080p").checked?"1080P":"",c=document.getElementById("2160p").checked?"2160P":"",d=document.getElementById("x264").checked?"X264":"",p=document.getElementById("h264").checked?"H264":"",b=document.getElementById("x265").checked?"X265":"",h=document.getElementById("h265").checked?"H265":"",u=document.getElementById("HDR").checked?"HDR ":"",g=document.getElementById("HEVC").checked?"HEVC":"",m=document.getElementById("WEBRip").checked?"WEBRIP":"",w=document.getElementById("BluRay").checked?"BLURAY":"",0==l.length&&0==i.length&&0==c.length&&0==d.length&&0==p.length&&0==b.length&&0==h.length&&0==u.length&&0==g.length&&0==m.length&&0==w.length&&(C=0),t=document.getElementById("tpbc-flist"),e=t.value.toUpperCase(),a=document.getElementsByClassName("d-table-row"),n=0;n0&&-1!==s.indexOf(l,0)&&(f=1),i.length>0&&-1!==s.indexOf(i,0)&&(f=1),c.length>0&&-1!==s.indexOf(c,0)&&(f=1),d.length>0&&-1!==s.indexOf(d,0)&&(f=1),p.length>0&&-1!==s.indexOf(p,0)&&(f=1),b.length>0&&-1!==s.indexOf(b,0)&&(f=1),h.length>0&&-1!==s.indexOf(h,0)&&(f=1),u.length>0&&-1!==s.indexOf(u,0)&&(f=1),g.length>0&&-1!==s.indexOf(g,0)&&(f=1),m.length>0&&-1!==s.indexOf(m,0)&&(f=1),w.length>0&&-1!==s.indexOf(w,0)&&(f=1)):f=1,s.indexOf(e)>-1&&(v=1),1==f&&1==v?a[n].classList.remove("d-none"):a[n].classList.add("d-none")},tpbcSort=(t,e)=>{if(0==e)return;const a=(t,a)=>4==e?t.children[a].dataset.tpbcTEpoch:5==e?t.children[a].dataset.tpbcTSize:t.children[a].innerText||t.children[a].textContent,o=t.target,n=o.closest("table").querySelector("tbody");var s,r;Array.from(n.querySelectorAll("tr")).sort((s=Array.from(o.parentElement.children).indexOf(o),r=this.asc=!this.asc,(t,e)=>{return o=a(r?t:e,s),n=a(r?e:t,s),""===o||""===n||isNaN(o)||isNaN(n)?o.toString().localeCompare(n):o-n;var o,n})).forEach((t=>n.appendChild(t)))},makeXXX=()=>{const t=document.createElement("a");t.alt="Porn",t.title="Porn",t.setAttribute("role","button"),t.href="#PornNotify";return t.innerHTML=' ',t.addEventListener("click",(t=>{t.preventDefault()})),t},makeIMDb=t=>{if(null===t)return;const e=document.createElement("a");e.href=`https://www.imdb.com/title/${t}/`,e.target="_blank",e.alt="IMDb",e.title="IMDb";return e.innerHTML='\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ',e},makeMagnet=(t,e)=>{if(null===t)return;const a=document.createElement("a");a.classList.add("ms-1"),a.href=`magnet:?xt=urn:btih:${t}&dn=${e}%20-%20Powered%20by%20The%20Pirate%20Bay%20Cleaner&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.bittor.pw%3A1337%2Fannounce&tr=udp%3A%2F%2Fpublic.popcorn-tracker.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.dler.org%3A6969%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce`,a.alt="Download",a.title="Download";return a.innerHTML='\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ',a.addEventListener("click",(t=>{(async()=>{if(!0===await GM.getValue("RememberDownloaded",!0)){const e=t.target.closest("tr"),a=e.dataset.tpbcTInfohash,o=await GM.getValue("DownloadedTorrents","[]");let n=JSON.parse(o);n.push(a),n=[...new Set(n)],await GM.setValue("DownloadedTorrents",`${JSON.stringify(n)}`),e.classList.add("text-decoration-line-through"),console.debug(a,n)}})()})),a},pingTPB=async()=>new Promise((t=>{(async()=>{const e=await fetch("https://thepiratebay.org/browse.php");e.status>=200&&e.status<400?t(JSON.parse(`{"siteDown": false, "status": ${e.status} }`)):t(JSON.parse(`{"siteDown": true, "status": ${e.status} }`))})()})),getData=async(t,e=!1)=>{const a=window.event,o=t.split(":");let n=o[0]||o,s=o[1]||0,r=document.getElementById("h2")||"";try{r=r.textContent.trim().replace(" Torrents","")}catch{}let l,i=o[2]||void 0,c="",d="",p="",b="",h=Number(s.split("_")[1]||-1);console.debug("getData:",n,s,i,h);const u=await pingTPB();if(u.siteDown){document.title="The Pirate Bay Cleaner :: OFFLINE";const t=300;d=' ',p="The Pirate Bay is Currently Offline",await setContent(`${d} ${p} `,0),await setContent(`Rechecking in ${t} seconds.
`,1);const e=document.querySelectorAll("form, button.btn, a.nav-link, input");for(let t=0;t{o>=0?a.textContent=o--:location.reload()}),1e3)}switch(b=a.isTrusted?a.target.textContent:r,n){case"top100":switch(!0){case"recent"==s:i="0"===i||void 0===i?"":`_${i}`,c=`${tpbApi}/precompiled/data_${n}_${s}${i}.json`,i=i.replace(/\D/g,""),p="Recent Torrents",d=' ';break;case s.startsWith("48h"):p=`${b} Torrents`,c=`${tpbApi}/precompiled/data_top100_${s}.json`,d=' ';break;default:p=`${b} Torrents`,c=`${tpbApi}/precompiled/data_top100_${s}.json`,d=' '}break;case"category":switch(i=i||0,c=`${tpbApi}/q.php?q=${n}%3A${s}%3A${i}`,p=`${b} Torrents`,s){case"100":case"101":case"102":case"103":case"104":case"199":d=' ';break;case"200":case"201":case"202":case"203":case"204":case"205":case"206":case"207":case"208":case"209":case"210":case"211":case"212":case"299":d=' ';break;case"300":case"301":case"302":case"303":case"304":case"305":case"306":case"399":d=' ';break;case"400":case"401":case"402":case"403":case"404":case"405":case"406":case"407":case"408":case"499":d=' ';break;case"500":case"501":case"502":case"503":case"504":case"505":case"506":case"507":case"599":d=' ';break;case"600":case"601":case"602":case"603":case"604":case"605":case"699":d=' ';break;default:d=' '}break;case"user":i=i||0,p=`User: ${s} Torrents`,c=`${tpbApi}/q.php?q=${n}%3A${s}%3A${i}`,d=' ';break;case"search":p=`Results for: ${s}`,c=`${tpbApi}/q.php?cat=0&q=${s}`,d=' '}await setContent(`${d} ${p} `,0),await setContent('',1),await setContent('\n \n \n Name \n \n Se \n Le \n Uploaded \n Size \n Uploader \n \n ',1),await setContent('',1);const g=await fetch(c,{cache:"no-cache"}),m=await g.text();l=m.includes("Database maintenance")?await JSON.parse(`[{"id": "0","name": "${m}","info_hash": "0000000000000000000000000000000000000000","leechers": "0","seeders": "0","num_files": "0","size": "0","username": "","added": "0","status": "member","category": "0","imdb": "","total_found": "1"}]`):await JSON.parse(m),console.debug(l);const w=await document.getElementById("tpbcList");for(let t=0;t=500&&l[t].category<600)&&(!0!==await GM.getValue("RemoveZeroSeeds",!0)||!Number(0===l[t].seeders))&&(!0!==await GM.getValue("RemoveUntrusted",!0)||"member"!=l[t].status);++t){if(!0===await GM.getValue("HideUploader",!1)){const e=(await GM.getValue("HideUploader_List","")).split(",").filter((t=>t)).map((t=>t.trim().toLowerCase())),a=[...new Set(e)],o=l[t].username.toLowerCase();if(a.includes(o)){console.debug("HideUploader",a,o);break}}if(!0===await GM.getValue("KeywordFilter",!1)){const e=(await GM.getValue("KeywordFilter_List","")).split(",").filter((t=>t)).map((t=>t.trim().toLowerCase())),a=[...new Set(e)],o=l[t].name.toLowerCase();if(a.some((t=>o.includes(t))))break}if(!0===await GM.getValue("KeywordKeeper",!1)){const e=(await GM.getValue("KeywordKeeper_List","")).split(",").filter((t=>t)).map((t=>t.trim().toUpperCase())),a=[...new Set(e)],o=l[t].name.toUpperCase();if(!a.some((t=>o.includes(t))))break}let e="";try{if(!0===await GM.getValue("RememberDownloaded",!0)){const a=await GM.getValue("DownloadedTorrents","[]"),o=JSON.parse(a),n=l[t].info_hash;o.includes(n)&&(e="text-decoration-line-through")}}catch{}const a=await getIcon(l[t].category)||"",o=document.createElement("svg");o.innerHTML=a;const n=o.querySelector("svg > svg > title")||"",s=await formatBytes(l[t].size)||"",r=await getIcon(l[t].status)||"",i=(null==l[t].imdb||l[t].imdb,Number(l[t].category));let c="";!isNaN(i)&&i>=500&&i<600&&(c="data-tpbc-t-porn"),w.innerHTML+=`\n \n ${a} \n ${l[t].name.trim()} \n \n ${l[t].seeders} \n ${l[t].leechers} \n ${new Date(1e3*l[t].added).toLocaleString(void 0,{day:"2-digit",month:"2-digit",year:"numeric"})} \n ${s} \n ${r}${l[t].username} \n `}await setContent("
",1);if(document.querySelectorAll("tr[data-tpbc-t-porn]").forEach((t=>{const e=t.children[1],a=makeXXX();e.append(a)})),!0===await GM.getValue("AddIMDBIcon",!1)){document.querySelectorAll('tr[data-tpbc-t-imdb^="tt"]').forEach((t=>{const e=t.children[2],a=t.getAttribute("data-tpbc-t-imdb"),o=makeIMDb(a);e.append(o)}))}if(document.querySelectorAll("tr[data-tpbc-t-infohash]").forEach((t=>{const e=t.getAttribute("data-tpbc-t-infohash");if("0000000000000000000000000000000000000000"==e)return;const a=t.children[2],o=t.children[1].textContent,n=makeMagnet(e,o);a.append(n)})),void 0!==i){await setContent('\n \n ",1);if(document.querySelectorAll('[data-tpbc="page"]').forEach((t=>{t.addEventListener("click",(t=>{t.preventDefault();let e=t.target.href;e=e.split("=")[1],console.debug(e),getData(e)}))})),0===w.children.length){const t=document.querySelector('a[data-tpbc="page"].active').parentElement.nextSibling.firstChild;if("29"!==t.textContent)return void t.click()}}const v=document.querySelectorAll('span[role="button"].torrent'),f=document.getElementById("torInfoMod");v.forEach((t=>{t.addEventListener("click",(async t=>{const e=t.target.closest("tr").dataset.tpbcTId;if("0"==e)return void t.preventDefault();const a=await fetch(`${tpbApi}/t.php?id=${e}`),o=await a.text(),n=await JSON.parse(o),s=await fetch(`${tpbApi}/f.php?id=${e}`),r=await s.text(),l=await JSON.parse(r);f.getElementsByTagName("h1")[0].textContent=n.name,document.getElementById("collapseInfo").children[0].innerHTML=n.descr;const i=document.querySelector('ul[class~="list-group-flush"]');let c=1;for(let t in l){let e="Filelist not found",a="0 bytes";l[t].name.length+l[t].name.length>0&&(e=l[t].name,a=await formatBytes(l[t].size)),i.innerHTML+=`${c}. ${e} \n ${a} `,c++}}))})),f.addEventListener("hide.bs.modal",(t=>{f.getElementsByTagName("h1")[0].innerHTML='
Loading... ',document.getElementById("collapseInfo").children[0].innerHTML="",document.getElementById("collapseFiles").children[0].children[0].innerHTML=""}));const y=document.getElementById("tpbcFilter"),C=document.createElement("input");C.classList.add("form-control","form-control-sm"),C.placeholder="Filter names...",C.setAttribute("spellcheck","false"),C.id="tpbc-flist",C.type="text",C.dataset.tpbc="filter",C.addEventListener("keyup",(t=>{t.preventDefault(),filterList()}));const k=["720p","1080p","2160p","x264","h264","x265","h265","WEBRip","BluRay","HDR","HEVC"];for(let t=0;t{filterList()})),e.append(a),e.append(o),y.children[0].append(C),y.children[1].append(e)}const M=document.getElementsByTagName("th");for(let t=0;t{tpbcSort(e,t)}));document.querySelectorAll('[data-tpbc="uploader"]').forEach((t=>{t.addEventListener("click",(t=>{t.preventDefault();const e=t.target.innerText;if("anonymous"===e.toLowerCase())return t.target.classList.add("shake"),void setTimeout((()=>{t.target.classList.remove("shake")}),400);getData(`user:${e}`)}))}));const x=await document.getElementById("tpbcLoader");return x&&x.remove(),!0},EffectiveSetting=async(t,e,a)=>{const o=document.getElementsByClassName("modal-body")[0];GM.setValue(`${t}`,e);const n=document.createElement("div");n.classList.add("form-check","form-switch");const s=document.createElement("input");s.classList.add("form-check-input"),s.type="checkbox",s.id=`cb${t}`,s.setAttribute("role","switch"),e&&s.setAttribute("checked","checked"),s.addEventListener("click",(e=>{GM.setValue(`${t}`,e.target.checked)}));const r=document.createElement("label");if(r.classList.add="form-check-label",r.setAttribute("for",`cb${t}`),r.innerHTML=`${a}`,n.append(s,r),o.append(n),["HideUploader","KeywordFilter","KeywordKeeper"].includes(t)){const e=document.createElement("div"),a=document.createElement("textarea");a.classList.add("form-control","mb-3"),a.setAttribute("rows","3"),a.setAttribute("spellcheck","false"),a.placeholder="Using this feature may slow down page load times, use with caution.";const n=await GM.getValue(`${t}_List`,"");a.textContent=n,a.addEventListener("keyup",(e=>{const a=e.target.value.trim();console.debug(a),GM.setValue(`${t}_List`,a)})),e.append(a),o.append(e)}},loadSettings=async()=>{await EffectiveSetting("RemoveUntrusted",await GM.getValue("RemoveUntrusted",!0),"Remove untrusted users (i.e. users without a trusted skull etc.)"),await EffectiveSetting("RemoveZeroSeeds",await GM.getValue("RemoveZeroSeeds",!0),"Remove torrents that have zero seeds."),await EffectiveSetting("ShrinkDescription",await GM.getValue("ShrinkDescription",!0),"Shrink (Hide/Show) the torrent description box."),await EffectiveSetting("ShrinkFileList",await GM.getValue("ShrinkFileList",!0),"Shrink (Hide/Show) the file list below the description box."),await EffectiveSetting("RememberDownloaded",await GM.getValue("RememberDownloaded",!0),"Strike-out example previously downloaded torrents (when magnet link clicked)"),await EffectiveSetting("RemovePorn",await GM.getValue("RemovePorn",!0),"Remove adult material (i.e. Porn, XXX, etc.)"),await EffectiveSetting("AddIMDBIcon",await GM.getValue("AddIMDBIcon",!1),`Add an icon that links to the IMDB page. ${await getIcon("imdb")}`),await EffectiveSetting("HideUploader",await GM.getValue("HideUploader",!1),"Remove users that you don't like torrents from (e.g. aXXo, YIFY, Anonymous etc.)"),await EffectiveSetting("KeywordFilter",await GM.getValue("KeywordFilter",!1),"Remove torrents that contain certain words (e.g. 480p, DVD, .TS. etc.)"),await EffectiveSetting("KeywordKeeper",await GM.getValue("KeywordKeeper",!1),"Keep torrents that contain certain words (e.g. 1080p, 720p, WEB etc.)")},ThePirateBayCleaner=()=>{console.debug("Loading The Pirate Bay Cleaner"),document.title="The Pirate Bay Cleaner",(async()=>{FixJsRedirect(await GM.getValue("FixJsRedirect",!0)),await GM.getValue("DownloadedTorrents",!1)||await GM.setValue("DownloadedTorrents","[]"),!0===await GM.getValue("NewGui",!0)&&await NewGui(await GM.getValue("NewGui",!0),await GM.getValue("NewGuiDarkmode",!0))})()};ThePirateBayCleaner();