Greasy Fork

来自缓存

Greasy Fork is available in English.

知识星球自动点赞脚本

知识星球自动化点赞,解放双手!

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         知识星球自动点赞脚本
// @namespace    https://github.com/CC11001100/ZhiShiXingQiu-Bang
// @version      0.3
// @description  知识星球自动化点赞,解放双手!
// @author       CC11001100
// @match       *://*/*
// @grant        none
// ==/UserScript==
(async () => {

    let bangCount = 0;
    let c = 5;
    while (true) {
        try {
            const bangElementList = document.querySelectorAll("div[title=点赞]");
            for (let bangElement of bangElementList) {
                if (bangElement.getAttribute("class") !== "like") {
                    continue;
                }
                // https://developer.mozilla.org/zh-CN/docs/Web/API/Element/scrollIntoView
                bangElement.scrollIntoView({behavior: "smooth", block: "center", inline: "center"});
                await sleep(500);
                bangElement.click();
                await sleep(500)
                bangCount++;
            }

            // 滚动到没有内容时的标记,为了防止网速慢到石化,退出时多给点机会
            if (document.querySelector(".no-more") !== null) {
                c--;
                await sleep(1000);
                if (c <= 0) {
                    break;
                }
            }

            await scrollToBottom();
        } catch (e) {
            alert("哦豁完蛋,报错了: " + e.message)
        }
        await sleep(1000);
    }
    alert(`点赞完成,本次共点赞${bangCount}条动态!`);

    async function sleep(mils) {
        return new Promise((resolve) => setTimeout(resolve, mils));
    }

    async function scrollToBottom() {
        // https://developer.mozilla.org/zh-CN/docs/Web/API/Window/scrollTo
        window.scrollTo({
            top: document.body.scrollHeight,
            behavior: "smooth"
        });
        await sleep(100);
        window.scrollTo({
            top: document.body.scrollHeight - 300,
            behavior: "smooth"
        });
        await sleep(100);
        window.scrollTo({
            top: document.body.scrollHeight,
            behavior: "smooth"
        });
    }

})();