Skip to content

Instantly share code, notes, and snippets.

@bigshans
Created October 5, 2018 05:37
Show Gist options
  • Save bigshans/49488bb56a27695a1f3e52d7dadbc279 to your computer and use it in GitHub Desktop.
Save bigshans/49488bb56a27695a1f3e52d7dadbc279 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name bilibili click
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 链接可点击
// @author Bigshans
// @match https://h.bilibili.com/*
// @match https://t.bilibili.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 问题在于要不要加入中文,加入显示效果不是很好,暂去除
function rep() {
var cl = document.getElementsByClassName('discription')[0] || document.getElementsByClassName('content-ellipsis')[0];
if (cl === undefined) {
setTimeout(rep, 500);
return ;
}
var context = cl.innerHTML;
console.log('pass');
if (context === '')
setTimeout(rep, 500);
else {
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:blue;">'+m+'</a>';})
}
console.log('exe');
console.log(replaceReg(regexp, context));
cl.innerHTML = replaceReg(regexp, context);
}
}
rep();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment