TKOR Enhanced

Enhanced user experience for toonkor

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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;
        }
    }
})();