Repository navigation
Expand file tree
/
Copy pathattention.js
More file actions
224 lines (193 loc) · 10.1 KB
/
Copy pathattention.js
File metadata and controls
224 lines (193 loc) · 10.1 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
// плагін попередження завантаження
(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: "Інформація про фільм може з'явитися раніше, ніж він стане доступним для перегляду."
},
attention_enabled: {
ru: 'Попередження вмикати',
en: 'Enable warnings',
uk: 'Попередження вмикати'
},
attention_description: {
ru: 'Включает предупреждения о том, что видео еще недоступно для просмотра, доступна только информация о нем',
en: 'Enables warnings that video is not yet available for viewing, only information about it is available',
uk: 'Вмикає попередження про те, що відео ще недоступне для перегляду, доступна тільки інформація про нього'
}
});
var CONFIG = {
online: {
id: 'hint-online-banner',
showDuration: 3000,
fadeDuration: 500,
repeat: false,
enabled: true
},
torrents: {
id: 'hint-torrent-banner',
showDuration: 4000,
fadeDuration: 500,
repeat: false,
enabled: true
},
incard: {
id: 'hint-incard-banner',
showDuration: 4000,
fadeDuration: 500,
repeat: false,
enabled: true
}
};
// Додаємо параметр в налаштування
function addSettingsParam() {
Lampa.SettingsApi.addParam({
component: 'interface_customization',
param: {
name: 'attention_enabled',
type: 'trigger',
default: true
},
field: {
name: '<div style="display: flex; align-items: center;"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" style="margin-right:10px;flex-shrink:0;min-width:24px;min-height:24px;max-width:24px;max-height:24px" viewBox="0 0 24 24" fill="none"><path d="M11.955 2.001c.32-.017.62.147.78.429h.002l9.908 17.374c.34.599-.055 1.29-.737 1.29H2.092c-.682 0-1.078-.691-.737-1.29L11.263 2.43h.002a.84.84 0 0 1 .69-.429z" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round" stroke-width="2"/><path d="M12 18a1 1 0 1 0 0-2 1 1 0 0 0 0 2" fill="currentColor"/><path d="M12 15V8" stroke="currentColor" stroke-width="2"/></svg>' + Lampa.Lang.translate('attention_enabled') + '</div>',
description: Lampa.Lang.translate('attention_description')
},
onChange: function(value) {
CONFIG.online.enabled = value;
CONFIG.torrents.enabled = value;
CONFIG.incard.enabled = value;
}
});
// Примусово оновлюємо відображення налаштувань після додавання параметра
if (Lampa.Settings && Lampa.Settings.main) {
Lampa.Settings.main().render();
}
}
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'
});
// Force 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'
});
// Подождём чуть дольше, чем сама анимация, чтобы DOM спокойно переварил
setTimeout(function () {
$el.remove();
}, duration + 50); // буфер для плавності
}
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
};
// Отримуємо початковий стан з налаштувань
var attentionEnabled = Lampa.Storage.field('attention_enabled', true);
CONFIG.online.enabled = attentionEnabled;
CONFIG.torrents.enabled = attentionEnabled;
CONFIG.incard.enabled = attentionEnabled;
Lampa.Storage.listener.follow('change', function (event) {
if (event.name === 'activity') {
var component = Lampa.Activity.active().component;
if (component === 'lampac' && CONFIG.online.enabled && (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' && CONFIG.torrents.enabled && (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' && CONFIG.incard.enabled && (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;
});
}
}
});
}
function startPlugin() {
// Ініціалізуємо функціонал
initializeHintFeature();
}
// Важливо: реєструємо параметр негайно, не чекаючи appready
addSettingsParam();
if (window.appready) {
startPlugin();
} else {
Lampa.Listener.follow('app', function (event) {
if (event.type === 'ready') {
startPlugin();
}
});
}
})();