Greasy Fork

Greasy Fork is available in English.

编创协Markdown编辑器

Markdown编辑器,直接替换编程猫社区论坛内置编辑器,让你的编辑器更好用!

当前为 2022-08-26 提交的版本,查看 最新版本

// ==UserScript==
// @name         编创协Markdown编辑器
// @namespace    https://bcmcreator.cn/
// @version      1.5
// @description  Markdown编辑器,直接替换编程猫社区论坛内置编辑器,让你的编辑器更好用!
// @author       冷鱼闲风
// @match        https://shequ.codemao.cn/community
// @match        https://shequ.codemao.cn/community?board=*
// @icon         https://pandao.github.io/editor.md/favicon.ico
// @grant        GM_xmlhttpRequest
// @connect      *
// @require      https://cdn.jsdelivr.net/npm/[email protected]
// @license      MIT
// ==/UserScript==
onload = (async () => {
    'use strict';
    let link = document.createElement("link");
    link.rel = "stylesheet";
    link.type = "text/css";
    link.href = "https://unpkg.com/[email protected]/dist/css/mdui.min.css";
    document.head.appendChild(link);
    document.getElementsByClassName("c-model_box--title")[0].style.display= 'none';
    document.getElementById("mceu_11").style.display= 'none';
    document.getElementsByClassName("r-community-c-forum_sender--container")[0].style.width= '100%';
    document.getElementsByClassName("r-community-c-forum_sender--option")[0].style.display= 'none';
    var box = document.getElementById("mceu_11");
    var doNotShield = {
        obj : { height: 380, mddata: '带全屏按钮+文本', banner: '',lx:'',lxx:'',fq:'',cs:0, id:0 ,name:'',xjm:'',cookie:'',tzidc:'',gs:'',ram:0,user:'',avatar_url:'',bcmid:''},
        beign: async () => {
            if(document.getElementsByClassName("r-community-c-forum_sender--title_input")[0].value==''){alert('请先在 (【发帖关键字】请输入标题(5-50字符以内】)输入框内写上本次文章标题。');}else{
                doNotShield.obj.name=document.getElementsByClassName("r-community-c-forum_sender--title_input")[0].value;
                if(doNotShield.obj.cs==0){
                    doNotShield.obj.cs+=1;
                    GM_xmlhttpRequest({
                        method: "get",
                        url: "https://api.codemao.cn/web/users/details",
                        data:document.cookie,
                        binary: true,
                        async onload({ response }) {
                            doNotShield.obj.id=JSON.parse(response).id;
                            doNotShield.obj.user=JSON.parse(response).nickname;
                            doNotShield.obj.avatar_url=JSON.parse(response).avatar_url;
                            GM_xmlhttpRequest({
                                method: "get",
                                url: "https://api.bcmcreator.cn/MD/edit/examples/savea.php?id="+doNotShield.obj.id+"&name="+doNotShield.obj.name,
                                binary: true,
                                async onload({ response }) {
                                    doNotShield.obj.xjm=response;
                                    var p = document.createElement('iframe');
                                    p.height = "1000px";
                                    p.width = "100%";
                                    p.id = "myFrame";
                                    p.src = "https://api.bcmcreator.cn/MD/edit/examples/full.php?id="+doNotShield.obj.id+"&xjm="+doNotShield.obj.xjm+"&name="+doNotShield.obj.name;
                                    p.scrolling = "no";
                                    box.parentNode.insertBefore(p, box);
                                },
                            });

                        },
                    });

                }else{
                    alert('你已经创建Markdown帖子了,不能再创建,请在帖子内修改。');}
            }
        },
        run: async () => {
            try {
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='热门活动'){ doNotShield.obj.fq='17';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='积木编程乐园'){ doNotShield.obj.fq='2';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='工作室&师徒'){ doNotShield.obj.fq='10';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='你问我答'){ doNotShield.obj.fq='5';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='神奇代码岛'){ doNotShield.obj.fq='3';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='图书馆'){ doNotShield.obj.fq='27';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='CoCo应用创作'){ doNotShield.obj.fq='2';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='Python乐园'){ doNotShield.obj.fq='11';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='源码精灵'){ doNotShield.obj.fq='26';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='NOC编程猫比赛'){ doNotShield.obj.fq='13';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='灌水池塘'){ doNotShield.obj.fq='7';}
                if(document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText=='训练师小课堂'){ doNotShield.obj.fq='28';}
                if(doNotShield.obj.mddata=='带全屏按钮+文本')
                {
                    doNotShield.obj.lx='1';
                    doNotShield.obj.lxx='2';
                } else{
                    doNotShield.obj.lx='2';
                    doNotShield.obj.lxx='3';
                }
                doNotShield.obj.ram=Math.ceil(Math.random()*999999999);
                doNotShield.obj.gs= new Object();
                doNotShield.obj.gs.content = '<p><img src="'+doNotShield.obj.banner+'" width="0.1" height="0.1"> <iframe src=\"//bcmcreator.cn/index.php?mod=tz&k='+ doNotShield.obj.lxx+'&bh='+doNotShield.obj.ram+'\" scrolling=\"no\" border=\"0\" frameborder=\"no\" framespacing=\"0\" allowfullscreen=\"true\"  style=\"width:100%;height:'+doNotShield.obj.height+'px; display: block; margin: 0px auto; max-width: 100%;\" > </iframe></p>';
                doNotShield.obj.gs.title =doNotShield.obj.name;
                GM_xmlhttpRequest({
                    url:"https://api.codemao.cn/web/forums/boards/"+doNotShield.obj.fq+"/posts",
                    method :"POST",
                    data:JSON.stringify(doNotShield.obj.gs),
                    headers: {
                        "Content-type": "application/json;charset=UTF-8",
                        "User-Agent":"Mozilla/4.0 (compatible; MSIE .0; Windows NT 6.1; Trident/4.0; SLCC2;)",
                        "Host":"api.codemao.cn",
                        "Cookie":document.cookie
                    },
                    async onload({ response }) {
                        doNotShield.obj.bcmid=JSON.parse(response).id;
                        GM_xmlhttpRequest({
                            method:"get",
                            url:"https://api.bcmcreator.cn/MD/bcmFORM.php?name="+doNotShield.obj.name+"&id="+doNotShield.obj.id+"&xjm="+doNotShield.obj.xjm+"&ram="+doNotShield.obj.ram+"&bcmid="+doNotShield.obj.bcmid+"&tx="+ doNotShield.obj.avatar_url+"&user="+ doNotShield.obj.user,
                            async onload({ response }) {
                                if(doNotShield.obj.bcmid!=undefined){
                                    window.open('https://shequ.codemao.cn/community/'+doNotShield.obj.bcmid);
                                }else{
                                    alert('发帖失败,原因是:'+response);
                                }
                            },
                        });
                    }
                });
            }
            catch(err) {
                alert('请选择发帖分区!');
            }
        },
        tz: async () => {
            if(doNotShield.obj.mddata=='带全屏按钮+文本')
            {
                doNotShield.obj.lx='1';
            } else{
                doNotShield.obj.lx='2';
            }
            window.open('https://api.bcmcreator.cn/MD/bcmMD.php?width='+doNotShield.obj.height+'&title='+document.getElementsByClassName("r-community-c-forum_sender--title_input")[0].value+'&md='+doNotShield.obj.xjm+'&k='+doNotShield.obj.lx+'&id='+doNotShield.obj.id);
        },
        tzid: async () => {
            if(doNotShield.obj.tzidc==''){
                alert('请输入论坛帖子ID,才能导入进来哦!');
            }else{
                GM_xmlhttpRequest({
                    method: "get",
                    url: "https://api.codemao.cn/web/users/details",
                    data:document.cookie,
                    binary: true,
                    async onload({ response }) {
                        doNotShield.obj.id=JSON.parse(response).id;
                        GM_xmlhttpRequest({
                            method: "get",
                            url: "https://api.bcmcreator.cn/MD/getMD.php?id="+doNotShield.obj.id+"&bcmid="+doNotShield.obj.tzidc,
                            binary: true,
                            async onload({ response }) {
                                doNotShield.obj.xjm=JSON.parse(response).xjm;
                                doNotShield.obj.name=JSON.parse(response).name;
                                document.getElementsByClassName("r-community-c-forum_sender--title_input")[0].value=doNotShield.obj.name;
                                var p = document.createElement('iframe');
                                p.height = "1000px";
                                p.width = "100%";
                                p.id = "myFrame";
                                p.src = "https://api.bcmcreator.cn/MD/edit/examples/full.php?id="+doNotShield.obj.id+"&xjm="+doNotShield.obj.xjm+"&name="+doNotShield.obj.name;
                                p.scrolling = "no";
                                box.parentNode.insertBefore(p, box);
                            },
                        });
                    }
                })
            }
        },
        help: async () => {}
    };
    document.querySelector("#root > div > div.r-index--main_cont > div > div.r-community--right_search_container > div > div.r-community--search_header > a.r-community--send_btn").addEventListener("click", () => {
        window.gui = new lil.GUI({title: "编创协Markdown编辑器"});
        window.gui.domElement.style.top = "unset";
        window.gui.domElement.style.bottom = "0";
        window.gui.domElement.style.userSelect = "none";
        const first=window.gui.addFolder( '初次使用' );
        first.add(doNotShield, "beign").name("创建Markdown帖子");
        const styles=window.gui.addFolder( '样式处理' );
        styles.add(doNotShield.obj, 'height', 0, 5000 ).name("帖子高度(px)");
        styles.add(doNotShield.obj, 'mddata', [ '带全屏按钮+文本', '纯文本' ] ).name("帖子类型");
        styles.add(doNotShield.obj, 'banner' ).name("小banner链接(可空)");
        styles.add(doNotShield, "tz").name("预览效果");
        const send=window.gui.addFolder( '发帖按钮' );
        send.add(doNotShield, "run").name("发布帖子");
        const anaphasis =window.gui.addFolder( '后期维护' );
        anaphasis.add(doNotShield.obj, 'tzidc').name("帖子ID");
        anaphasis.add(doNotShield, "tzid").name("导入帖子");
    });

});