TKOR Enhanced

Enhanced user experience for toonkor

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TKOR Enhanced
// @author       Minjae Kim
// @version      1.07
// @description  Enhanced user experience for toonkor
// @match        https://tkor1*.com/*
// @grant        none
// @include      /^https?:\/\/(?:www\.)?tkor\d{3}\.com\/.*/
// @icon         https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRjf9ah_nrpbeAvtWWj4SspQhTCY_-bikwFswNoO-ovMA&s=10
// @license      MIT
// @run-at       document-start
// @namespace    https://greasyfork.org/en/users/1529082-minjae-kim
// ==/UserScript==
(function () {
  'use strict';
    //adblock css
    function adblock(){
        const css = `
            #mobile_nav,
            .navbar.navbar-default.navbar-static-top,
            .col-md-12.mobile-banner,
            #banner_21_img,
            .bn.bnt,
            #nad
            {
                display: none !important;
            }
        `;
        if (typeof GM_addStyle !== 'undefined') {
            GM_addStyle(css);
        } else {
            const style = document.createElement('style');
            style.textContent = css;
            document.head.append(style);
        }
    }
    
    //add search box
    function searchboxInsert() {
        const targetElement = document.querySelector('#bo_list_total');
        if (targetElement) {
            const searchBoxHTML = `
                <div class="custom-search-wrapper" style="display: inline-block; margin-left: 10px;">
                    <input type="search" id="custom-search" placeholder="Search..." style="padding: 5px 10px; border: 1px solid #ccc; border-radius: 4px;">
                    <button id="custom-search-btn" style="padding: 5px 10px; cursor: pointer;">Go</button>
                </div>
            `;
            targetElement.insertAdjacentHTML('afterend', searchBoxHTML);
                const performSearch = () => {
                    const query = document.getElementById('custom-search').value;
                    if (query) {
                        window.location.href = `/bbs/search.php?sfl=wr_subject%7C%7Cwr_content&stx=${encodeURIComponent(query)}`;
                    }
                };
                document.getElementById('custom-search-btn').addEventListener('click', performSearch);
                document.getElementById('custom-search').addEventListener('keydown', (event) => {
                    if (event.key === 'Enter') {
                        event.preventDefault();
                        performSearch();
                    }
                });
        }
    }

    function runIdleTasks() {
        console.log("[Userscript] Browser is idle. Running background tasks...");

        // Heavy operations (e.g., scraping, analytics, loading large external libraries)
        performHeavyLifting();
        adblock();
        searchboxInsert();
    }

    // Schedule the idle tasks safely
    if ('requestIdleCallback' in window) {
        requestIdleCallback(runIdleTasks, { timeout: 2000 });
        // Note: 'timeout' ensures it runs within 2 seconds even if the browser is busy
    } else {
        // Fallback for older browsers or Safari (which lacks full support)
        window.addEventListener('load', () => {
            setTimeout(runIdleTasks, 1);
        });
    }

    //goto recent url number
    function performHeavyLifting() {
        const numberPart = location.hostname.match(/\d+/)[0];
        console.log(numberPart);
        
        const number = Number(numberPart)+1;
        const error = document.querySelector("#cf-error-details");
        const error2 = document.querySelector("#body_sec");
        if(error){
            const newUrl = `https://tkor${number}.com${window.location.pathname}`;
            window.location.href = newUrl;
            console.log("error1");
            return;
        }
        else if (!error2){
            const newUrl = `https://tkor${number}.com${window.location.pathname}`;
            window.location.href = newUrl;
            console.log("error2");
            return;
        }
        else {
            console.log("noError");
            return;
        }
    }
})();