-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinjector.js
More file actions
executable file
·97 lines (82 loc) · 2.9 KB
/
injector.js
File metadata and controls
executable file
·97 lines (82 loc) · 2.9 KB
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
(function () {
'use strict';
var BTN_ID = 'kometaThemesBtn';
var BTN_CLASS = 'button-flat btnKometaThemes detailButton';
var observer = null;
var injDebounce = null;
function isDetailPage() {
return (window.location.hash || '').indexOf('/details') > -1;
}
function getItemId() {
try {
var h = window.location.hash || '';
var qs = h.split('?')[1] || '';
return new URLSearchParams(qs).get('id') || null;
} catch (e) {
return null;
}
}
function createButton() {
var btn = document.createElement('button');
btn.id = BTN_ID;
btn.setAttribute('is', 'emby-button');
btn.type = 'button';
btn.className = BTN_CLASS;
btn.title = 'KometaThemes';
var div = document.createElement('div');
div.className = 'detailButton-content';
var span = document.createElement('span');
span.className = 'material-icons detailButton-icon music_note';
span.setAttribute('aria-hidden', 'true');
span.style.color = '#00a4dc';
div.appendChild(span);
btn.appendChild(div);
return btn;
}
function injectButton() {
if (!isDetailPage()) return false;
// Always remove old button — item ID may have changed
var old = document.getElementById(BTN_ID);
if (old) old.remove();
var container = document.querySelector('.mainDetailButtons');
if (!container) return false;
var itemId = getItemId();
if (!itemId) return false;
var moreBtn = container.querySelector('.btnMoreCommands');
var btn = createButton();
btn.addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
try {
Dashboard.navigate('configurationpage?name=KometaThemesSearch&itemId=' + itemId);
} catch (ex) {
window.location.hash = '#!/configurationpage?name=KometaThemesSearch&itemId=' + itemId;
}
});
if (moreBtn) {
container.insertBefore(btn, moreBtn);
} else {
container.appendChild(btn);
}
return true;
}
function tryInject() {
if (!isDetailPage()) return;
clearTimeout(injDebounce);
injDebounce = setTimeout(function () {
injectButton();
}, 200);
}
// Observe DOM changes
observer = new MutationObserver(tryInject);
observer.observe(document.body, { childList: true, subtree: true });
// Handle navigation
window.addEventListener('hashchange', function () {
// On hash change, remove old button and let observer recreate
var old = document.getElementById(BTN_ID);
if (old) old.remove();
// Observer will pick up the new DOM and reinject
});
// Initial injection
injectButton();
})();