Last active
May 11, 2022 08:13
-
-
Save chenx6/d715c93ccc06d9f03c9f1db0ee9b747d to your computer and use it in GitHub Desktop.
去他妈的转载狗
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 去他妈的转载狗 | |
// @namespace Violentmonkey Scripts | |
// @match https://cn.bing.com/search* | |
// @grant GM_xmlhttpRequest | |
// @version 1.0 | |
// @author chen_null | |
// @description 2021/1/21 下午4:14:58 | |
// ==/UserScript== | |
// https://csdnimg.cn/release/blogv2/dist/pc/img/reprint.png | |
let reprintPictureRegex = /https:\/\/.+reprint\.png/; // CSDN 转载文章图片链接 | |
let vipArticleRegex = /https:\/\/.+identityVip.png/; | |
let csdnUrlRegex = /https:\/\/.+\.csdn\.net/; // CSDN 正则 | |
let garbageSite = [/www\.jb51\.net/, | |
/qastack\.cn/, | |
/www\.codenong\.com/, | |
/cn\.voidcc\.com/, | |
/www\.phpfans\.net/, | |
/cloud\.tencent\.com\/developer\/information/, | |
/www\.yiibai\.com/, | |
/download\.csdn\.net/, | |
/www\.gitmemory\.com/]; // 垃圾网站正则 | |
let debug = true; | |
function debugLog(message) { | |
if (debug) { | |
console.log(message); | |
} | |
} | |
/** | |
* 获取内容,看下是否为转载文章 | |
* @param {string} url 请求 URL | |
*/ | |
function asyncCsdnFilter(url) { | |
return new Promise((resolve, reject) => { | |
// 找到 URL,并且看下是不是 CSDN 的 | |
if (url.search(csdnUrlRegex) == -1) { | |
return resolve(false); | |
} | |
debugLog("找到 CSDN 网址 " + url); | |
// 发起请求,看下是不是转载的 | |
GM_xmlhttpRequest({ | |
"method": "GET", | |
"headers": { | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0", | |
"Accept-Language": "zh-CN,zh;q=0.8", | |
"Referer": "https://cn.bing.com" | |
}, | |
"url": url, | |
"onload": (response) => { | |
// 看下有没有“转载”的图片标识 | |
// 找到了脑瘫 VIP 文章 | |
if (response.responseText.search(reprintPictureRegex) !== -1 | |
|| response.responseText.search(vipArticleRegex) !== -1) { | |
debugLog("找到了死妈转载狗 " + url); | |
return resolve(true); | |
} | |
return resolve(false); | |
}, | |
"onerror": (response) => { | |
let status = response.statusText; | |
console.error("Fetch error %s", status); | |
return reject(new Error(status)); | |
} | |
}); | |
}) | |
} | |
/** | |
* 去除链接,加上警示标志 | |
* @param {HTMLElement} node 要删除的节点 | |
*/ | |
function removeShit(node) { | |
node.textContent = "别看了,是司马转载狗拉的屎!"; | |
node.parentElement.parentElement.style.textDecoration = "line-through"; | |
} | |
document.querySelectorAll(".sh_favicon").forEach((node) => { | |
let url = node.href; | |
// 首先,去除垃圾站的内容 | |
if (garbageSite | |
.map((value, index, array) => { return url.search(value) != -1; }) | |
.findIndex((value) => { return value === true; }) != -1) { | |
removeShit(node); | |
} | |
asyncCsdnFilter(url) | |
.then((value) => { | |
if (value === true) { | |
removeShit(node); | |
} | |
}) | |
.catch((reason) => { debugLog(reason); }); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment