-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrandom-theme-button.js
42 lines (40 loc) · 2.14 KB
/
random-theme-button.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
// Random Theme Button
// version 2022.10.2
// https://forum.vivaldi.net/topic/34767/random-theme-button
// Load a random theme when clicking a command chain button.
(function randomTheme() {
function randomize() {
vivaldi.prefs.get("vivaldi.themes.current", (current) => {
vivaldi.prefs.get("vivaldi.themes.user", (collection) => {
if (collection.length > 1) {
let rd = "";
while (rd === "" || rd.id === current) {
rd = collection[Math.floor(Math.random() * collection.length)];
}
vivaldi.prefs.set({ path: "vivaldi.themes.current", value: rd.id });
} else {
console.log(
"Please create additional themes in vivaldi://settings/themes"
);
}
});
});
}
let appendChild = Element.prototype.appendChild;
Element.prototype.appendChild = function () {
if (this.tagName === "BUTTON") {
setTimeout(
function () {
if (
this.title === "Random Theme" &&
this.classList.contains("ToolbarButton-Button")
) {
this.innerHTML = `<span><svg width="18" height="18" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" style="width:18px;height:18px"><path d="M403.8 34.4c12-5 25.7-2.2 34.9 6.9l64 64c6 6 9.4 14.1 9.4 22.6s-3.4 16.6-9.4 22.6l-64 64c-9.2 9.2-22.9 11.9-34.9 6.9s-19.8-16.6-19.8-29.6V160H352c-10.1 0-19.6 4.7-25.6 12.8L284 229.3 244 176l31.2-41.6C293.3 110.2 321.8 96 352 96h32V64c0-12.9 7.8-24.6 19.8-29.6zM164 282.7L204 336l-31.2 41.6C154.7 401.8 126.2 416 96 416H32c-17.7 0-32-14.3-32-32s14.3-32 32-32H96c10.1 0 19.6-4.7 25.6-12.8L164 282.7zm274.6 188c-9.2 9.2-22.9 11.9-34.9 6.9s-19.8-16.6-19.8-29.6V416H352c-30.2 0-58.7-14.2-76.8-38.4L121.6 172.8c-6-8.1-15.5-12.8-25.6-12.8H32c-17.7 0-32-14.3-32-32s14.3-32 32-32H96c30.2 0 58.7 14.2 76.8 38.4L326.4 339.2c6 8.1 15.5 12.8 25.6 12.8h32V320c0-12.9 7.8-24.6 19.8-29.6s25.7-2.2 34.9 6.9l64 64c6 6 9.4 14.1 9.4 22.6s-3.4 16.6-9.4 22.6l-64 64z"/></svg></span>`;
this.addEventListener("click", randomize);
}
}.bind(this, arguments[0])
);
}
return appendChild.apply(this, arguments);
};
})();