This commit is contained in:
dv 2026-03-23 17:17:08 +03:00
parent a2fb35f149
commit 38b30e4f25
2 changed files with 47 additions and 56 deletions

View file

@ -1,6 +1,8 @@
// ==================== ГЛАВНЫЙ ФАЙЛ ====================
(function() {
let capsLogoUrl = null; // URL caps.svg, сохраняется при первой замене логотипа
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', waitForConfigAndInit);
} else {
@ -62,9 +64,11 @@
if (!replaceLogoEnabled || !hasGetURL) return false;
const logo = document.querySelector(LOGO_SELECTOR);
if (logo && !logo.dataset.capsReplaced) {
logo.dataset.capsOriginalSrc = logo.src;
logo.dataset.capsReplaced = '1';
logo.setAttribute('data-caps-ui', 'true');
logo.src = chrome.runtime.getURL('icons/caps.svg');
logo.setAttribute('data-caps-logo', 'true');
capsLogoUrl = chrome.runtime.getURL('icons/caps.svg');
logo.src = capsLogoUrl;
debugLog('🖼️ [LOGO] Заменён на caps.svg', from ? '(' + from + ')' : '');
applyVisibilityToElement(logo);
return true;
@ -113,9 +117,6 @@
return;
}
// Кнопка переключения видимости UI (показывается на всех CAPS-страницах)
addToggleButton();
// Настраиваем Escape
if (core.CloseHandler) {
core.CloseHandler.setupEscapeHandler();
@ -167,22 +168,36 @@
if (!el) return;
const core = window.VideoIPRedirect;
const visible = core && core.CONFIG.uiVisible !== false;
if (el.hasAttribute('data-caps-logo')) {
if (visible && capsLogoUrl) {
el.src = capsLogoUrl;
} else if (!visible && el.dataset.capsOriginalSrc) {
el.src = el.dataset.capsOriginalSrc;
}
} else {
el.style.display = visible ? '' : 'none';
}
}
function applyVisibility(visible) {
// Скрываем/показываем UI-элементы расширения
document.querySelectorAll('[data-caps-ui="true"]').forEach(el => {
// Кнопка-переключатель не скрывается — иначе не выйти из режима скрытия
if (el.classList.contains('caps-ui-toggle-btn')) return;
el.style.display = visible ? '' : 'none';
el.style.display = visible ? (el.dataset.capsUiDisplay || '') : 'none';
});
// Обновляем иконку кнопки переключателя
const toggleBtn = document.querySelector('.caps-ui-toggle-btn');
if (toggleBtn) {
toggleBtn.title = visible ? 'Скрыть улучшения CAPS (Shift+F1)' : 'Показать улучшения CAPS (Shift+F1)';
toggleBtn.textContent = visible ? '👁' : '🙈';
// Показываем/скрываем оригинальные элементы (обратная логика)
document.querySelectorAll('[data-caps-original="true"]').forEach(el => {
el.style.display = visible ? 'none' : '';
});
// Для логотипа меняем src вместо скрытия
document.querySelectorAll('[data-caps-logo="true"]').forEach(el => {
if (visible && capsLogoUrl) {
el.src = capsLogoUrl;
} else if (!visible && el.dataset.capsOriginalSrc) {
el.src = el.dataset.capsOriginalSrc;
}
});
}
function toggleVisibility() {
@ -211,46 +226,6 @@
}
}
function addToggleButton() {
if (document.querySelector('.caps-ui-toggle-btn')) return;
const core = window.VideoIPRedirect;
const visible = core && core.CONFIG.uiVisible !== false;
const btn = document.createElement('button');
btn.className = 'caps-ui-toggle-btn';
btn.setAttribute('data-caps-ui', 'true');
btn.textContent = visible ? '👁' : '🙈';
btn.title = visible ? 'Скрыть улучшения CAPS (Shift+F1)' : 'Показать улучшения CAPS (Shift+F1)';
btn.style.cssText = `
position: fixed;
bottom: 16px;
right: 16px;
z-index: 999999;
width: 36px;
height: 36px;
border-radius: 50%;
border: none;
background: rgba(102, 126, 234, 0.85);
color: white;
font-size: 18px;
cursor: pointer;
box-shadow: 0 2px 8px rgba(0,0,0,0.25);
display: flex;
align-items: center;
justify-content: center;
padding: 0;
line-height: 1;
transition: opacity 0.2s;
`;
btn.onmouseover = () => { btn.style.opacity = '1'; };
btn.onmouseout = () => { btn.style.opacity = '0.7'; };
btn.style.opacity = '0.7';
btn.onclick = () => toggleVisibility();
document.body.appendChild(btn);
}
// ---- Обработка запросов из popup ----
if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.onMessage) {

View file

@ -140,9 +140,16 @@
wrapper.style.display = 'inline-block';
wrapper.style.verticalAlign = 'middle';
wrapper.setAttribute('data-caps-ui', 'true');
wrapper.setAttribute('data-caps-ui-display', 'inline-block');
if (addVideo) wrapper.appendChild(createVideoButton(host));
if (addScheme) wrapper.appendChild(createButton(mnemoLink, host));
mnemoLink.parentNode.replaceChild(wrapper, mnemoLink);
// Оставляем оригинальную ссылку в DOM — она показывается когда UI скрыт
const isVisible = core.CONFIG?.uiVisible !== false;
mnemoLink.setAttribute('data-caps-original', 'true');
mnemoLink.style.display = isVisible ? 'none' : '';
wrapper.style.display = isVisible ? 'inline-block' : 'none';
mnemoLink.parentNode.insertBefore(wrapper, mnemoLink);
core.activeSchemeButton = true;
debugLog('✅ Кнопка успешно добавлена!');
@ -156,6 +163,15 @@
removeSchemeButton: function() {
const wrapper = document.querySelector('.scheme-buttons-wrapper');
if (wrapper) {
// Восстанавливаем оригинальную ссылку
const parent = wrapper.parentNode;
if (parent) {
const originalLink = parent.querySelector('[data-caps-original="true"]');
if (originalLink) {
originalLink.style.display = '';
originalLink.removeAttribute('data-caps-original');
}
}
wrapper.remove();
core.activeSchemeButton = false;
return true;