TKOR Enhanced

Enhanced user experience for toonkor

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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;
        }
    }
})();