-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
40 lines (36 loc) · 1007 Bytes
/
content.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
38
39
40
function parseAndReplaceComments () {
let times = 0;
let video;
if (video = document.querySelector('video')) {
video.remove();
}
[].slice.call(document.querySelectorAll('.comment-renderer-text-content'))
.filter(function (commentNode) {
times += 1;
return /*times < 10 &&*/ !commentNode.getAttribute('data-yourude-parsed');
})
.forEach(function (commentNode) {
let urlToFetch = 'https://yourude.com?text=' + encodeURIComponent(commentNode.innerText);
commentNode.setAttribute('data-yourude-parsed', 1);
fetch(urlToFetch)
.then(function (res) {
return res.json();
})
.then(function (responseJson) {
if (!responseJson.isChanged) {
return;
}
// TODO
commentNode.style.color = 'green';
commentNode.setAttribute('title', commentNode.innerText);
commentNode.innerText = responseJson.text;
})
// .err(function (res) {
//
// })
;
})
;
}
parseAndReplaceComments();
setInterval(parseAndReplaceComments, 1000);