forked from ywzhaiqi/userscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TiebaNojump.user.js
37 lines (30 loc) · 1007 Bytes
/
TiebaNojump.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// ==UserScript==
// @name TiebaNojump
// @namespace https://github.com/ywzhaiqi
// @include http://tieba.baidu.com/p/*
// @version 1.1
// @grant none
// ==/UserScript==
function run() {
var urls = document.querySelectorAll('a[href^="http://jump.bdimg.com/safecheck"]');
for (var i = 0; i < urls.length; i++) {
var url = urls[i].textContent;
if (url.indexOf("http") == -1)
url = "http://" + url;
urls[i].setAttribute("href", url);
}
}
function addMutationObserver(selector, callback) {
var watch = document.querySelector(selector);
if (!watch) return;
var observer = new MutationObserver(function(mutations){
var nodeAdded = mutations.some(function(x){ return x.addedNodes.length > 0; });
if (nodeAdded) {
// observer.disconnect();
callback();
}
});
observer.observe(watch, {childList: true, subtree: true});
}
run();
addMutationObserver('#j_p_postlist', run);