-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
79 lines (69 loc) · 2.85 KB
/
script.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
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
// Получение настроек
async function getSettings(name) {
try {
const response = await fetch(`http://localhost:2007/get_handle?name=${name}`);
if (!response.ok) throw new Error(`Ошибка сети: ${response.status}`);
const { data } = await response.json();
if (!data?.sections) {
console.warn("Структура данных не соответствует ожидаемой");
return null;
}
return transformJSON(data);
} catch (error) {
console.error(error);
return null;
}
}
// "Трансформирование" полученных настроек для более удобного использования
function transformJSON(data) {
const result = {};
try {
data.sections.forEach(section => {
section.items.forEach(item => {
if (item.type === "text" && item.buttons) {
result[item.id] = {};
item.buttons.forEach(button => {
result[item.id][button.id] = {
value: button.text,
default: button.defaultParameter
};
});
} else {
result[item.id] = {
value: item.bool || item.input || item.selected || item.value || item.filePath,
default: item.defaultParameter
};
}
});
});
} finally {
return result;
}
}
// Применение настроек
function applySettings(settings) {
// Создание "контейнера" для нашего CSS кода
let exampleStyleElement = document.getElementById('example-style');
if (!exampleStyleElement) {
exampleStyleElement = document.createElement('style');
exampleStyleElement.id = 'example-style';
document.head.appendChild(exampleStyleElement);
}
// Очищаем его для перезаписи в зависимости от настроек
exampleStyleElement.textContent = '';
// Применяем настройку, если она включена
if (settings.opacity.value === true) {
exampleStyleElement.textContent += `
div[data-test-id="FULLSCREEN_PLAYER_MODAL"] {
backdrop-filter: blur(10px) !important;
background-color: hsla(from var(--player-average-color-background) h s l / 85%) !important;
}
`;
}
}
// Обновляем настройки каждые 2 секунды
setInterval(async () => {
const settings = await getSettings("ExampleTheme");
if (!settings) return;
applySettings(settings);
}, 2000);