// ==UserScript== // @name 编程猫使用优化 // @namespace https://shequ.codemao.cn/user/438403 // @version 1.46.274 // @description 对于在使用编程猫中遇到的各种问题的部分优化 // @author 小鱼yuzifu // @match *://shequ.codemao.cn/* // @icon https://static.codemao.cn/coco/player/unstable/B1F3qc2Hj.image/svg+xml?hash=FlHXde3J3HLj1PtOWGgeN9fhcba3 // @grant GM_xmlhttpRequest // @require https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js // @require https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/sweetalert/2.1.2/sweetalert.min.js // @require https://fastly.jsdelivr.net/npm/lil-gui@0.16 // @require https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/tldjs/2.3.1/tld.min.js // @require https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/viewerjs/1.10.4/viewer.min.js // @require https://greasyfork.org/scripts/465118-librarycomment/code/libraryComment.js?version=1229105 // @license 616 SB License // @downloadURL none // ==/UserScript== let oldFnOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function () { if (arguments[1].includes("hidden_status")) { return oldFnOpen.apply(); } return oldFnOpen.apply(this, arguments); }; (function () { "use strict"; if (window.location.href.indexOf("writer") != -1) { return false; } if (window.location.href.indexOf("publish") != -1) { let publish_on = setInterval(() => { if (window.location.href.indexOf("publish") == -1) { window.location.reload(); clearInterval(publish_on); } }, 100); return false; } function titleChange(content) { if (document.querySelector("title") && document.querySelector("title").innerHTML != content) { document.querySelector("title").innerHTML = content; } } // 白名单 let whiteList = ["box3.codemao.cn", "pickduck.cn", "shequ.codemao.cn", "player.codemao.cn", "static.yuzifu.top", "blog.yzf.moe", "player.bilibili.com", "bcmcreator.cn"]; // 感谢刘andy提供的代码awa unsafeWindow._dangerouslyOpenNewWindow = unsafeWindow.open; unsafeWindow.openurl = (url) => { // console.log("捕获"); if ((url.includes("community") || url.includes("wiki/forum")) && (parseInt(url.split("/")[2]) || parseInt(url.split("/")[3]))) { // console.log("发现为帖子"); let id = ""; if (url.includes("community")) { id = url.split("/")[2]; } else { id = url.split("/")[3]; } // console.log(id); $.ajax({ type: "GET", url: `https://api.codemao.cn/web/forums/posts/${id}/details`, contentType: "application/json;charset=UTF-8", async: true, xhrFields: { withCredentials: true, }, success: function (obj) { let a = document.createElement("div"); a.innerHTML = obj.content; // console.log(a); if (a.querySelector("iframe,embed")) { for (let i of a.querySelectorAll("iframe,embed")) { // console.log(i.getAttribute("src"), tldjs.parse(i.getAttribute("src")).hostname); if (i.getAttribute("src") && !whiteList.includes(tldjs.parse(i.getAttribute("src")).hostname)) { if (i.getAttribute("src").indexOf("https://static.codemao.cn/yuque/preview/") === 0) { $.ajax({ type: "GET", url: i.getAttribute("src"), async: true, success: function (obj) { let a = document.createElement("div"); a.innerHTML = obj; if (a.querySelector("script:not(script[src])").innerHTML.includes("viewer.setDocument")) { return unsafeWindow._dangerouslyOpenNewWindow(url); } else { swal({ title: "危险", text: "即将访问的帖子存在风险!", icon: "error", dangerMode: true, buttons: { visit: "继续访问(不推荐)", danger: "立即退出(推荐)" }, }).then((x) => { if (x == "visit") { swal({ title: "警告", text: "您真的要继续访问吗?", dangerMode: true, buttons: { visit: "继续访问(不推荐)", danger: "立即退出(推荐)" }, }).then((x) => { if (x == "visit") { return unsafeWindow._dangerouslyOpenNewWindow(url); } return null; }); document.querySelector(".swal-button-container:last-child button").focus(); } return null; }); document.querySelector(".swal-button-container:last-child button").focus(); } }, }); } else { swal({ title: "危险", text: "即将访问的帖子存在风险!", icon: "error", dangerMode: true, buttons: { visit: "继续访问(不推荐)", danger: "立即退出(推荐)" }, }).then((x) => { if (x == "visit") { swal({ title: "警告", text: "您真的要继续访问吗?", dangerMode: true, buttons: { visit: "继续访问(不推荐)", danger: "立即退出(推荐)" }, }).then((x) => { if (x == "visit") { return unsafeWindow._dangerouslyOpenNewWindow(url); } return null; }); document.querySelector(".swal-button-container:last-child button").focus(); } return null; }); document.querySelector(".swal-button-container:last-child button").focus(); } } else { return unsafeWindow._dangerouslyOpenNewWindow(url); } } } else { return unsafeWindow._dangerouslyOpenNewWindow(url); } }, error: function (res) { swal({ title: "警告", text: "无法甄别即将访问的帖子是否危险!", icon: "warning", buttons: { visit: "暂不访问", danger: "继续访问" }, closeOnClickOutside: false, }).then((x) => { if (x == "danger") { return unsafeWindow._dangerouslyOpenNewWindow(url); } return null; }); // console.log(res.responseJSON); }, }); } else { // console.log("catched go"); return unsafeWindow._dangerouslyOpenNewWindow(url); } }; unsafeWindow.open = unsafeWindow.openurl; $("head").append( ` ` ); if (!document.querySelector('meta[name="theme-color"]')) { $("head").append(``); } setInterval(() => { //尝试制作防劫持 if ( window.location.href.indexOf("message") != -1 || ((window.location.href.indexOf("community") != -1 || window.location.href.indexOf("wiki/forum/") != -1) && parseInt(window.location.href.slice(25 + 11)) && document.querySelector("iframe")) || window.location.href.indexOf("reader") != -1 ) { var iframes = document.querySelectorAll("iframe"); for (var i = 0; i < iframes.length; i++) { if (!whiteList.includes(tldjs.getDomain(iframes[i].getAttribute("src")))) { iframes[i].style.position = "inherit"; if (!iframes[i].getAttribute("sandbox") && iframes[i] != document.querySelector(".mce-edit-area iframe")) { iframes[i].setAttribute("sandbox", "allow-forms allow-scripts allow-same-origin allow-popups"); iframes[i].setAttribute("src", "https://static.yuzifu.top/bcm/iframe.php?url=" + iframes[i].getAttribute("src")); } } } var embeds = document.querySelectorAll("embed"); for (i = 0; i < embeds.length; i++) { if (!whiteList.includes(tldjs.getDomain(embeds[i].getAttribute("src")))) { var embed_to_iframe = document.createElement("iframe"); embed_to_iframe.style.width = embeds[i].style.width; embed_to_iframe.style.height = embeds[i].style.height; embed_to_iframe.setAttribute("src", embeds[i].getAttribute("src")); embeds[i].parentNode.replaceChild(embed_to_iframe, embeds[i]); } } } }, 10); setInterval(() => { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/creation-tools/v1/user/center/honor", data: document.cookie, binary: true, onload({ response }) { localStorage.setItem("twikoo", `{"nick":"${JSON.parse(response).nickname}","mail":"","link":"${"https://shequ.codemao.cn/user/" + JSON.parse(response).user_id}"}`); }, }); try { if (window.location.href.indexOf("community") != -1 || window.location.href.indexOf("wiki/forum") != -1) { titleChange("论坛 | 编程猫社区"); } if (window.location.href.indexOf("work_shop") != -1) { if (parseInt(window.location.href.slice(25 + 10)) && document.querySelector(".r-work_shop-r-details--details_wrap .r-work_shop-r-details--header_cont .r-work_shop-r-details--title p")) { titleChange("工作室 | " + document.querySelector(".r-work_shop-r-details--details_wrap .r-work_shop-r-details--header_cont .r-work_shop-r-details--title p").innerHTML + " | 编程猫社区"); if (document.querySelector(".c-model_box--show:not(.target,.abc) .r-work_shop-r-details-component-project_dialog--project_box_wrap")) { document.querySelector(".c-model_box--show:not(.target)").classList.add("target"); document.querySelector(".c-model_box--show .r-work_shop-r-details-component-project_dialog--project_box_wrap").classList.add("target"); $(".c-model_box--show .r-work_shop-r-details-component-project_dialog--project_box_wrap").after("
"); $(".c-model_box--show .r-work_shop-r-details-component-project_dialog--project_box_wrap.target").remove(); $(".c-model_box--show .r-work_shop-r-details-component-project_dialog--project_box_wrap").append( `
你有作品的话,会过一会儿显示在这里的~
` ); GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/creation-tools/v1/user/center/honor", data: document.cookie, binary: true, onload({ response }) { GM_xmlhttpRequest({ method: "get", url: `https://api.codemao.cn/creation-tools/v2/user/center/work-list?user_id=${JSON.parse(response).user_id}&offset=0&limit=1000`, data: document.cookie, binary: true, async onload({ response }) { if (JSON.parse(response).items.length !== 0) { $(".r-work_shop-r-details-component-project_dialog--empty").remove(); } for (let abc of JSON.parse(response).items) { let type; switch (abc.type) { case 1: type = "Kitten"; break; case 12: type = "CoCo"; break; case 7: type = "海龟"; break; case 8: type = "Nemo"; break; case 15: type = "KittenN"; break; default: type = ""; break; } if (!document.querySelector(".r-work_shop-r-details-component-project_dialog--item[work-id='" + abc.id + "']")) { $(".r-work_shop-r-details-component-project_dialog--project_list").append(`
${abc.work_name}
${abc.view_times}
${ type === "" ? "" : ` ${type}` }
`); } } $(".r-work_shop-r-details-component-project_dialog--item[work-id]").on("click", function () { swal(`确定是 ${this.getElementsByClassName("r-work_shop-r-details-component-project_dialog--item_name")[0].innerHTML} 这个作品吗?`, { buttons: ["取消", "确认"] }).then((value) => { let work_id = this.getAttribute("work-id"); if (value) { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/web/shops/" + parseInt(window.location.href.slice(25 + 10)), data: document.cookie, binary: true, async onload({ response }) { $.ajax({ type: "POST", url: `https://api.codemao.cn/web/work_shops/works/contribute?id=${JSON.parse(response).shop_id}&work_id=${work_id}`, contentType: "application/json;charset=UTF-8", xhrFields: { withCredentials: true, }, success: function () { swal({ title: "成功", text: `成功投稿!`, icon: "success", }); }, error: function (res) { if (res.responseJSON.error_code == "Work-Has-Join-to-Work-shop@Community-Admin") { swal({ title: "错误", text: "这个作品你投过了吧?", icon: "error", }); } else { swal({ title: "错误", text: "未知错误,如果此作品是KittenN作品,可能当前并不支持投稿😭", icon: "error", }); } // console.log(res.responseJSON); }, }); }, }); } }); }); }, }); }, }); } } else { titleChange("工作室 | 编程猫社区"); } } if (window.location.href.indexOf("discover") != -1) { titleChange("发现 | 编程猫社区"); } if (window.location.href.indexOf("gallery") != -1) { if (parseInt(window.location.href.slice(25 + 8)) && document.querySelector(".r-gallery-r-detail--name")) { titleChange("活动 | " + document.querySelector(".r-gallery-r-detail--name").innerHTML + " | 编程猫社区"); } else { titleChange("活动 | 编程猫社区"); } } if (window.location.href.indexOf("user") != -1) { titleChange("个人中心 | " + document.querySelector(".r-user-c-banner--name").innerHTML + " | 编程猫社区"); } if (window.location.href.indexOf("work") != -1) { titleChange("作品 | " + document.querySelector(".r-work-c-work_info--work_name").innerHTML + " | 编程猫社区"); /* 反防沉迷系统,提供制作作品时调试,但不提供游玩🤔️ 想用可以自行取消下段代码的注释 */ if (document.querySelector(".c-virtual_player--virtual_player")) { $(".r-work-c-player--work_player_container .r-work-c-player--player_fun .r-work-c-player--player_refresh").remove(); $(".r-work-c-player--player_control_bar .r-work-c-player--reset_btn").remove(); var workType = $(".r-work-c-work_info--work_tool") .text() .replace(/作品由|创作/g, ""); var web; if (workType == "kitten3") { web = "https://player.codemao.cn/old/"; } else if (workType == "kitten4") { web = "https://player.codemao.cn/new/"; } else if (workType == "nemo") { web = "https://nemo.codemao.cn/w/"; } else if (workType == "CoCo编辑器") { web = "https://coco.codemao.cn/editor/player/"; } else if (workType == "海龟编辑器") { web = "https://turtle.codemao.cn/?entry=sharing&channel_type=community&action=open_published_project&work_id="; } else if (workType == "KittenN编辑器") { web = "https://kn.codemao.cn/player?workId="; } $(".r-work-c-player--work_player_container .r-work-c-player--player_container.r-work-c-player--fullscreen iframe").css("height", "100%"); if (!document.querySelector(".c-virtual_player--virtual_player").getElementsByTagName("iframe")[0]) { document.querySelector(".c-virtual_player--virtual_player").innerHTML = ''; } } } if (window.location.href.indexOf("studio") != -1) { titleChange("活动 | " + document.querySelector(".r-studio--studio_title").innerHTML + " | 编程猫社区"); } if (window.location.href.indexOf("setting") != -1) { titleChange("设置 | 编程猫社区"); if (!document.querySelector(".r-setting-component-set_avatar--upload_link.upload")) { $(".r-setting-component-set_avatar--upload_link").after(document.querySelector(".r-setting-component-set_avatar--upload_link").cloneNode(true)).remove(); $(".r-setting-component-set_avatar--upload_link").addClass("upload"); $(".r-setting-component-set_avatar--btn_save").after(document.querySelector(".r-setting-component-set_avatar--btn_save").cloneNode(true)).remove(); $(".r-setting-component-set_avatar--btn_save").addClass("upload"); document.querySelector(".r-setting-component-set_avatar--upload_link.upload").onclick = () => { var e = document.createElement("input"); e.setAttribute("type", "file"); e.addEventListener("change", function (e) { var n = e.target.files[0]; document.querySelector(".r-setting-component-set_avatar--left_area_container .r-setting-component-set_avatar--my_avatar").style.backgroundImage = `url(${upload(n)})`; }); e.click(); }; document.querySelector(".r-setting-component-set_avatar--btn_save.upload").onclick = () => { let url = document.querySelector(".r-setting-component-set_avatar--left_area_container .r-setting-component-set_avatar--my_avatar").style.backgroundImage; url = url.includes('"') ? url.replace('url("', "").replace('")', "") : url.replace("url(", "").replace(")", ""); $.ajax({ type: "PATCH", url: "https://api.codemao.cn/tiger/v3/web/accounts/info", contentType: "application/json;charset=UTF-8", data: JSON.stringify({ avatar_url: url, }), dataType: "json", xhrFields: { withCredentials: true, }, success: function () { document.querySelector(".c-model_box--dialog_wrap .c-model_box--content_box .c-model_box--close").click(); document.querySelector(".r-setting--setting_form .r-setting--form_item .r-setting--head_icon").style.backgroundImage = `url(${url})`; document.querySelector(".c-navigator--header-content .c-navigator--user_wrap .c-navigator--avatar").style.backgroundImage = `url(${url})`; window.location.reload(); }, error: function (res) { alert("失败"); // console.log(res.responseJSON); }, }); }; } } function upload(file) { let url, fn, token, key, upload_url; fn = "avatar"; $.ajax({ type: "GET", url: "https://oversea-api.code.game/tiger/kitten/cdn/token/1?prefix=avatar&bucket=static", contentType: "application/json;charset=UTF-8", async: false, xhrFields: { withCredentials: true, }, success: function (res) { upload_url = res.bucket_url; token = res["data"][0]["token"]; key = res["data"][0]["filename"]; }, }); var formData = new FormData(); formData.append("token", token); formData.append("key", key); formData.append("fname", fn); formData.append("file", file); $.ajax({ type: "POST", url: "https://upload.qiniup.com/", async: false, contentType: false, processData: false, data: formData, success: function (res) { url = "/" + res.key; }, }); return encodeURI(upload_url + url); } if (window.location.href.indexOf("course") != -1) { titleChange("课程 | 编程猫社区"); } if (window.location.href.indexOf("mall") != -1) { titleChange("素材 | 编程猫社区"); } if (window.location.href.indexOf("my") != -1) { titleChange("作品管理 | 编程猫社区"); } if (window.location.href.indexOf("wiki/novel") != -1) { titleChange("图书馆 | 编程猫社区"); } if (window.location.href.indexOf("wiki/cartoon") != -1) { titleChange("漫画连载 | 编程猫社区"); } if (window.location.href.indexOf("wiki/book") != -1) { titleChange("资料图鉴 | 编程猫社区"); } if ((window.location.href.indexOf("community") != -1 || window.location.href.indexOf("wiki/forum/") != -1) && parseInt(window.location.href.slice(25 + 11)) && document.querySelector(".r-community-r-detail--forum_content")) { let gallery = new Viewer(document.querySelector(".r-community-r-detail--forum_content")); for (var photos of document.querySelectorAll(".r-community-r-detail-c-comment_item--content")) { new Viewer(photos); } } if (document.querySelector(".r-404--container") != null) { titleChange("404 | 编程猫社区"); if (document.querySelector("a").innerHTML == "返回首页") { document.querySelector("a").innerHTML = "3秒后返回首页"; } else { if (document.querySelector("a").innerHTML != "返回首页喽~") { document.querySelector("a").innerHTML = (parseFloat(document.querySelector("a").innerHTML.slice(0)) * 10 - 1) / 10 + "秒后返回首页"; } if (Math.ceil(parseFloat(document.querySelector("a").innerHTML.slice(0))) == "0") { window.location.href = "https://shequ.codemao.cn/"; document.querySelector("a").innerHTML = "返回首页喽~"; } } } } catch (e) { // console.error(e); } }, 100); (function () { /* 这里是自定义Logo */ setInterval(() => { if (document.querySelector(".c-navigator--logo_wrap img") || document.querySelector(".index__header-brand___2nK8h img")) { $(".c-navigator--logo_wrap img").remove(); $(".index__header-brand___2nK8h img").remove(); let PICKCAT = localStorage.getItem("customLogo") || "PICKCAT"; $(".c-navigator--logo_wrap").append(`${PICKCAT}`); $(".index__header-brand___2nK8h").append(`${PICKCAT}`); $("li[data-watch_event='下载APP-入口tab']").after(`
  • 设置
  • `); $("li.index__first-nav-content___1Ea0w:last-child").before( `
  • 设置
  • ` ); document.documentElement.style.setProperty("--main-color", localStorage.getItem("main-color") || "#fec433"); document.documentElement.style.setProperty("--second-color", localStorage.getItem("second-color") || "#f6b206"); document.documentElement.style.setProperty("--person-setting", localStorage.getItem("person-setting") || "pic"); document.documentElement.style.setProperty("--person-color", localStorage.getItem("person-color") || "#000"); document.documentElement.style.setProperty("--person-bg", localStorage.getItem("person-bg") || "url(https://cdn-community.codemao.cn/community_frontend/asset/banner_65b4a.png)"); document.documentElement.style.setProperty("--highlight-color", localStorage.getItem("highlight-color") || "#ec443d"); document.documentElement.style.setProperty("--isLevelShown", localStorage.getItem("isLevelShown") || ""); try { document.querySelector('meta[name="theme-color"]').content = localStorage.getItem("main-color") || "#fec433"; } catch (e) {} if (!document.querySelector(".c-dialog--dialog_cover")) { $("body").append("
    "); } $(".c-dialog--dialog_cover").after(`
    导航栏标题
    主题设置
    浅色 深色 自动
    主色调
    辅色调
    突出色调
    个人中心背景
    图片 纯色
    等级显示
    铃铛红点清除
    作品再创作查询
    账号“登录用户名”设置
    作品广告评论关键词设置
    作品广告评论查询
    语雀Markdown编辑器
    论坛自动翻页
    首页排版
    新人指导 代码岛3.0精选 点猫精选 新作喵喵看 训练师小课堂 优秀工作室 原创少儿小说 编程TV 社区星推荐
    自定义CSS样式
    `); var ws; let user_id; let wsHeart; setInterval(() => { if (!ws) { user_id = localStorage.getItem("user_id"); ws = new WebSocket(`wss://7c364134-d8e2-4b58-9567-7ca3847e4534-00-o9h3cgt860l2.pike.replit.dev/?id=${localStorage.getItem("user_id")}`); ws.onopen = function (evt) { wsHeart = setInterval(() => { let sendobj = JSON.stringify({ id: localStorage.getItem("user_id"), type: "post", }); ws.send(sendobj); if (window.location.href.indexOf("user/") != -1 && parseInt(window.location.href.slice(25 + 5))) { let sendobj = JSON.stringify({ id: parseInt(window.location.href.slice(25 + 5)).toString(), type: "get", }); ws.send(sendobj); ws.onmessage = function (e) { // console.log(JSON.parse(e.data).status); if (!document.querySelector(".user-status") && JSON.parse(e.data).status !== "未知") { $(".r-user-c-banner--banner .r-user-c-banner--background .r-user-c-banner--container .r-user-c-banner--photo img").before("
    "); } switch (JSON.parse(e.data).status) { case "在线": document.querySelector(".user-status").style.background = "lightgreen"; break; case "离线": document.querySelector(".user-status").style.background = "gray"; break; default: break; } }; } }, 1000); // console.log("Connection open ..."); }; ws.onclose = function (evt) { // console.log("Connection closed."); clearInterval(wsHeart); }; ws.onerror = function (err) { // console.log(err); }; } else if (user_id !== localStorage.getItem("user_id")) { if (ws) { ws.close(); clearInterval(wsHeart); ws = null; } } }, 1000); if (window.location.href.indexOf("work/") != -1 && parseInt(window.location.href.slice(25 + 5))) { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/creation-tools/v1/works/" + parseInt(window.location.href.slice(25 + 5)), data: document.cookie, binary: true, onload({ response }) { if (JSON.parse(response).type == "NEMO") { setInterval(() => { if (document.querySelector(".r-work-c-player--player_fun .r-work-c-player--player_rotate_screen") == null) { $(".r-work-c-player--player_full_screen").after( `` ); $(".r-work-c-player--player_fun .r-work-c-player--player_rotate_screen").click(function () { rotateDeg -= 90; document.documentElement.style.setProperty("--rotateDeg", "rotate(" + rotateDeg + "deg)"); document.documentElement.style.setProperty("--OppoRotateDeg", "rotate(" + -rotateDeg + "deg)"); //document.getElementById('player_cover').contentWindow.document.querySelector('body').style.transform='rotate(' + -rotateDeg + 'deg)' }); } if (document.querySelector(".r-work-c-player--player_control_bar .r-work-c-player--player_rotate_screen") == null) { $(".r-work-c-player--player_control_bar .r-work-c-player--reset_btn").css("right", 136 + "px"); $(".r-work-c-player--quit_fullscreen_btn").before( `
    旋转屏幕
    ` ); $(".r-work-c-player--player_control_bar .r-work-c-player--player_rotate_screen").click(function () { rotateDeg -= 90; document.documentElement.style.setProperty("--rotateDeg", "rotate(" + rotateDeg + "deg)"); document.documentElement.style.setProperty("--OppoRotateDeg", "rotate(" + -rotateDeg + "deg)"); //document.getElementById('player_cover').contentWindow.document.querySelector('body').style.transform='rotate(' + -rotateDeg + 'deg)' }); } }, 100); var rotateDeg = 0; } }, }); } var theme, whiles; function to_light() { theme = "light"; document.documentElement.style.setProperty("--main-color", localStorage.getItem("main-color") || "#fec433"); document.documentElement.style.setProperty("--second-color", localStorage.getItem("second-color") || "#f6b206"); document.querySelector('meta[name="theme-color"]').content = localStorage.getItem("main-color") || "#fec433"; clearInterval(whiles); whiles = setInterval(() => { try { document.querySelector(".forum_editor .mce-edit-area.mce-container.mce-panel iframe").contentWindow.document.body.style.backgroundColor = ""; document.querySelector(".forum_editor .mce-edit-area.mce-container.mce-panel iframe").contentWindow.document.body.style.color = ""; } catch (e) {} }); if ((window.location.href.indexOf("community") != -1 || window.location.href.indexOf("wiki/forum/") != -1) && parseInt(window.location.href.slice(25 + 10)) && document.querySelector("iframe[allowfullscreen]")) { document.querySelector("iframe[allowfullscreen]").src = document.querySelector("iframe[allowfullscreen]").src; if (document.querySelector("iframe[allowfullscreen]").attachEvent) { document.querySelector("iframe[allowfullscreen]").attachEvent("onload", function () { document.querySelector("iframe[allowfullscreen]").contentWindow.postMessage("light", "*"); }); } else { document.querySelector("iframe[allowfullscreen]").onload = function () { document.querySelector("iframe[allowfullscreen]").contentWindow.postMessage("light", "*"); }; } } try { $(".darkmode").remove(); } catch (e) {} } function to_dark() { theme = "dark"; document.documentElement.style.setProperty("--main-color", "#666666"); document.documentElement.style.setProperty("--second-color", "#525252"); document.querySelector('meta[name="theme-color"]').content = "#666666"; clearInterval(whiles); whiles = setInterval(() => { try { document.querySelector(".forum_editor .mce-edit-area.mce-container.mce-panel iframe").contentWindow.document.body.style.backgroundColor = "#525252"; document.querySelector(".forum_editor .mce-edit-area.mce-container.mce-panel iframe").contentWindow.document.body.style.color = "#fff"; } catch (e) {} }); if ((window.location.href.indexOf("community") != -1 || window.location.href.indexOf("wiki/forum/") != -1) && parseInt(window.location.href.slice(25 + 10)) && document.querySelector("iframe[allowfullscreen]")) { // document.querySelector("iframe[allowfullscreen]").src = document.querySelector("iframe[allowfullscreen]").src; if (document.querySelector("iframe[allowfullscreen]").attachEvent) { document.querySelector("iframe[allowfullscreen]").attachEvent("onload", function () { document.querySelector("iframe[allowfullscreen]").contentWindow.postMessage("dark", "*"); }); } else { document.querySelector("iframe[allowfullscreen]").onload = function () { document.querySelector("iframe[allowfullscreen]").contentWindow.postMessage("dark", "*"); }; } } $("head").append(` `); } $("body").after(``); $("#custom-sett textarea").on("change", () => { localStorage.setItem("custom-sett", document.querySelector("#custom-sett textarea").value); document.querySelector("#custom-setts").innerHTML = document.querySelector("#custom-sett textarea").value; }); $("input#main-color").on("change", () => { localStorage.setItem("main-color", document.querySelector("input#main-color").value); if (theme == "light") { document.documentElement.style.setProperty("--main-color", document.querySelector("input#main-color").value); document.querySelector('meta[name="theme-color"]').content = localStorage.getItem("main-color") || "#fec433"; } }); $("input#second-color").on("change", () => { if (theme == "light") { document.documentElement.style.setProperty("--second-color", document.querySelector("input#second-color").value); } localStorage.setItem("second-color", document.querySelector("input#second-color").value); }); $("input#highlight-color").on("change", () => { document.documentElement.style.setProperty("--highlight-color", document.querySelector("input#highlight-color").value); localStorage.setItem("highlight-color", document.querySelector("#highlight-color").value); }); $("input#level-shown").on("change", () => { if (document.querySelector("input#level-shown").checked) { document.documentElement.style.setProperty("--isLevelShown", ""); localStorage.setItem("isLevelShown", ""); } else { document.documentElement.style.setProperty("--isLevelShown", "none"); localStorage.setItem("isLevelShown", "none"); } }); $("input#auto-turn").on("change", () => { if (document.querySelector("input#auto-turn").checked) { localStorage.setItem("auto-turn", "true"); } else { localStorage.setItem("auto-turn", ""); swal("将要刷新页面以保存修改", { buttons: ["取消", "确认"] }).then((value) => { if (value) { window.location.reload(); } }); } }); $("input#md-use").on("change", () => { if (document.querySelector("input#md-use").checked) { localStorage.setItem("md-use", "true"); } else { localStorage.setItem("md-use", ""); remove_md(); } }); $("input#customLogo").on("change", () => { localStorage.setItem("customLogo", document.querySelector("input#customLogo").value); $(".c-navigator--logo_wrap img").remove(); let PICKCAT = localStorage.getItem("customLogo") || "PICKCAT"; if (document.querySelector(".pickcat")) { document.querySelector(".pickcat").innerHTML = PICKCAT; } else { $(".c-navigator--logo_wrap").append(`${PICKCAT}`); } }); $('input[value="pic"]').on("change", () => { document.documentElement.style.setProperty("--person-color", ""); document.documentElement.style.setProperty("--person-bg", localStorage.getItem("person-bg") || "url(https://cdn-community.codemao.cn/community_frontend/asset/banner_65b4a.png)"); localStorage.setItem("person-setting", "pic"); document.documentElement.style.setProperty("--person-setting", "pic"); document.querySelector("#person-bg-btn").style.display = "block"; document.querySelector("#person-color").style.display = "none"; if (window.location.href.indexOf("user") != -1 && JSON.parse(response).user_id != parseInt(window.location.href.slice(25 + 5))) { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/creation-tools/v1/user/center/honor?user_id=" + parseInt(window.location.href.slice(25 + 5)), data: document.cookie, binary: true, onload({ response }) { if (JSON.parse(response).user_cover == "") { document.documentElement.style.setProperty("--person-bg", "url(https://cdn-community.codemao.cn/community_frontend/asset/banner_65b4a.png)"); document.documentElement.style.setProperty("--person-color", ""); } else { document.documentElement.style.setProperty("--person-bg", "url(" + JSON.parse(response).user_cover + ")"); document.documentElement.style.setProperty("--person-color", ""); } }, }); } }); $('input[value="color"]').on("change", () => { document.documentElement.style.setProperty("--person-color", localStorage.getItem("person-color") || "#000"); document.documentElement.style.setProperty("--person-bg", ""); localStorage.setItem("person-setting", "color"); document.documentElement.style.setProperty("--person-setting", "color"); document.querySelector("#person-bg-btn").style.display = "none"; document.querySelector("#person-color").style.display = "block"; if (window.location.href.indexOf("user") != -1 && JSON.parse(response).user_id != parseInt(window.location.href.slice(25 + 5))) { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/creation-tools/v1/user/center/honor?user_id=" + parseInt(window.location.href.slice(25 + 5)), data: document.cookie, binary: true, onload({ response }) { if (JSON.parse(response).user_cover == "") { document.documentElement.style.setProperty("--person-bg", "url(https://cdn-community.codemao.cn/community_frontend/asset/banner_65b4a.png)"); document.documentElement.style.setProperty("--person-color", ""); } else { document.documentElement.style.setProperty("--person-bg", "url(" + JSON.parse(response).user_cover + ")"); document.documentElement.style.setProperty("--person-color", ""); } }, }); } }); $("input[fish]").on("change", function () { if (document.querySelector('li[data-watch_event="' + this.value + '-入口tab"]')) { document.querySelector('li[data-watch_event="' + this.value + '-入口tab"]').style.display = this.checked ? "" : "none"; } else { for (h of document.querySelectorAll(".index__first-nav-content___1Ea0w")) { if (h.getElementsByTagName("a")[0].innerHTML == this.value || (h.getElementsByTagName("a")[0].getElementsByTagName("span")[1] && h.getElementsByTagName("a")[0].getElementsByTagName("span")[1].innerHTML == this.value)) { h.style.display = this.checked ? "" : "none"; } } } localStorage.setItem("isShown" + this.value, this.checked); }); $("input[fish2]").on("change", function () { document.documentElement.style.setProperty(this.value, this.checked ? "" : "none"); localStorage.setItem(this.value, this.checked ? "" : "none"); }); $('input[value="light"]').on("change", function () { localStorage.setItem("theme", "light"); to_light(); }); $('input[value="dark"]').on("change", function () { localStorage.setItem("theme", "dark"); to_dark(); }); $('input[value="auto"]').on("change", function () { localStorage.setItem("theme", "auto"); if (!window.matchMedia("(prefers-color-scheme: light)").matches) { to_dark(); } else { to_light(); } }); let junkComment = 0; let searching = 0; let junkCommentID = []; let junkContent = []; function afterGetJunk(workid) { // console.log(junkComment, junkCommentID); let junkCommentTotal = document.createElement("div"); junkCommentTotal.style = ` max-height: 400px; overflow: auto; `; for (let conut = 0; conut < junkComment; conut++) { let aaa = document.createElement("input"); aaa.type = "checkbox"; aaa.checked = true; aaa.value = junkCommentID[conut]; let bbb = document.createElement("span"); bbb.innerHTML = junkContent[conut]; let ccc = document.createElement("div"); ccc.appendChild(aaa); ccc.appendChild(bbb); ccc.style = ` display: flex; justify-content: flex-start; align-items: baseline; `; aaa.onchange = function () { if (this.checked) { junkCommentID.push(parseInt(this.value)); } else { junkCommentID.splice(junkCommentID.indexOf(parseInt(this.value)), 1); } junkComment = junkCommentID.length; // console.log(junkCommentID); }; junkCommentTotal.appendChild(ccc); } swal({ title: "注意", text: "你有" + junkComment + "条广告,是否需要直接删除", content: junkCommentTotal, icon: "info", buttons: ["取消", "确认"], }).then((value) => { if (value) { let cleaning = 0; let fail = 0; for (let id of junkCommentID) { $.ajax({ type: "DELETE", url: `https://api.codemao.cn/creation-tools/v1/works/${workid}/comment/${id}`, contentType: "application/json;charset=UTF-8", async: true, xhrFields: { withCredentials: true, }, success: function () { cleaning++; if (cleaning === junkComment) { swal({ title: "成功", text: "还你一个干净的评论区~", icon: "success", }); } else { swal({ title: "清理中···", text: `正在清理,现在已清理${cleaning}/${junkComment}条`, icon: "info", buttons: false, closeOnClickOutside: false, closeOnEsc: false, }); } }, error: function (res) { if (fail !== 1) { cleaning++; swal({ title: "错误", text: res.responseJSON.error_message, icon: "error", }); // console.log(res.responseJSON); fail = 1; } }, }); } if (junkComment !== 0) { swal({ title: "清理中···", text: `正在清理,现在已清理0/${junkComment}条`, icon: "info", buttons: false, closeOnClickOutside: false, closeOnEsc: false, }); } else { swal({ title: "成功", text: "还你一个干净的评论区~", icon: "success", }); } } }); } function readComment(offset, workid, limit) { $.ajax({ type: "GET", url: `https://api.codemao.cn/creation-tools/v1/works/${workid}/comments?offset=${offset}&limit=20`, contentType: "application/json;charset=UTF-8", async: true, xhrFields: { withCredentials: true, }, success: function (res) { for (let com of res.items) { if (eval("/" + localStorage.getItem("JunkWord") + "/").test(com.content)) { junkContent.push(`${com.id} ${com.user.nickname}:${com.content}`); junkComment++; junkCommentID.push(com.id); } if (com.replies) { for (let rep of com.replies.items) { if (eval("/" + localStorage.getItem("JunkWord") + "/").test(rep.content)) { junkContent.push(`${rep.id} ${rep.reply_user.nickname}${rep.parent_user ? " 回复 " + rep.parent_user.nickname : ""}:${rep.content}`); junkComment++; junkCommentID.push(com.id); } } } searching++; swal({ title: "查找中···", text: `正在查找垃圾评论,目前进度${searching}/${limit}`, icon: "info", buttons: false, closeOnClickOutside: false, closeOnEsc: false, }); } if (offset < limit) { readComment(offset + 20, workid, limit); } else { afterGetJunk(workid); } }, error: function (res) { swal({ title: "错误", text: res.responseJSON.error_message, icon: "error", }); // console.log(res.responseJSON); }, }); } $("#Junkcomment-btn").on("click", () => { if (!localStorage.getItem("JunkWord")) { localStorage.setItem("JunkWord", "(点|点个|互|给个)(赞|再创作|收藏|关|关注)|不喜可删|广告|(升|冲)(高手|传说|大佬)|协作项目|(来|可以)看一下(我的|我的作品)|已赞"); } swal("请选择你的操作(如果你不懂正则表达式,请选择添加,否则选择修改)", { buttons: { add: { text: "添加屏蔽词", }, change: { text: "修改屏蔽词", }, watch: { text: "查看屏蔽词", }, }, }).then((value) => { switch (value) { case "add": swal("请输入你要添加的单个屏蔽词", { content: "input", }).then((value) => { if (value) { localStorage.setItem("JunkWord", localStorage.getItem("JunkWord") + "|" + value); } }); break; case "change": var inputment = document.createElement("input"); inputment.className = "swal-content__input"; inputment.value = localStorage.getItem("JunkWord"); swal("请输入你要修改的正则表达式", { content: inputment, }).then((value) => { if (value && inputment.value) { localStorage.setItem("JunkWord", inputment.value); } }); break; case "watch": swal({ title: "你的正则表达式为", text: localStorage.getItem("JunkWord"), icon: "info", }); break; default: break; } }); }); $("#commentCheck-btn").on("click", () => { if (!localStorage.getItem("JunkWord")) { localStorage.setItem("JunkWord", "(点|点个|互|给个)(赞|再创作|收藏|关|关注)|不喜可删|广告|(升|冲)(高手|传说|大佬)|协作项目|(来|可以)看一下(我的|我的作品)|已赞"); } var inputment = document.createElement("input"); inputment.className = "swal-content__input"; if (window.location.href.indexOf("work/") != -1 && parseInt(window.location.href.slice(25 + 5))) { inputment.value = parseInt(window.location.href.slice(25 + 5)); } else { inputment.value = ""; } swal("请输入你要查询的作品ID", { content: inputment, }).then((value) => { if (value) { if (inputment.value != "") { GM_xmlhttpRequest({ method: "get", url: `https://api.codemao.cn/creation-tools/v1/works/${inputment.value}/comments?offset=0&limit=5`, data: document.cookie, binary: true, onload({ response }) { if (response == undefined) { swal({ title: "错误", text: "未知原因", icon: "error", }); } else if (JSON.parse(response).error_message !== undefined) { swal({ title: "错误", text: JSON.parse(response).error_message, icon: "error", }); } else { junkComment = 0; junkCommentID = []; searching = 0; junkContent = []; readComment(0, inputment.value, JSON.parse(response).page_total); swal({ title: "查找中···", text: `正在查找垃圾评论,目前进度0/${JSON.parse(response).page_total}`, icon: "info", buttons: false, closeOnClickOutside: false, closeOnEsc: false, }); } }, }); } else { swal({ title: "错误", text: "请输入作品ID!", icon: "error", }); } } }); }); $("#person-color").on("change", function () { document.documentElement.style.setProperty("--person-color", this.value); localStorage.setItem("person-color", this.value); }); $("#person-bg-btn").on("click", function () { document.querySelector("#person-bg").click(); }); if (localStorage.getItem("isLevelShown") == "none") { document.querySelector("input#level-shown").checked = false; } else { document.querySelector("input#level-shown").checked = true; } var i, h; for (i of document.querySelectorAll("input[fish]")) { if (localStorage.getItem("isShown" + i.value) != null) { if (localStorage.getItem("isShown" + i.value) == "true") { if (document.querySelector('li[data-watch_event="' + i.value + '-入口tab"]')) { document.querySelector('li[data-watch_event="' + i.value + '-入口tab"]').style.display = ""; i.checked = true; } else if (document.querySelector(".index__first-nav-content___1Ea0w")) { for (h of document.querySelectorAll(".index__first-nav-content___1Ea0w")) { if (h.getElementsByTagName("a")[0].innerHTML == i.value || (h.getElementsByTagName("a")[0].getElementsByTagName("span")[1] && h.getElementsByTagName("a")[0].getElementsByTagName("span")[1].innerHTML == i.value)) { h.style.display = ""; i.checked = true; } } } } else { if (document.querySelector('li[data-watch_event="' + i.value + '-入口tab"]')) { document.querySelector('li[data-watch_event="' + i.value + '-入口tab"]').style.display = "none"; i.checked = false; } else if (document.querySelector(".index__first-nav-content___1Ea0w")) { for (h of document.querySelectorAll(".index__first-nav-content___1Ea0w")) { if (h.getElementsByTagName("a")[0].innerHTML == i.value || (h.getElementsByTagName("a")[0].getElementsByTagName("span")[1] && h.getElementsByTagName("a")[0].getElementsByTagName("span")[1].innerHTML == i.value)) { h.style.display = "none"; i.checked = false; } } } } } } for (i of document.querySelectorAll("input[fish2]")) { if (localStorage.getItem(i.value) != null) { if (localStorage.getItem(i.value) == "none") { document.documentElement.style.setProperty(i.value, "none"); i.checked = false; } else { document.documentElement.style.setProperty(i.value, ""); i.checked = true; } } } $("#person-bg").on("change", function () { var file = this.files[0]; if (!/image\/\w+/.test(file.type)) { return false; } if (typeof FileReader != "undefined") { var reader = new FileReader(); var imgFile; reader.readAsDataURL(file); reader.onload = function (e) { imgFile = e.target.result; document.documentElement.style.setProperty("--person-bg", "url(" + imgFile + ")"); localStorage.setItem("person-bg", "url(" + imgFile + ")"); }; } else { var URL = window.URL || window.webkitURL; var imageURL = URL.createObjectURL(file); document.documentElement.style.setProperty("--person-bg", "url(" + imageURL + ")"); localStorage.setItem("person-bg", "url(" + imageURL + ")"); } }); function remixCheck(num, list) { if (num.length == 0) { return list; } for (var a of num) { if (a.is_published == 1 || a.is_published == 0) { try { list[0].push(a.id); list[1].push(a.author.nickname); list[2].push(a.is_published); } catch (e) {} } if (a.children != "[]") { remixCheck(a.children); } } return list; } $("#remixCheck-btn").on("click", () => { var inputment = document.createElement("input"); inputment.className = "swal-content__input"; if (window.location.href.indexOf("work/") != -1 && parseInt(window.location.href.slice(25 + 5))) { inputment.value = parseInt(window.location.href.slice(25 + 5)); } else { inputment.value = ""; } swal("请输入你要查询的作品ID", { content: inputment, }).then((value) => { if (value) { if (inputment.value != "") { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/tiger/work/tree/" + inputment.value, data: document.cookie, binary: true, async onload({ response }) { if (response == undefined) { swal({ title: "错误", text: "未知原因", icon: "error", }); } else if (JSON.parse(response).children == undefined) { swal({ title: "错误", text: "请检查一下自己的作品ID是否输入正确!", icon: "error", }); } else { var s = remixCheck(JSON.parse(response).children, [[], [], []]); if (s[0].length != 0) { var copymefuck = document.createElement("table"); copymefuck.style = "width:100%;border-spacing: 10px;"; for (var ppp = 0; ppp < s[0].length; ppp++) { var aaa = document.createElement("tr"); aaa.setAttribute("published", s[2][ppp]); aaa.innerHTML += "" + s[0][ppp] + "" + s[1][ppp] + ""; copymefuck.appendChild(aaa); } swal({ content: copymefuck, title: "有" + s[0].length + "个再创作了!", icon: "warning", }); document.querySelector(".swal-content").style = "max-height: 400px;overflow: auto;"; $(copymefuck).before("

    隐藏未发布的

    "); $(copymefuck).before(`

    原作品ID:${JSON.parse(response).id}

    `); $(".pubornot").on("click", function () { if (document.querySelector(".pubornot").id == "hidenotpub") { $('tr[published="0"]').css("display", "none"); document.querySelector(".swal-title").innerHTML = "有" + document.querySelectorAll('tr[published="1"]').length + "个再创作并发布的了!"; document.querySelector(".pubornot").id = "shownotpub"; document.querySelector(".pubornot").innerHTML = "显示未发布的"; } else { $('tr[published="0"]').css("display", ""); document.querySelector(".swal-title").innerHTML = "有" + s[0].length + "个再创作了!"; document.querySelector(".pubornot").id = "hidenotpub"; document.querySelector(".pubornot").innerHTML = "隐藏未发布的"; } }); } else { swal({ title: "好耶!", text: "目前没有人再创作并发布此作品!", icon: "success", }); } } }, }); } else { swal({ title: "错误", text: "请输入作品ID!", icon: "error", }); } } }); }); $("#username-btn").on("click", () => { var inputment = document.createElement("input"); inputment.className = "swal-content__input"; swal({ title: "请输入你要更改的登录用户名", text: "这个用户名将作为你的登录账号使用", content: inputment, }).then((value) => { if (value) { if (inputment.value != "") { swal({ title: "警告", text: `你的用户名是:${inputment.value}\n这里作再三强调,只能修改一次\n你确定吗?`, icon: "warning", dangerMode: true, buttons: true, }).then((value) => { if (value) { $.ajax({ type: "PATCH", url: "https://api.codemao.cn/tiger/v3/web/accounts/username", contentType: "application/json;charset=UTF-8", data: JSON.stringify({ username: inputment.value, }), dataType: "json", xhrFields: { withCredentials: true, }, success: function () { swal({ title: "成功", text: `你现在的用户名是:${inputment.value}\n以后你就可以用这个来登录你的编程猫账号了!`, icon: "success", }); }, error: function (res) { swal({ title: "错误", text: res.responseJSON.error_message, icon: "error", }); // console.log(res.responseJSON); }, }); } }); } else { swal({ title: "错误", text: "请输入用户名!", icon: "error", }); } } }); }); /*这里不知道为啥不能for整,所以只好这样*/ $("#mess-del-btn").on("click", () => { swal({ text: "开始清除!", buttons: false, timer: 3000, }); GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/web/message-record?query_type=LIKE_FORK&limit=200&offset=0", data: document.cookie, binary: true, async onload({ response }) { for (var y = 0; y < JSON.parse(response).total; y += 200) { messDel(y, "LIKE_FORK"); } }, }); GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/web/message-record?query_type=SYSTEM&limit=200&offset=0", data: document.cookie, binary: true, async onload({ response }) { for (var y = 0; y < JSON.parse(response).total; y += 200) { messDel(y, "SYSTEM"); } }, }); GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/web/message-record?query_type=COMMENT_REPLY&limit=200&offset=0", data: document.cookie, binary: true, async onload({ response }) { for (var y = 0; y < JSON.parse(response).total; y += 200) { messDel(y, "COMMENT_REPLY"); } swal({ text: "你的铃铛红点已清除,再也不会急死强迫症的你了~", buttons: false, timer: 3000, }); }, }); }); async function messDel(offset, types) { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/web/message-record?query_type=" + types + "&limit=200&offset=" + offset, data: document.cookie, binary: true, async onload({ response }) {}, }); } const addRipple = function (e) { let overlay = $("
    "); overlay.removeClass("animate"); const x = parseInt(e.pageX - $(this).offset().left) - overlay.width() / 2; const y = parseInt(e.pageY - $(this).offset().top) - overlay.height() / 2; overlay .css({ left: x, top: y, }) .addClass("animate"); $(this).append(overlay); setTimeout(() => { overlay.remove(); }, 500); }; let rippleList = [ ".c-navigator--header-content .c-navigator--nav_wrap .c-navigator--item a", ".c-navigator--dropdown-wrap li a", ".r-community--send_btn", "li[data-watch_event='旋转-入口tab']", ".r-community-c-forum_sender--option", ".r-home-c-community_star--user_recommend_item", ".r-user-c-banner--btn", ".c-navigator--logout", ".c-navigator--cont .c-navigator--item", ".r-community-c-forum_sender--select_area span", ".r-community--forum_list div li", ".r-community--forum_list2 div li", ".r-community--board_item", ".r-home-c-work_card--work_card", ".r-community--search_container .r-community--my_options .r-community--option", ".r-gallery-c-theme_card--card_item", ]; setInterval(() => { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/creation-tools/v1/user/center/honor", data: document.cookie, binary: true, async onload({ response }) { var options, info; if (JSON.parse(response).user_id) { if (Notification.permission !== "denied") { Notification.requestPermission().then((permission) => {}); } if (!localStorage.getItem("user" + JSON.parse(response).user_id)) { localStorage.setItem("user" + JSON.parse(response).user_id, JSON.parse(response).fans_total + "," + JSON.parse(response).liked_total); } if (localStorage.getItem("user" + JSON.parse(response).user_id).split(",")[0] != JSON.parse(response).fans_total) { info = JSON.parse(response).fans_total - localStorage.getItem("user" + JSON.parse(response).user_id).split(",")[0] > 0 ? "多" : "少"; options = { body: `现在你的粉丝数为:${JSON.parse(response).fans_total},比上次${info}了${Math.abs(JSON.parse(response).fans_total - localStorage.getItem("user" + JSON.parse(response).user_id).split(",")[0])}个`, icon: "https://static.codemao.cn/coco/player/unstable/B1F3qc2Hj.image/svg+xml?hash=FlHXde3J3HLj1PtOWGgeN9fhcba3", tag: "fans_total", }; if (n) n.close(); var n = new Notification("粉丝数", options); // 显示通知 } if (localStorage.getItem("user" + JSON.parse(response).user_id).split(",")[1] != JSON.parse(response).liked_total) { info = JSON.parse(response).liked_total - localStorage.getItem("user" + JSON.parse(response).user_id).split(",")[1] > 0 ? "多" : "少"; options = { body: `现在你的点赞数为:${JSON.parse(response).liked_total},比上次${info}了${Math.abs(JSON.parse(response).liked_total - localStorage.getItem("user" + JSON.parse(response).user_id).split(",")[1])}个`, icon: "https://static.codemao.cn/coco/player/unstable/B1F3qc2Hj.image/svg+xml?hash=FlHXde3J3HLj1PtOWGgeN9fhcba3", tag: "liked_total", }; if (k) k.close(); var k = new Notification("点赞数", options); // 显示通知 } localStorage.setItem("user" + JSON.parse(response).user_id, JSON.parse(response).fans_total + "," + JSON.parse(response).liked_total); } }, }); GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/web/message-record/count", data: document.cookie, binary: true, async onload({ response }) { try { $("li[data-watch_event='消息-评论'] a .c-navigator--reply_count").css("display", "none"); $("li[data-watch_event='消息-赞'] a .c-navigator--reply_count").css("display", "none"); $("li[data-watch_event='消息-系统'] a .c-navigator--reply_count").css("display", "none"); $(".c-navigator--message span").css("display", "none"); } catch (error) {} if (JSON.parse(response)[0]) { if (JSON.parse(response)[0].count == 0) { if (document.querySelector("li[data-watch_event='消息-评论'] a .c-navigator--reply_count")) { $("li[data-watch_event='消息-评论'] a .c-navigator--reply_count").css("display", "none"); } else if (document.querySelector("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.0'] .index__reply_count___1nqAb")) { $("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.0'] .index__reply_count___1nqAb").css("display", "none"); } } else { if (document.querySelector("li[data-watch_event='消息-评论'] a .c-navigator--reply_count")) { $("li[data-watch_event='消息-评论'] a .c-navigator--reply_count:first-child").css("display", ""); document.querySelector("li[data-watch_event='消息-评论'] a .c-navigator--reply_count").innerHTML = `(${JSON.parse(response)[0].count})`; } else { $("li[data-watch_event='消息-评论'] a").append(`(${JSON.parse(response)[0].count})`); } if (document.querySelector("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.0'] .index__reply_count___1nqAb")) { $("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.0'] a span.index__reply_count___1nqAb:nth-child(2)").css("display", ""); document.querySelector("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.0'] .index__reply_count___1nqAb").innerHTML = `(${JSON.parse(response)[0].count})`; } else { $("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.0'] a").append(`(${JSON.parse(response)[0].count})`); } } if (JSON.parse(response)[1].count == 0) { if (document.querySelector("li[data-watch_event='消息-赞'] a .c-navigator--reply_count")) { $("li[data-watch_event='消息-赞'] a .c-navigator--reply_count").css("display", "none"); } else if (document.querySelector("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.1'] .index__reply_count___1nqAb")) { $("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.1'] .index__reply_count___1nqAb").css("display", "none"); } } else { if (document.querySelector("li[data-watch_event='消息-赞'] a .c-navigator--reply_count")) { $("li[data-watch_event='消息-赞'] a .c-navigator--reply_count:first-child").css("display", ""); document.querySelector("li[data-watch_event='消息-赞'] a .c-navigator--reply_count").innerHTML = `(${JSON.parse(response)[1].count})`; } else { $("li[data-watch_event='消息-赞'] a").append(`(${JSON.parse(response)[1].count})`); } if (document.querySelector("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.1'] .index__reply_count___1nqAb")) { $("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.1'] a span.index__reply_count___1nqAb:nth-child(2)").css("display", ""); document.querySelector("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.1'] .index__reply_count___1nqAb").innerHTML = `(${JSON.parse(response)[1].count})`; } else { $("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.1'] a").append(`(${JSON.parse(response)[1].count})`); } } if (JSON.parse(response)[2].count == 0) { if (document.querySelector("li[data-watch_event='消息-系统'] a .c-navigator--reply_count")) { $("li[data-watch_event='消息-系统'] a .c-navigator--reply_count").css("display", "none"); } else if (document.querySelector("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.2'] .index__reply_count___1nqAb")) { $("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.2'] .index__reply_count___1nqAb").css("display", "none"); } } else { if (document.querySelector("li[data-watch_event='消息-系统'] a .c-navigator--reply_count")) { $("li[data-watch_event='消息-系统'] a .c-navigator--reply_count:first-child").css("display", ""); document.querySelector("li[data-watch_event='消息-系统'] a .c-navigator--reply_count").innerHTML = `(${JSON.parse(response)[2].count})`; } else { $("li[data-watch_event='消息-系统'] a").append(`(${JSON.parse(response)[2].count})`); } if (document.querySelector("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.2'] .index__reply_count___1nqAb")) { $("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.2'] a span.index__reply_count___1nqAb:nth-child(2)").css("display", ""); document.querySelector("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.2'] .index__reply_count___1nqAb").innerHTML = `(${JSON.parse(response)[2].count})`; } else { $("li[data-reactid='.0.0.0.0.0.3.0.0.1.0.2'] a").append(`(${JSON.parse(response)[2].count})`); } } if (JSON.parse(response)[0].count + JSON.parse(response)[1].count + JSON.parse(response)[2].count == 0) { if (document.querySelector(".c-navigator--message span")) { $(".c-navigator--message span").css("display", "none"); } else if (document.querySelector(".index__user_wrap___11XZU .index__message___3tAMD span")) { $(".index__user_wrap___11XZU .index__message___3tAMD span").css("display", "none"); } } else { if (document.querySelector(".c-navigator--message span")) { $(".c-navigator--message span:first-child").css("display", ""); document.querySelector(".c-navigator--message span").innerHTML = `${ JSON.parse(response)[0].count + JSON.parse(response)[1].count + JSON.parse(response)[2].count > 99 ? "99+" : JSON.parse(response)[0].count + JSON.parse(response)[1].count + JSON.parse(response)[2].count }`; } else { $(".c-navigator--message").append( `${ JSON.parse(response)[0].count + JSON.parse(response)[1].count + JSON.parse(response)[2].count > 99 ? "99+" : JSON.parse(response)[0].count + JSON.parse(response)[1].count + JSON.parse(response)[2].count }` ); } if (document.querySelector(".index__user_wrap___11XZU .index__message___3tAMD span")) { $(".index__user_wrap___11XZU .index__message___3tAMD span:first-child").css("display", ""); document.querySelector(".index__user_wrap___11XZU .index__message___3tAMD span").innerHTML = `${ JSON.parse(response)[0].count + JSON.parse(response)[1].count + JSON.parse(response)[2].count > 99 ? "99+" : JSON.parse(response)[0].count + JSON.parse(response)[1].count + JSON.parse(response)[2].count }`; } else { $(".index__user_wrap___11XZU .index__message___3tAMD").append( `${ JSON.parse(response)[0].count + JSON.parse(response)[1].count + JSON.parse(response)[2].count > 99 ? "99+" : JSON.parse(response)[0].count + JSON.parse(response)[1].count + JSON.parse(response)[2].count }` ); } } } }, }); }, 1000); let url; setInterval(() => { try { $(".r-home-c-creativityComponent--creativity .r-home-c-creativityComponent--box .r-home-c-creativityComponent--detail .r-home-c-creativityComponent--text-box .r-home-c-creativityComponent--introduction img").attr( "src", "https://static.codemao.cn/coco/player/unstable/r1Z2a8yEj.image/png?hash=Fpf08Z93Z-LgvoMLKzbyACyAvroC" ); } catch (e) {} for (i of rippleList) { for (h of document.querySelectorAll(i)) { if (!$(h).hasClass("yzf-animate")) { $(h).addClass("yzf-animate"); $(h).css({ position: "relative", overflow: "hidden", transition: "0.1s ease-in", }); if (i == ".r-home-c-community_star--user_recommend_item") { $(h).children("a").mousedown(addRipple); } else { $(h).mousedown(addRipple); } } } } if ( (window.location.href.indexOf("community") != -1 || window.location.href.indexOf("wiki") != -1) && !parseInt(window.location.href.slice(25 + 10)) && window.location.href.indexOf("wiki/forum/") == -1 && window.location.href.indexOf("wiki/book") == -1 && window.location.href.indexOf("wiki/cartoon") == -1 && window.location.href.indexOf("wiki/novel") == -1 ) { if (Boolean(localStorage.getItem("md-use")) && document.getElementsByClassName("r-community-c-forum_sender--option")[0].style.display != "none") { bcm_markdown(); } if (Boolean(localStorage.getItem("md-use"))) { $(".forum_editor .mce-tinymce.mce-container.mce-panel").hide(); } var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; var windowHeight = document.documentElement.clientHeight || document.body.clientHeight; var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; $(".r-community--scroll_to_top").remove(); if (document.querySelector("#yzfnb") == null) { $(".r-index--main_cont").after('
    '); } if (scrollTop + windowHeight >= scrollHeight) { try { if (Boolean(localStorage.getItem("auto-turn")) && !document.querySelector("#loading")) { // document.documentElement.scrollTop = scrollHeight - windowHeight - 10; document.querySelector(".r-community--forum_list .c-pagination--btn.c-pagination--page-container li:last-child").click(); if (!document.querySelector(".r-community--forum_list .c-pagination--btn.c-pagination--page-container li:last-child.c-pagination--nomore")) { $(".r-community--forum_list2").after("

    加载中

    "); } } } catch (err) {} } } try { var reactTinymce = document.querySelector(".mce-edit-area iframe"); for (i of reactTinymce.contentWindow.document.querySelectorAll("img")) { if (i.className.indexOf("encode") == -1) { i.src = i.src; i.className = "encode"; i.removeAttribute("alt"); } } } catch (e) {} if ((window.location.href.indexOf("community") != -1 || window.location.href.indexOf("wiki/forum/") != -1) & Boolean(localStorage.getItem("auto-turn"))) { if (document.querySelector(".r-community--forum_list2") == null) { $(".r-community--forum_list").after("
    "); url = []; } if ( document.querySelector(".r-community--forum_list div:not(div[class])") != null && (document.querySelector(".r-community--forum_filter") != null || document.querySelector(".r-community--content_my_container") != null) && (document.querySelector("#fan") == null || document.querySelector(".r-community--content_my_container") != null) ) { if (!document.querySelector(".c-pagination--activePage") || document.querySelector(".c-pagination--activePage").innerHTML == "1") { $(".r-community--forum_list2").empty(); url = []; } var forum_list = document.querySelectorAll(".r-community--forum_list div:not(div[class])"); for (i of forum_list) { unsafeWindow.geturl = (u) => { // console.log(u); url.push(u); }; unsafeWindow.open = unsafeWindow.geturl; i.querySelector("li").click(); let oCopy = i.cloneNode(true); oCopy.querySelector("li").classList.remove("yzf-animate"); $(".r-community--forum_list2").append(oCopy); } unsafeWindow.open = unsafeWindow.openurl; // console.log(url); $(".r-community--forum_list div:not(div[class])").css("display", "none").addClass("dec"); for (i = 0; i < document.querySelectorAll(".r-community--forum_list2 div:not(div[class]) li").length; i++) { let onurl = url[i]; document.querySelectorAll(".r-community--forum_list2 div:not(div[class]) li")[i].onclick = () => { unsafeWindow.open(onurl); // console.log(onurl); }; } if (Boolean(localStorage.getItem("auto-turn"))) { $(".r-community--page_contianer").hide(); } $(".r-community--forum_list").append("
    "); $("#loading").remove(); } } if (window.location.href.indexOf("/message") != -1) { scrollTop = document.documentElement.scrollTop || document.body.scrollTop; windowHeight = document.documentElement.clientHeight || document.body.clientHeight; scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; try { document.querySelector(".r-message--load_more").style.opacity = 0; } catch (err) {} if (scrollTop + windowHeight >= scrollHeight) { try { document.querySelector(".r-message--load_more").click(); } catch (err) {} } var user_face; for (user_face of document.querySelectorAll(".r-message-c-comments--user_face")) { if (user_face.className.indexOf("encode") == -1) { user_face.classList.add("encode"); user_face_now(user_face); } } for (user_face of document.querySelectorAll(".r-message-c-buy--user_face")) { if (user_face.className.indexOf("encode") == -1) { user_face.classList.add("encode"); user_face_now(user_face); } } for (user_face of document.querySelectorAll(".r-message-c-system_message--user_face")) { if (user_face.className.indexOf("encode") == -1) { user_face.classList.add("encode"); user_face_now(user_face); } } } }, 100); function user_face_now(user_face) { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/creation-tools/v1/user/center/honor?user_id=" + user_face.href.slice(25 + 5), data: document.cookie, binary: true, async onload({ response }) { if (!JSON.parse(response).avatar_url) { user_face.style.backgroundImage = "url('https://cdn-community.codemao.cn/47/community/d2ViXzEwMDFfMTYwMTg3NDJfMTYwMTg3NDJfMTYyNjU3ODkzOTI2M185MGJlYmIyNQ.png')"; user_face.style.filter = "grayscale(1)"; } else { user_face.style.backgroundImage = "url('" + JSON.parse(response).avatar_url + "')"; } }, }); } document.querySelector("#custom-sett textarea").value = localStorage.getItem("custom-sett"); document.querySelector("#custom-setts").innerHTML = document.querySelector("#custom-sett textarea").value; $("head").append(` `); $("head").append(` `); $("li[data-watch_event='设置-入口tab']").click(function () { $("#yzf-settings").css("display", "block"); $("#yzf-settings").css("transform", "translateY(0)"); $("#yzf-close").click(() => { $(".c-dialog--dialog_wrap").css("opacity", "0"); $("#yzf-settings").css("transform", "translateY(-20px)"); setTimeout(() => { if (document.querySelector(".c-dialog--dialog_wrap")) { $(".c-dialog--dialog_wrap").removeClass("c-dialog--visiable c-dialog--show"); $(".c-dialog--dialog_wrap").css("opacity", ""); $("#yzf-settings").css("display", "none"); } else { $(".c-dialog--dialog_cover").fadeOut(200); $("#yzf-settings").fadeOut(200); } }, 200); }); $("#main-color").val(localStorage.getItem("main-color") || "#fec433"); $("#second-color").val(localStorage.getItem("second-color") || "#f6b206"); $("#person-color").val(localStorage.getItem("person-color") || "#000"); $("#highlight-color").val(localStorage.getItem("highlight-color") || "#ec443d"); document.querySelector("input#md-use").checked = Boolean(localStorage.getItem("md-use")) ? true : false; document.querySelector("input#auto-turn").checked = Boolean(localStorage.getItem("auto-turn")) ? true : false; if (document.querySelector(".c-dialog--dialog_wrap")) { $(".c-dialog--dialog_wrap").addClass("c-dialog--visiable c-dialog--show"); } else { $(".c-dialog--dialog_cover").css("zIndex", "100").fadeIn(200); } }); if (localStorage.getItem("theme") == "light" || localStorage.getItem("theme") == null) { document.querySelector('input[value="light"]').checked = true; to_light(); } else if (localStorage.getItem("theme") == "dark") { document.querySelector('input[value="dark"]').checked = true; to_dark(); } else { if (localStorage.getItem("theme") == "auto") { document.querySelector('input[value="auto"]').checked = true; const themeMedia = window.matchMedia("(prefers-color-scheme: light)"); if (!themeMedia.matches) { to_dark(); } else { to_light(); } themeMedia.addListener((e) => { if (localStorage.getItem("theme") == "auto") { if (!e.matches) { to_dark(); } else { to_light(); } } }); } } if (localStorage.getItem("person-setting") == "color") { document.querySelector('input[value="color"]').checked = true; document.querySelector("#person-bg-btn").style.display = "none"; document.querySelector("#person-color").style.display = "block"; document.documentElement.style.setProperty("--person-color", localStorage.getItem("person-color") || "#000"); document.documentElement.style.setProperty("--person-bg", ""); } else { document.querySelector('input[value="pic"]').checked = true; document.querySelector("#person-bg-btn").style.display = "block"; document.querySelector("#person-color").style.display = "none"; document.documentElement.style.setProperty("--person-color", ""); document.documentElement.style.setProperty("--person-bg", localStorage.getItem("person-bg") || "url(https://cdn-community.codemao.cn/community_frontend/asset/banner_65b4a.png)"); } GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/web/users/details", data: document.cookie, binary: true, async onload({ response }) { if (window.location.href.indexOf("user") != -1 && JSON.parse(response).id != parseInt(window.location.href.slice(25 + 5))) { GM_xmlhttpRequest({ method: "get", url: "https://api.codemao.cn/creation-tools/v1/user/center/honor?user_id=" + parseInt(window.location.href.slice(25 + 5)), data: document.cookie, binary: true, async onload({ response }) { if (JSON.parse(response).user_cover == "") { document.querySelector(".r-user-c-banner--banner .r-user-c-banner--background").style.setProperty("background-image", "url(https://cdn-community.codemao.cn/community_frontend/asset/banner_65b4a.png)", "important"); } else { document.querySelector(".r-user-c-banner--banner .r-user-c-banner--background").style.setProperty("background-image", "url(" + JSON.parse(response).user_cover + ")", "important"); } }, }); } }, }); } }, 100); })(); $("head").append(` `); function remove_md() { if (document.querySelector(".forum_editor.ne-doc-major-editor")) { $(".yuque-sender,#preview,#yuque").remove(); $(".forum_editor .mce-tinymce.mce-container.mce-panel,.r-community-c-forum_sender--bottom_options .r-community-c-forum_sender--option").show(); document.querySelector(".forum_editor").classList.remove("ne-doc-major-editor"); } } function bcm_markdown() { if (document.querySelector(".forum_editor:not(.ne-doc-major-editor)")) { document.querySelector(".forum_editor").classList.add("ne-doc-major-editor"); $(".r-community-c-forum_sender--bottom_options .r-community-c-forum_sender--option").after($(".r-community-c-forum_sender--bottom_options .r-community-c-forum_sender--option").clone(true).addClass("yuque-sender")).hide(); $(".forum_editor").append(``); $("body").append(``); document.querySelector(".r-community-c-forum_sender--bottom_options .r-community-c-forum_sender--option.yuque-sender").onclick = async (e) => { let tag; e.preventDefault(); try { if (document.getElementsByClassName("r-community-c-forum_sender--title_input")[0].value.length < 5 || document.getElementsByClassName("r-community-c-forum_sender--title_input")[0].value.length > 50) { swal({ title: "错误", text: "请填写5-50字的标题", icon: "error", }); return false; } let tags = { 热门活动: 17, 积木编程乐园: 2, "工作室&师徒": 10, 你问我答: 5, 神奇代码岛: 3, 图书馆: 6, CoCo应用创作: 27, Python乐园: 11, 源码精灵: 26, NOC编程猫比赛: 13, 通天塔: 4, 灌水池塘: 7, 训练师小课堂: 28, }; tag = tags[document.getElementsByClassName("r-community-c-forum_sender--active")[0].innerText]; document.querySelector("#yuque").contentWindow.postMessage("data", "*"); // let texts, trueURL, previewContent; window.addEventListener( "message", (e) => { // console.log(e.data); if (typeof e.data === "number") { let content = `

    `; GM_xmlhttpRequest({ url: "https://api.codemao.cn/web/forums/boards/" + tag + "/posts", method: "POST", data: JSON.stringify({ title: document.getElementsByClassName("r-community-c-forum_sender--title_input")[0].value, content: content, }), 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 }) { // console.log(JSON.parse(response).id); window.open("https://shequ.codemao.cn/community/" + JSON.parse(response).id); }, }); } else { texts = e.data; previewContent = ` 预览
    `; let url, fn, token, key, upload_url; fn = "preview.html"; $.ajax({ type: "GET", url: "https://oversea-api.code.game/tiger/kitten/cdn/token/1?type=text%2Fhtml&prefix=yuque%2Fpreview&bucket=static", contentType: "application/json;charset=UTF-8", async: false, xhrFields: { withCredentials: true, }, success: function (res) { upload_url = res.bucket_url; token = res["data"][0]["token"]; key = res["data"][0]["filename"]; }, }); var formData = new FormData(); formData.append("token", token); formData.append("key", key); formData.append("fname", fn); const file = new File([previewContent], fn, { type: "text/html", }); formData.append("file", file); $.ajax({ type: "POST", url: "https://upload.qiniup.com/", async: false, contentType: false, processData: false, data: formData, success: function (res) { url = "/" + res.key; }, }); trueURL = encodeURI(upload_url + url); // console.log(trueURL); $("#preview").attr("src", encodeURI(upload_url + url)); if (document.querySelector("#preview").attachEvent) { document.querySelector("#preview").attachEvent("onload", function () { document.querySelector("#preview").contentWindow.postMessage("height", "*"); }); } else { document.querySelector("#preview").onload = function () { document.querySelector("#preview").contentWindow.postMessage("height", "*"); }; } } }, false ); } catch (err) { swal({ title: "错误", text: "请选择发帖分区!", icon: "error", }); } }; } } })();