Repository navigation
Expand file tree
/
Copy path+attention.js
More file actions
232 lines (214 loc) · 10.2 KB
/
Copy path+attention.js
File metadata and controls
232 lines (214 loc) · 10.2 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
(function () {
'use strict';
// Додаємо переклади для підказок
Lampa.Lang.add({
hints_torrents: {
ru: "Видео не загружается или тормозит? Попробуйте выбрать другую раздачу.",
en: "Video not loading or lagging? Try a different torrent.",
uk: "Відео не завантажується чи гальмує? Спробуйте іншу роздачу."
},
hints_online: {
ru: "Видео не загружается или тормозит? Попробуйте выбрать другой источник или озвучку.",
en: "Video not loading or lagging? Try a different source or audio track.",
uk: "Відео не завантажується чи гальмує? Спробуйте інше джерело або озвучення."
},
hints_incard: {
ru: "Информация о фильме может появиться раньше, чем он станет доступен для просмотра.",
en: "A film may appear in the catalog before it's available to watch.",
uk: "Інформація про фільм може з’явитися раніше, ніж він стане доступним для перегляду."
},
hints_plugin_title: {
ru: "Підказки завантаження",
en: "Loading hints",
uk: "Підказки завантаження"
},
hints_online_subtitle: {
ru: "Підказка при онлайн-перегляді",
en: "Hint for online viewing",
uk: "Підказка при онлайн-перегляді"
},
hints_torrents_subtitle: {
ru: "Підказка при торрентах",
en: "Hint for torrents",
uk: "Підказка при торрентах"
},
hints_incard_subtitle: {
ru: "Підказка в картці фільму",
en: "Hint in movie card",
uk: "Підказка в картці фільму"
}
});
// Конфігурація підказок
var CONFIG = {
online: {
id: 'hint-online-banner',
showDuration: 3000,
fadeDuration: 500,
repeat: false
},
torrents: {
id: 'hint-torrent-banner',
showDuration: 4000,
fadeDuration: 500,
repeat: false
},
incard: {
id: 'hint-incard-banner',
showDuration: 4000,
fadeDuration: 500,
repeat: false
}
};
// Функція створення банера підказки (для онлайн і торрентів)
function createHintText(hintText, id) {
return '<div id="' + id + '" style="overflow: hidden; display: flex; align-items: center; background-color: rgba(0, 0, 0, 0.07); border-radius: 0.5em; margin-left: 1.2em; margin-right: 1.2em; padding: 0.8em; font-size: 1.2em; transition: opacity 0.5s; line-height: 1.4;">' + hintText + '</div>';
}
// Функція створення банера підказки в картці фільму
function createHintText_incard(hintText, id) {
return '<div id="' + id + '" style="overflow: hidden; display: flex; align-items: center; background-color: rgba(0, 0, 0, 0.15); border-radius: 0.5em; margin-bottom: 1.2em; padding: 0.8em; font-size: 1.2em; transition: opacity 0.5s; line-height: 1.4;">' + hintText + '</div>';
}
// Функція плавного зникнення та видалення елемента
function fadeOutAndRemove($el, duration) {
var height = $el[0].scrollHeight;
$el.css({
maxHeight: height + 'px',
overflow: 'hidden'
});
// Примусово викликаємо reflow
$el[0].offsetHeight;
$el.css({
transition: 'opacity ' + duration + 'ms, max-height ' + duration + 'ms, margin-bottom ' + duration + 'ms, padding ' + duration + 'ms',
opacity: '0',
maxHeight: '0px',
marginBottom: '0px',
paddingTop: '0px',
paddingBottom: '0px'
});
setTimeout(function () {
$el.remove();
}, duration + 50);
}
// Очікування появи елемента в DOM
function waitForElement(selector, callback) {
var check = function () {
var el = document.querySelector(selector);
if (el) {
callback(el);
return true;
}
return false;
};
if (typeof MutationObserver !== 'undefined') {
if (check()) return;
var observer = new MutationObserver(function () {
if (check()) observer.disconnect();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
} else {
var interval = setInterval(function () {
if (check()) clearInterval(interval);
}, 500);
}
}
// Основна функція ініціалізації підказок
function initializeHintFeature() {
var shown = {
online: false,
torrents: false,
incard: false
};
Lampa.Storage.listener.follow('change', function (event) {
if (event.name === 'activity') {
var component = Lampa.Activity.active().component;
// Підказка для онлайн-перегляду (lampac)
if (component === 'lampac' && Lampa.Storage.get('hints_online_enabled', true) && (CONFIG.online.repeat || !shown.online)) {
waitForElement('.explorer__files-head', function (el) {
var $hint = $(createHintText(Lampa.Lang.translate('hints_online'), CONFIG.online.id));
$(el).before($hint);
setTimeout(function () {
fadeOutAndRemove($hint, CONFIG.online.fadeDuration);
}, CONFIG.online.showDuration);
shown.online = true;
});
}
// Підказка для торрентів
if (component === 'torrents' && Lampa.Storage.get('hints_torrents_enabled', true) && (CONFIG.torrents.repeat || !shown.torrents)) {
waitForElement('.explorer__files-head', function (el) {
var $hint = $(createHintText(Lampa.Lang.translate('hints_torrents'), CONFIG.torrents.id));
$(el).before($hint);
setTimeout(function () {
fadeOutAndRemove($hint, CONFIG.torrents.fadeDuration);
}, CONFIG.torrents.showDuration);
shown.torrents = true;
});
}
// Підказка в картці фільму
if (component === 'full' && Lampa.Storage.get('hints_incard_enabled', true) && (CONFIG.incard.repeat || !shown.incard)) {
waitForElement('.full-start-new__head', function (el) {
var $hint = $(createHintText_incard(Lampa.Lang.translate('hints_incard'), CONFIG.incard.id));
$(el).before($hint);
setTimeout(function () {
fadeOutAndRemove($hint, CONFIG.incard.fadeDuration);
}, CONFIG.incard.showDuration);
shown.incard = true;
});
}
}
});
}
// Додаємо пункт у головне меню Лампа
Lampa.Menu.addButton(
'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 8v4l3 3"></path><circle cx="12" cy="12" r="10"></circle></svg>',
Lampa.Lang.translate('hints_plugin_title'),
function () {
Lampa.Select.show({
title: Lampa.Lang.translate('hints_plugin_title'),
items: [
{
title: Lampa.Lang.translate('hints_online'),
subtitle: Lampa.Lang.translate('hints_online_subtitle'),
checkbox: true,
checked: Lampa.Storage.get('hints_online_enabled', true),
onSelect: function (item) {
Lampa.Storage.set('hints_online_enabled', item.checked);
}
},
{
title: Lampa.Lang.translate('hints_torrents'),
subtitle: Lampa.Lang.translate('hints_torrents_subtitle'),
checkbox: true,
checked: Lampa.Storage.get('hints_torrents_enabled', true),
onSelect: function (item) {
Lampa.Storage.set('hints_torrents_enabled', item.checked);
}
},
{
title: Lampa.Lang.translate('hints_incard'),
subtitle: Lampa.Lang.translate('hints_incard_subtitle'),
checkbox: true,
checked: Lampa.Storage.get('hints_incard_enabled', true),
onSelect: function (item) {
Lampa.Storage.set('hints_incard_enabled', item.checked);
}
}
],
onBack: function () {
Lampa.Controller.toggle('menu');
}
});
}
);
// Запуск плагіна після готовності додатка
if (window.appready) {
initializeHintFeature();
} else {
Lampa.Listener.follow('app', function (event) {
if (event.type === 'ready') {
initializeHintFeature();
}
});
}
})();