-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe3-messy-post-purifier.user.js
More file actions
59 lines (54 loc) · 1.95 KB
/
e3-messy-post-purifier.user.js
File metadata and controls
59 lines (54 loc) · 1.95 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// ==UserScript==
// @name E3 Messy Post Purifier
// @namespace https://e3p.nycu.edu.tw/
// @version 0.6
// @description omg
// @author CSY54
// @match https://e3p.nycu.edu.tw/theme/dcpc/news/news_view.php*
// @match https://e3p.nycu.edu.tw/mod/forum/view.php*
// @match https://e3p.nycu.edu.tw/mod/dcpcforum/view.php*
// @match https://e3p.nycu.edu.tw/mod/dcpcforum/discuss.php*
// @match https://e3p.nycu.edu.tw/mod/dcpcforum/index.php*
// @match https://e3p.nycu.edu.tw/course/view.php*
// @match https://e3p.nycu.edu.tw/mod/folder/view.php*
// @updateURL https://github.com/CSY54/tampermonkey-userscripts/raw/master/e3-messy-post-purifier.user.js
// @downloadURL https://github.com/CSY54/tampermonkey-userscripts/raw/master/e3-messy-post-purifier.user.js
// ==/UserScript==
;(() => {
function purifyDOM(node) {
const res = document.createElement(node.tagName)
node.classList.forEach((className) => {
res.classList.add(className)
})
for (const childNode of node.childNodes) {
switch (childNode.nodeType) {
case Node.TEXT_NODE: {
const curNode = document.createTextNode(childNode.textContent)
res.appendChild(curNode)
break
}
case Node.ELEMENT_NODE: {
if (['IMG', 'VIDEO'].includes(childNode.tagName)) {
res.appendChild(childNode)
break
}
const curNode = purifyDOM(childNode)
if (curNode.tagName === 'A') {
curNode.classList.add('aalink')
curNode.href = childNode.href
curNode.target = childNode.target
}
res.appendChild(curNode)
break
}
default:
console.info('ignore node:', childNode)
}
}
return res
}
const elements = document.querySelectorAll('div.no-overflow')
for (const e of elements) {
e.parentNode.replaceChild(purifyDOM(e), e)
}
})()