Skip to content

Instantly share code, notes, and snippets.

@bigshans
Created October 7, 2018 07:57
Show Gist options
  • Save bigshans/7b7b1c2c7896853a39ee7d573fd5097b to your computer and use it in GitHub Desktop.
Save bigshans/7b7b1c2c7896853a39ee7d573fd5097b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name bilibili 评论区可点击
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author BigShans
// @match https://h.bilibili.com/*
// @match https://t.bilibili.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function ans(html) {
var regexp = /((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/ig;
function replaceReg(reg,str){
return str.replace(reg,function(m){return '<a href="'+m+'" style="color:#00a1d6;" class="dynamic-link-hover-bg" target="_blank">'+m+'</a>';})
}
return replaceReg(regexp, html.innerHTML);
}
function bind(comment_list) {
console.log(comment_list);
}
function listen_reply(node){
var observer = new MutationObserver(function (mutations, observer){
mutations.forEach(function(mutation){
var array = mutation.addedNodes;
array.forEach(function(node){
var text = node.getElementsByClassName('text-con')[0];
if (text !== undefined) {
console.log(ans(text));
text.innerHTML = ans(text);
}
})
})
});
var options = {
'childList': true
}
observer.observe(node, options);
}
function listen() {
var comment_list = document.querySelector('.comment-list');
if (comment_list === undefined || comment_list === null) {
setTimeout(listen, 100);
return ;
}
var observer = new MutationObserver(function (mutations, observer) {
mutations.forEach(function(mutation) {
var array = mutation.addedNodes;
array.forEach(function(node){
var text = node.getElementsByClassName('text')[0];
var reply = node.getElementsByClassName('reply-box')[0];
if (reply !== undefined) {
listen_reply(reply);
}
if (text !== undefined) {
//console.log(ans(text));
text.innerHTML = ans(text);
}
})
});
});
var options = {
'childList': true,
'attributes': true,
'characterData': true
}
observer.observe(comment_list, options);
}
listen();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment