// ==UserScript== // @name cmgreener // @namespace http://tampermonkey.net/ // @version 1.0.1 // @description greener for shequ.codemao.cn // @author Albert Z // @include *://shequ.codemao.cn/* // @icon https://static.codemao.cn/whitef/favicon.ico // @license MIT // @grant none // @downloadURL none // ==/UserScript== var removes = {}; removes['shequ.codemao.cn/course'] = ['r-course--banner']; removes['shequ.codemao.cn/discover'] = []; removes['shequ.codemao.cn/work_shop'] = ['r-work_shop--banner']; removes['shequ.codemao.cn/community'] = ['r-community--bulletin_container', 'r-community--notic_item_icon_hot', 'c-post_list--status_icon c-post_list--hot', 'c-post_list--status_icon c-post_list--up', 'r-community--roules_btn' ]; removes['shequ.codemao.cn/mall'] = ['r-mall-r-home--banner']; removes['shequ.codemao.cn/gallery'] = ['r-gallery--banner']; removes['shequ.codemao.cn'] = ['r-home--guide_part', 'r-home-c-workshop_area--workshop_work']; window.onload = function () { // 重定向anchor标签 var anchors = [...document.getElementsByClassName('c-navigator--nav_wrap')[0].getElementsByTagName('a')].slice(0, 7); for (var i = 0; i < anchors.length; i++) { var a = anchors[i]; let url = a.href; a.onclick = function () {window.location.href = url;}; } // 论坛区延迟执行(适应XHR) if (window.location.href.indexOf('shequ.codemao.cn/community') > -1) { setTimeout(function () { let url = 'shequ.codemao.cn/community'; for (let cn in removes[url]) { var ele = document.getElementsByClassName(removes[url][cn]); if (ele.length) { // 隐藏元素 for (var i = 0; i < ele.length; i++) { ele[i].style.display = 'none'; } // 增加上边距 if (window.location.href != 'https://shequ.codemao.cn/community') { var main = document.getElementsByClassName('r-index--main_cont')[0]; main.style.marginTop = '5%'; } } } }, 1000); // 解析屏蔽词 if (window.location.href.startsWith('https://shequ.codemao.cn/community/')) { var id = window.location.href.replace('https://shequ.codemao.cn/community/', ''); var httpRequest = new XMLHttpRequest(); httpRequest.open('GET', 'https://api.codemao.cn/web/forums/posts/' + id + '/details', true); httpRequest.send(); httpRequest.onreadystatechange = function () { if (httpRequest.readyState == 4 && httpRequest.status == 200) { var data = eval('(' + httpRequest.responseText + ')'); var content = document.getElementsByClassName('r-community-r-detail--forum_content')[0]; content.innerHTML = data.content; } }; // 重新高亮代码 setTimeout(function () { Prism.highlightAll(); }, 1000); } // 其余页面 } else { for (let url in removes) { if (window.location.href.indexOf(url) > -1) { for (let cn in removes[url]) { var ele = document.getElementsByClassName(removes[url][cn]); if (ele.length) { // 隐藏部分元素 for (var i = 0; i < ele.length; i++) { ele[i].style.display = 'none'; } // 增加上边距 if (window.location.href != 'https://shequ.codemao.cn/' && window.location.href != 'https://shequ.codemao.cn/community') { var main = document.getElementsByClassName('r-index--main_cont')[0]; main.style.marginTop = '5%'; } } } } } } };