forked from Krazete/bookmarklets
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathytsentiment.js
More file actions
21 lines (21 loc) · 792 Bytes
/
ytsentiment.js
File metadata and controls
21 lines (21 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Array.from(document.getElementsByTagName("ytd-video-renderer"))
.concat(Array.from(document.getElementsByTagName("ytd-grid-video-renderer")))
.concat(Array.from(document.getElementsByTagName("ytd-compact-video-renderer")))
.forEach(function(e) {
var link = e.querySelector("#thumbnail").href;
var xhr = new XMLHttpRequest();
xhr.open("GET", link, true);
xhr.onload = function() {
var match = this.responseText.match(/"percentIfIndifferent":(\d+),/);
var rating = parseInt(Math.pow(match[1] / 100, Math.E) * 256);
e.style.background = "rgb(" + (256 - rating) + ", " + rating + ", 0)";
setTimeout(function() {
e.style.transition = "background 1s";
e.style.background = "";
}, 10000);
setTimeout(function() {
e.style.transition = "";
}, 1000);
};
xhr.send();
});