-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject.js
101 lines (91 loc) · 3.08 KB
/
inject.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function load() {
// Check if its a playlist page
var intervalId = setInterval(function() {
var tracksSummaryElement = document.querySelector('.fullHero__tracksSummary');
if (tracksSummaryElement) {
clearInterval(intervalId);
inject(); // It is a playlist
}
// Check multiple times
if (intervalId.checkCount === undefined) {
intervalId.checkCount = 0;
}
intervalId.checkCount++;
if (intervalId.checkCount >= 30) {
clearInterval(intervalId);
}
}, 100);
}
function inject() {
// Get target
var container = document.getElementsByClassName('fullHero__foreground')[0];
// Make div with button
var div = document.createElement("div");
var button = document.createElement("button");
button.innerHTML = "Autoload";
// Style the button
var style = document.createElement('style');
style.innerHTML =
'.autoload_button button {' +
'height: 5.5em;' +
'width: 5.5em;' +
'color: #ffffff;' +
'background-color: #ff5500;' +
'border-style: none;' +
'border-radius: 50%;' +
'box-shadow: none;' +
'margin-top: 6em;' +
'margin-left: 1.75em;' +
'}' +
'.autoload_button button:hover {' +
'background-color: #ff3300;' +
'}' +
'.autoload_button button:disabled {' +
'background-color: #333333;' +
'opacity: 0.5;' +
'}'
;
document.head.appendChild(style)
div.setAttribute('class', 'autoload_button');
// Add it to the target
container.appendChild(div);
div.appendChild(button);
// Disable if we don't need to load anything
var trackAmount = parseInt(document.querySelector('.genericTrackCount__title').textContent);
if (trackAmount <= 15) {
button.disabled = true;
}
// Add click Function
const buttonOnClick = () => {
button.disabled = true;
scroll();
loop();
function loop() {
setTimeout(function() {
var lastTrackElement = document.querySelector('ul.trackList__list li:last-child');
var numberElement = lastTrackElement.querySelector(".trackItem__number");
if (numberElement && numberElement.textContent) {
var numberText = numberElement.textContent.trim();
var numberValue = parseInt(numberText);
// Keep looping if we haven't reached the bottom
if (trackAmount > numberValue) {
scroll()
}
// At the bottom, one last scroll
if (trackAmount == numberValue) {
scroll()
return;
}
}
loop();
}, 250)
}
};
button.addEventListener('click', buttonOnClick);
}
function scroll() {
window.scrollTo({
top: document.documentElement.scrollHeight
});
}
load();