фикс
This commit is contained in:
parent
a2fb35f149
commit
38b30e4f25
2 changed files with 47 additions and 56 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
// ==================== ГЛАВНЫЙ ФАЙЛ ====================
|
// ==================== ГЛАВНЫЙ ФАЙЛ ====================
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
let capsLogoUrl = null; // URL caps.svg, сохраняется при первой замене логотипа
|
||||||
|
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
document.addEventListener('DOMContentLoaded', waitForConfigAndInit);
|
document.addEventListener('DOMContentLoaded', waitForConfigAndInit);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -62,9 +64,11 @@
|
||||||
if (!replaceLogoEnabled || !hasGetURL) return false;
|
if (!replaceLogoEnabled || !hasGetURL) return false;
|
||||||
const logo = document.querySelector(LOGO_SELECTOR);
|
const logo = document.querySelector(LOGO_SELECTOR);
|
||||||
if (logo && !logo.dataset.capsReplaced) {
|
if (logo && !logo.dataset.capsReplaced) {
|
||||||
|
logo.dataset.capsOriginalSrc = logo.src;
|
||||||
logo.dataset.capsReplaced = '1';
|
logo.dataset.capsReplaced = '1';
|
||||||
logo.setAttribute('data-caps-ui', 'true');
|
logo.setAttribute('data-caps-logo', 'true');
|
||||||
logo.src = chrome.runtime.getURL('icons/caps.svg');
|
capsLogoUrl = chrome.runtime.getURL('icons/caps.svg');
|
||||||
|
logo.src = capsLogoUrl;
|
||||||
debugLog('🖼️ [LOGO] Заменён на caps.svg', from ? '(' + from + ')' : '');
|
debugLog('🖼️ [LOGO] Заменён на caps.svg', from ? '(' + from + ')' : '');
|
||||||
applyVisibilityToElement(logo);
|
applyVisibilityToElement(logo);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -113,9 +117,6 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Кнопка переключения видимости UI (показывается на всех CAPS-страницах)
|
|
||||||
addToggleButton();
|
|
||||||
|
|
||||||
// Настраиваем Escape
|
// Настраиваем Escape
|
||||||
if (core.CloseHandler) {
|
if (core.CloseHandler) {
|
||||||
core.CloseHandler.setupEscapeHandler();
|
core.CloseHandler.setupEscapeHandler();
|
||||||
|
|
@ -167,22 +168,36 @@
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
const core = window.VideoIPRedirect;
|
const core = window.VideoIPRedirect;
|
||||||
const visible = core && core.CONFIG.uiVisible !== false;
|
const visible = core && core.CONFIG.uiVisible !== false;
|
||||||
el.style.display = visible ? '' : 'none';
|
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) {
|
function applyVisibility(visible) {
|
||||||
|
// Скрываем/показываем UI-элементы расширения
|
||||||
document.querySelectorAll('[data-caps-ui="true"]').forEach(el => {
|
document.querySelectorAll('[data-caps-ui="true"]').forEach(el => {
|
||||||
// Кнопка-переключатель не скрывается — иначе не выйти из режима скрытия
|
el.style.display = visible ? (el.dataset.capsUiDisplay || '') : 'none';
|
||||||
if (el.classList.contains('caps-ui-toggle-btn')) return;
|
|
||||||
el.style.display = visible ? '' : 'none';
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обновляем иконку кнопки переключателя
|
// Показываем/скрываем оригинальные элементы (обратная логика)
|
||||||
const toggleBtn = document.querySelector('.caps-ui-toggle-btn');
|
document.querySelectorAll('[data-caps-original="true"]').forEach(el => {
|
||||||
if (toggleBtn) {
|
el.style.display = visible ? 'none' : '';
|
||||||
toggleBtn.title = visible ? 'Скрыть улучшения CAPS (Shift+F1)' : 'Показать улучшения CAPS (Shift+F1)';
|
});
|
||||||
toggleBtn.textContent = visible ? '👁' : '🙈';
|
|
||||||
}
|
// Для логотипа меняем 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() {
|
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 ----
|
// ---- Обработка запросов из popup ----
|
||||||
|
|
||||||
if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.onMessage) {
|
if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.onMessage) {
|
||||||
|
|
|
||||||
|
|
@ -140,9 +140,16 @@
|
||||||
wrapper.style.display = 'inline-block';
|
wrapper.style.display = 'inline-block';
|
||||||
wrapper.style.verticalAlign = 'middle';
|
wrapper.style.verticalAlign = 'middle';
|
||||||
wrapper.setAttribute('data-caps-ui', 'true');
|
wrapper.setAttribute('data-caps-ui', 'true');
|
||||||
|
wrapper.setAttribute('data-caps-ui-display', 'inline-block');
|
||||||
if (addVideo) wrapper.appendChild(createVideoButton(host));
|
if (addVideo) wrapper.appendChild(createVideoButton(host));
|
||||||
if (addScheme) wrapper.appendChild(createButton(mnemoLink, 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;
|
core.activeSchemeButton = true;
|
||||||
debugLog('✅ Кнопка успешно добавлена!');
|
debugLog('✅ Кнопка успешно добавлена!');
|
||||||
|
|
@ -156,6 +163,15 @@
|
||||||
removeSchemeButton: function() {
|
removeSchemeButton: function() {
|
||||||
const wrapper = document.querySelector('.scheme-buttons-wrapper');
|
const wrapper = document.querySelector('.scheme-buttons-wrapper');
|
||||||
if (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();
|
wrapper.remove();
|
||||||
core.activeSchemeButton = false;
|
core.activeSchemeButton = false;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue