Files
fuck-csdn-blog/js/script.js
2024-09-27 01:17:30 +08:00

93 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 版权所有bmy
* 邮箱2271608011@qq.com
* 备注:代码没啥好看的,写给自己用
*/
setTimeout(() => {
let currentURL = location.href;
let webSiteUrl = {
csdn: "blog.csdn.net",
zhihu: {
home: "www.zhihu.com",
zhuanlan: "zhuanlan.zhihu.com",
},
jianshu: "www.jianshu.com",
juejin: "juejin.cn",
};
let clearHref = (el, tarAttr = "?target=") => {
$(el)
.eq(0)
.find("a")
.each(function () {
let href = $(this).attr("href");
if (href != undefined && href.includes(tarAttr)) {
// 针对掘金的一些特殊情况进行处理href会莫名其妙多出一次target
if ( (href.split("target").length - 1) == 2) {
let url = decodeURIComponent(decodeURIComponent(href).split("?target=")[2])
$(this).attr("href", url);
} else {
$(this).attr("href", decodeURIComponent(href.split(tarAttr)[1]));
}
}
});
};
let clearCopy = (el) => {
let newArticle = $(el).eq(0).clone();
$(el).eq(0).replaceWith(newArticle);
};
if (currentURL.includes(webSiteUrl.csdn)) {
// 分析源网站的代码,链接是这个:
// https://csdnimg.cn/release/blogv2/dist/pc/js/detail-0ce0e42bff.min.js
// https://csdnimg.cn/release/blogv2/dist/pc/js/detail-4c4f40c1d8.min.js
// https://g.csdnimg.cn/common/csdn-toolbar/csdn-toolbar.js
// 自动展开所有折叠的代码
$(".hide-preCode-bt").click();
window.articleType = -1;
window.copyPopSwitch = false;
clearCopy("#content_views");
// 重新修复文章正文a标签的所有点击事件
$("#content_views").on("click", "a", function (t) {
var a = $(this).attr("href") || "";
t.preventDefault();
window.open(a, "_blank");
});
} else if (
currentURL.includes(webSiteUrl.zhihu.zhuanlan) ||
currentURL.includes(webSiteUrl.zhihu.home)
) {
// 展开问题的全文
$(".QuestionRichText-more").click();
// 展开阅读全文​ 需要登录才可以
$(".ContentItem-expandButton").click();
clearHref("body");
let eachContent = () =>
$(".RichContent").each(function () {
clearCopy(this);
});
eachContent();
let Observe = new MutationObserver((mutations, observer) => eachContent());
Observe.observe($(".css-0")[0], { childList: true, attributes: true });
} else if (currentURL.includes(webSiteUrl.jianshu)) {
clearCopy("div[role=main] section");
clearHref("div[role=main] section", "?t=");
} else if (currentURL.includes(webSiteUrl.juejin)) {
clearCopy("#article-root");
clearHref(".main-area .article")
}
}, 300);