发表了专栏文章 ,快来看看吧!

· · 休闲·娱乐

upd on 2025/3/18:跳转到 luogu.me

写了一个插件,弥补专栏不能同步到犇犇的缺陷

效果应该不用我展示了吧(默认大家都是从犇犇过来的)

甚至可以帮忙转发别人的专栏

有 bug 可以评论或者私信发我

// ==UserScript==
// @name         luogu 专栏发送到犇犇
// @namespace    http://tampermonkey.net/
// @version      2024-05-10
// @description  向之前 blog 一样,将 luogu 专栏发送到犇犇
// @author       konyakest
// @match        https://www.luogu.com.cn/
// @match        https://www.luogu.com/article/*
// @match        https://www.luogu.com.cn/article/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// ==/UserScript==

async function postBenben(data){
    await fetch("https://www.luogu.com.cn/api/feed/postBenben", {
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
            "X-CSRF-Token": document.querySelector("meta[name=csrf-token]").content
        },
        "body": `content=${encodeURI(data)}`,
        "method": "POST"
    });
}

async function sleep(time){await new Promise(resolve => setTimeout(resolve, time));}

(async function(){
    await sleep(1000);
    if(location.href === "https://www.luogu.com.cn/"){
        let text = GM_getValue("text");
        console.log(text);
        if(!text){
            return;
        }
        GM_deleteValue("text");
        console.log("start post");
        await postBenben(text);
        console.log("post finished");
        return;
    }
    let but = document.createElement("button");
    but.className = "solid lform-size-middle";
    but.innerText = "转发到犇犇";
    but.style = "margin-left: 15px";
    but.onclick = function(){
        if(!confirm("确认要转发到犇犇吗?")){
            return;
        }
        let text = `> ${
            document.querySelector(".actions > a:nth-child(4) > div:nth-child(1)")? "":
            document.querySelector(".luogu-username").innerText
        } 发表了专栏文章 [${document.querySelector("#article-title").innerText}](${"https://www.luogu.me/article/"+location.href.split('/').pop()}) ,快来看看吧!`;
        text += '\n> \n';
        text += document.querySelector(".lfe-marked").innerText.split('\n').map(x=>`> ${x}`).join('\n');
        GM_setValue("text",text);
        console.log(GM_getValue("text"));
        window.open("https://www.luogu.com.cn/");
    };
    document.querySelector(".metas").appendChild(but);
})();