-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkdice-mobile-bookmarklet.js
42 lines (34 loc) · 1.53 KB
/
kdice-mobile-bookmarklet.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
javascript:(function () {
/* Adds CSS script and viewport meta tags into html head */
const s = document.createElement('link');
s.setAttribute('href', 'https://cdn.jsdelivr.net/gh/tomas223/kdice-mobile@8c2dbf7eac925846c8d261bca2bbe222eb33b5e1/styles/kdice-mobile-style.css');
s.setAttribute('rel', 'stylesheet');
s.setAttribute('type', 'text/css');
const m = document.createElement('meta');
m.setAttribute('name', 'viewport');
m.setAttribute('content', 'width=615,shrink-to-fit=yes');
document.getElementsByTagName('head')[0].appendChild(m);
document.getElementsByTagName('head')[0].appendChild(s);
/* Adds auto end-turn checkbox */
const btn = document.querySelector('.iogc-Controls button');
const lbl = document.createElement('label');
const txt = document.createTextNode('Auto End-Turn');
const chckbx = document.createElement('input');
chckbx.setAttribute('type', 'checkbox');
lbl.appendChild(chckbx);
lbl.appendChild(txt);
document.querySelector('.iogc-Controls').appendChild(lbl);
const btnObserver = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (
mutation.attributeName === 'aria-hidden'
&& btn.getAttribute('aria-hidden') === null
&& chckbx.checked
) {
setTimeout(() => btn.click(), 100);
}
}
});
btnObserver.observe(btn, { attributes: true });
console.log('custom Kdice mobile script injected');
})();