Last active
January 4, 2022 04:46
-
-
Save thallium/0d8945d523767ecf277e65b6a6f33193 to your computer and use it in GitHub Desktop.
make 博客园(cnblog) looks clean
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name cnblog clean looking 博客园干净外观 | |
// @namespace https://blog.csdn.net/qq1337715208/article/details/108289826 | |
// @version 0.3 | |
// @description disable user js and background image | |
// @author jin & Thallium54 | |
// @match *://*.cnblogs.com/* | |
// @resource CSS main.css | |
// @grant GM_addStyle | |
// @grant GM_getResourceText | |
// @require https://common.cnblogs.com/scripts/jquery-2.2.0.min.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// 最多检测50次,找不到 loadBlogNews 就放弃 | |
let maxCheckNum = 50; | |
function check_f(){ | |
try { | |
if (typeof(loadBlogNews) == "function") { | |
return true; | |
} | |
} catch(e) { | |
return false; | |
} | |
return false; | |
} | |
function tryStopIt(){ | |
if (!check_f()){ | |
if (maxCheckNum > 0){ | |
maxCheckNum -= 1 | |
setTimeout(tryStopIt, 100); //没找到就每隔0.1秒重试 | |
} else {// 尝试50次后还没有找到,就放弃 | |
console.log("未找到,替换失败。"); | |
} | |
return; | |
} // end if (!check_f) | |
loadBlogNews = function () { | |
$.ajax({ | |
url: getAjaxBaseUrl() + "news.aspx", | |
type: "get", | |
dataType: "text", | |
success: function(n) { | |
if (n) | |
if (n.indexOf("<script") < n.indexOf("<script>getFollowStatus")) { | |
if (n.indexOf("cdn.jsdelivr.net/gh/BNDong/Cnblogs-Theme-SimpleMemory") >= 0) { | |
var t = n.match(/GhUserName *: *['"](\w+)['"]/); | |
(t === null || t[1].toUpperCase() === "BNDong".toUpperCase()) && (n = n.replace(/(GhVersions *: *["'])v1\.([0-1]\.\d+|2\.[0-5].*?),*/g, "$1v1.2.6").replace(/(Cnblogs-Theme-SimpleMemory@)v1\.([0-1]\.\d+|2\.[0-5])/gi, "$1v1.2.6")) | |
} | |
$.getScript(location.protocol + "//common.cnblogs.com/script/jquery.writeCapture-min.js", function() { | |
let reg1 = new RegExp("[\\r\\n]", "g"); | |
let reg2 = new RegExp("<script.*?>.*?window\\.requestAnimationFrame.*?</script>","g"); | |
let filted_content = n.replace(reg1," "); | |
filted_content = filted_content.replace(reg2, " "); | |
let reg3 = new RegExp("<script.+?src=[\"'](.+?)[\"'].*?>.*?</script>","g"); | |
filted_content = filted_content.replace(reg3, function(subtxt, cat1, pian, txt){ | |
let bad = false; | |
$.ajax({ | |
url:cat1, | |
type:"get", | |
dataType:"text", | |
async:false, | |
success:function(resp){ | |
resp = resp.replace(reg1, " "); | |
let reg4 = new RegExp("<script.*?>.*?window\\.requestAnimationFrame.*?</script>","g"); | |
//let reg5 = new RegExp("<script.+?src=[\"'].+?[\"'].*?>.*?</script>","g"); | |
if (reg4.exec(resp)) { | |
bad = true; | |
} | |
} | |
}); | |
if (bad) { | |
return " "; | |
} | |
return subtxt; | |
}); | |
/// | |
console.alert("debug : " + filted_content); | |
$("#sidebar_news").writeCapture().html(filted_content).show(); | |
}) | |
} else | |
n.indexOf("错误提示:发生了异常") < 0 && $("#sidebar_news").html(n).show(); | |
} | |
}) // end $.ajax | |
} //end loadBlogNews | |
console.log("成功地替换了 loadBlogNews"); | |
return; | |
} | |
tryStopIt(); | |
var style = GM_getResourceText("CSS"); | |
GM_addStyle(style); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@media (prefers-color-scheme: dark) { | |
body { | |
background-image: none !important; | |
background-color: #131516; | |
} | |
} | |
@media (prefers-color-scheme: light) { | |
body { | |
background-color: #d8dee9 !important; | |
background-image: none !important; | |
} | |
} | |
#blogTitle { | |
display: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment