Empornium: Name to tag search

Takes marked text and searches empornium

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Empornium: Name to tag search
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Takes marked text and searches empornium
// @author       Your Name
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=empornium.is
// @grant        GM_registerMenuCommand
// @grant        GM_openInTab
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to process text
    function processSelectedText() {
        const selectedText = window.getSelection().toString();
        if (!selectedText) {
            alert("Please select some text before using this command.");
            return null;
        }
        let processedText = selectedText.trim().toLowerCase().replace(/\s+/g, '.');
        return encodeURIComponent(processedText);
    }

    // Navigate in current tab
    function navigateInCurrentTab() {
        const processedText = processSelectedText();
        if (processedText) {
            window.location.href = `https://www.empornium.is/torrents.php?order_by=seeders&order_way=desc&searchtext=&action=advanced&title=&sizeall=&sizetype=gb&sizerange=0.01&filelist=&taglist=${processedText}&autocomplete_toggle=on`;
        }
    }

    // Open in new tab
    function openInNewTab() {
        const processedText = processSelectedText();
        if (processedText) {
            GM_openInTab(`https://www.empornium.is/torrents.php?order_by=seeders&order_way=desc&searchtext=&action=advanced&title=&sizeall=&sizetype=gb&sizerange=0.01&filelist=&taglist=${processedText}&autocomplete_toggle=on`, true);
        }
    }

    // Register menu commands
    GM_registerMenuCommand("Emp (Ctrl+Alt+C)", navigateInCurrentTab, 'c');
    GM_registerMenuCommand("Emp in New Tab (Ctrl+Alt+N)", openInNewTab, 'n');

    // Add keyboard shortcuts
    document.addEventListener('keydown', function(e) {
        if (e.ctrlKey && e.altKey && e.code === 'KeyN') {
            e.preventDefault();
            openInNewTab();
        } else if (e.ctrlKey && e.altKey && e.code === 'KeyC') {
            e.preventDefault();
            navigateInCurrentTab();
        }
    });
})();