Greasy Fork

Greasy Fork is available in English.

编创协Markdown编辑器

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         编创协Markdown编辑器
// @namespace    https://bcmcreator.cn/
// @version      1.0
// @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:'',fq:'',cs:0, id:0 ,name:'',xjm:'',cookie:'',tzidc:''},
        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
                            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 () => {
            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.fq!=''){
                if(doNotShield.obj.mddata=='带全屏按钮+文本')
                {
                    doNotShield.obj.lx='1';
                } else{
                    doNotShield.obj.lx='2';
                }
                GM_xmlhttpRequest({
                    method:"get",
                    url:"https://api.bcmcreator.cn/MD/bcmFORM.php?name="+doNotShield.obj.name+"&pic"+doNotShield.obj.banner+"&width="+doNotShield.obj.height+"&mk="+doNotShield.obj.lx+"&qy="+doNotShield.obj.fq+"&id="+doNotShield.obj.id+"&xjm="+doNotShield.obj.xjm,
                    headers:  {
                        "User-Agent": doNotShield.obj.cookie,
                    },
                    async onload({ response }) {
                        if(JSON.parse(response).id!=undefined){
                            window.open('https://shequ.codemao.cn/community/'+JSON.parse(response).id);
                        }else{
                            alert('发帖失败,原因是:'+response);
                        }
                    },
                });
            }else{
                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 anaphasis =window.gui.addFolder( '后期维护' );
        anaphasis.add(doNotShield.obj, 'tzidc').name("导入帖子ID(可空)");
        anaphasis.add(doNotShield, "tzid").name("导入帖子");
        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.obj, 'cookie' ).name("Cookie(会员可留空)");
        send.add(doNotShield, "run").name("发布帖子");
    });

});