Created
July 21, 2022 04:46
-
-
Save KrisCris/e615e0c006ee483881011d0513e0a487 to your computer and use it in GitHub Desktop.
PreventBiliBiliReplyJumpURL, 禁用b站评论区自动话题 (带蓝色搜索icon超链接的词条)
This file contains hidden or 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 禁用b站评论区自动话题 (带蓝色搜索icon超链接的词条) | |
// @namespace https://greasyfork.org/zh-CN/scripts/447612-%E5%B9%B2%E6%8E%89%E6%96%B0%E7%89%88b%E7%AB%99%E8%AF%84%E8%AE%BA%E5%8C%BA%E7%9A%84%E6%90%9C%E7%B4%A2-%E6%94%BE%E5%A4%A7%E9%95%9C-%E8%93%9D%E5%AD%97-%E5%8A%9F%E8%83%BD | |
// @version 1.0 | |
// @description 禁用b站评论区自动话题 (带蓝色搜索icon超链接的词条) | |
// @author DuckBurnIncense, MODIFIED BY KrisCris | |
// @match *://www.bilibili.com/video/* | |
// @icon https://www.bilibili.com/favicon.ico | |
// @grant none | |
// @homepage //duckburnincense.ml/ | |
// @supportURL https://www.bilibili.com/video/BV1SS4y1E7xB | |
// @supportURL https://space.bilibili.com/12184831 | |
// @license MIT | |
// @run-at document-end | |
// ==/UserScript== | |
const removeHashTag = () => { | |
const reg = /^(?:<a.*?>)(.*)(?:<\/a>)$/gim; | |
// 啊b天天改class名来屏蔽我脚本, 只好改成黑名单模式了 | |
const searchWordQueries = [ | |
'a.jump-url-link.underline-word', | |
'a.underline-link.comment-jump-url', | |
'a.jump-link.search-word', | |
]; | |
const searchIconQueries = [ | |
'i.jump-url-prefix.search-word', | |
'i.underline.jump-img', | |
'i.icon.search-word', | |
]; | |
searchWordQueries.forEach(query => { | |
let searchWords = document.querySelectorAll(query); | |
searchWords.forEach(item => { | |
item.outerHTML = item.outerHTML.replace(reg, '$1'); | |
}); | |
}); | |
searchIconQueries.forEach(query => { | |
let searchIcons = document.querySelectorAll(query); | |
searchIcons.forEach(item => { | |
item.outerHTML = ''; | |
}); | |
}); | |
} | |
const addXMLRequestCallback = (callback) =>{ | |
var oldSend, i; | |
if( XMLHttpRequest.callbacks ) { | |
// we've already overridden send() so just add the callback | |
XMLHttpRequest.callbacks.push( callback ); | |
} else { | |
// create a callback queue | |
XMLHttpRequest.callbacks = [callback]; | |
// store the native send() | |
oldSend = XMLHttpRequest.prototype.send; | |
// override the native send() | |
XMLHttpRequest.prototype.send = function(){ | |
// process the callback queue | |
// the xhr instance is passed into each callback but seems pretty useless | |
// you can't tell what its destination is or call abort() without an error | |
// so only really good for logging that a request has happened | |
// I could be wrong, I hope so... | |
// EDIT: I suppose you could override the onreadystatechange handler though | |
for( i = 0; i < XMLHttpRequest.callbacks.length; i++ ) { | |
XMLHttpRequest.callbacks[i]( this ); | |
} | |
// call the native send() | |
oldSend.apply(this, arguments); | |
} | |
} | |
} | |
addXMLRequestCallback( function( xhr ) { | |
xhr.addEventListener("load", function(){ | |
if ( xhr.readyState == 4 && xhr.status == 200 ) { | |
// console.log( xhr.responseURL ); | |
if ( xhr.responseURL.includes("api.bilibili.com/x/v2/reply/") ) { | |
console.log(xhr); | |
removeHashTag(); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment