המשרתת של ניב

מנקה אשכולות של אתגרים שבועיים בקלות ובמהירות

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         המשרתת של ניב
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  מנקה אשכולות של אתגרים שבועיים בקלות ובמהירות
// @author       Muffin24
// @match        https://www.fxp.co.il/forumdisplay.php?f=*
// @grant        none
// ==/UserScript==
if (!/^(?!ארכיון).*הפרסות|אתגרים.*$/.test(window.forumname)) {
    return;
}
const selector = typeof ISMOBILEFXP !== 'undefined' ? 'breadcrumb' : 'above_threadlist';
const regex = /https:\/\/www\.fxp\.co\.il\/showthread\.php\?t=\d+/;
const link = document.createElement("a");
link.innerText = "ניקוי אשכולות נעולים";
link.className = "newcontent_textcontrol";
link.style.width = "140px";
link.addEventListener('click', async function () {
    const mergethreadurl = prompt("קישור לאשכול הניקוי של האתגרים השבועיים");
    if (!regex.test(mergethreadurl)) {
        return;
    }
    //TODO: remove or update dom | maybe regex
    const res = await (await fetch('https://www.fxp.co.il/modcp/antispam.php')).text();
    const doc = new DOMParser().parseFromString(res, 'text/html')
    if (!doc.querySelector('table').innerText.includes('לא נבחר משתמש')) {
        location.href = 'https://www.fxp.co.il/modcp/antispam.php';
        return alert("אנא התחבר למשתמש ונסה שוב לאחר ההתחברות");
    }
    //
    const threads = document.querySelectorAll('#threads > li.lock');
    for (const thread of threads) {
        const threadid = thread.id.split('_').at(1);
        const response = await fetch(`https://www.fxp.co.il/showthread.php?t=${threadid}&pp=40`);
        const html = await response.text();
        //TODO: regex or improve selector
        const doc = new DOMParser().parseFromString(res, 'text/html')
        const posts = [...doc.querySelectorAll('.postbit')].shift().map(post => {
            if (post.querySelector('.postbody_unposted')) {
                return;
            }
            return post.id.split('_')[1]
        })
        //
        fetch("https://www.fxp.co.il/inlinemod.php", {
            headers: {
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
            },
            method: "POST",
            body: new URLSearchParams({
                securitytoken: window.SECURITYTOKEN,
                postids: posts.join(','),
                t: threadid,
                do: "domoveposts",
                type: 1,
                mergethreadurl
            })
        })
            .then(_ => {
            alert('כל האשכולות הנעולים נוקו בהצלחה');
        })
            .catch(error => {
            alert('אופס משום מה ניב לא הצליח לבצע את הניקוי כמו שצריך ):');
            console.log('error', error);
        })
            .finally(location.reload)
    }
})
document.getElementById(selector).after(link);