-
Notifications
You must be signed in to change notification settings - Fork 2
/
YouTube View Counter.user.js
55 lines (51 loc) · 1.68 KB
/
YouTube View Counter.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function has(a, b) {
try {
if (a.indexOf(b) > -1) {
return true
}
} catch (c) {}
return false
}
document.getElementByXPath = function(c) {
var b = this.evaluate(c, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (b.snapshotLength > 0) {
return b.snapshotItem(0)
}
};
document.getElementsByXPath = function(e) {
var d = new Array();
var b = this.evaluate(e, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (var c = 0; c < b.snapshotLength; c++) {
d.push(b.snapshotItem(c))
}
return d
};
function waitForElementToDisplay(a, b) {
if (document.querySelector(a) != null) {
console.log(a + " found");
return
} else {
setTimeout(function() {
waitForElementToDisplay(a, b)
}, b)
}
}
function waitForElementToDisplayWithXpath(a, b) {
if (document.getElementByXPath(a) != null) {
console.log(a + " found");
return
} else {
setTimeout(function() {
waitForElementToDisplayWithXpath(a, b)
}, b)
}
};
function getVal(e) {
return multiplier = e.substr(-1).toLowerCase(), "k" == multiplier ? 1e3 * parseFloat(e) : "m" == multiplier ? 1e6 * parseFloat(e) : void 0
}
//*[@id='metadata-line']//*[contains(text(), 'views')]
a = document.getElementsByXPath("//*[@id='metadata-line']//*[contains(text(), 'views')]")
for (var i = 0; i < a.length; i++) {
console.log(getVal(a[i].textContent.replace(' views', '')),
document.getElementByXPath("(//a[@id='video-title' and contains(@href, 'watch?')])[" + (i + 1).toString() + "]").href)
}