(function () { 'use strict'; // CONFIGURATION const imageUrl = 'https://ptpimg.me/of13dd.png'; // Replace with your image const username = 'AutoTorrentManager'; const password = 'Yj09ddjXDq9tL9jkfbQ4ltO8hbY38iKj'; const webhookUrl = '/webhook/sonarr'; const webhooks = [ { name: 'Trigger A', description: 'Add Global Tag to untagged series only', trigger: 'a' }, { name: 'Trigger B', description: 'Force-add Global Tag to all series', trigger: 'b' }, { name: 'Trigger C', description: 'Remove Global Tag from indexer-tagged series', trigger: 'c' } ]; // CREATE INDICATOR TAB const tab = document.createElement('div'); tab.style.position = 'fixed'; tab.style.top = '5px'; tab.style.left = '0'; tab.style.width = '20px'; tab.style.height = '50px'; tab.style.background = 'transparent'; tab.style.borderLeft = '2px solid #FF6600'; tab.style.zIndex = '9999'; tab.style.cursor = 'pointer'; tab.style.borderRadius = '0 4px 4px 0'; //tab.style.opacity = '0.3'; // Create icon container (initially hidden) const iconContainer = document.createElement('div'); iconContainer.style.position = 'fixed'; iconContainer.style.top = '10px'; iconContainer.style.left = '-50px'; iconContainer.style.width = '40px'; iconContainer.style.height = '40px'; iconContainer.style.borderRadius = '50%'; iconContainer.style.backgroundImage = `url(${imageUrl})`; iconContainer.style.backgroundSize = 'cover'; iconContainer.style.backgroundPosition = 'center'; iconContainer.style.opacity = '0.5'; iconContainer.style.transition = 'left 0.3s ease, opacity 0.3s ease'; iconContainer.style.zIndex = '10000'; iconContainer.style.cursor = 'pointer'; iconContainer.style.paddingLeft = '20px'; // match .logoContainer padding iconContainer.style.display = 'flex'; iconContainer.style.alignItems = 'center'; // Reveal icon on hover const isMobile = /Mobi|Android/i.test(navigator.userAgent); if (isMobile) { tab.addEventListener('click', () => { iconContainer.style.left = '12px'; iconContainer.style.opacity = '1.0'; }); } else { tab.addEventListener('mouseenter', () => { iconContainer.style.left = '12px'; iconContainer.style.opacity = '1.0'; }); } if (!isMobile) { iconContainer.addEventListener('mouseleave', () => { if (!isMenuVisible) { iconContainer.style.left = '-50px'; iconContainer.style.opacity = '0.5'; } }); } // DROPDOWN MENU const menu = document.createElement('div'); menu.style.position = 'fixed'; menu.style.top = '55px'; menu.style.left = '10px'; menu.style.backgroundColor = 'var(--sidebarBackgroundColor)'; menu.style.border = '2px solid var(--pageBackground)'; menu.style.borderRadius = '8px'; menu.style.boxShadow = '0px 4px 6px rgba(0,0,0,0.1)'; menu.style.padding = '10px'; menu.style.zIndex = '10001'; menu.style.display = 'none'; menu.style.minWidth = '220px'; webhooks.forEach(hook => { const row = document.createElement('div'); row.style.marginBottom = '10px'; row.style.padding = '10px'; row.style.borderRadius = '6px'; row.style.transition = 'background-color 0.2s ease'; row.style.display = 'flex'; row.style.flexDirection = 'column'; row.style.alignItems = 'stretch'; row.style.cursor = 'pointer'; const desc = document.createElement('div'); desc.textContent = hook.description; desc.style.fontSize = '12px'; desc.style.color = '#CCCCCC'; desc.style.textAlign = 'center'; row.addEventListener('mouseenter', () => { row.style.backgroundColor = 'var(--sidebarActiveBackgroundColor)'; desc.style.color = 'var(--themeBlue)' }); row.addEventListener('mouseleave', () => { row.style.backgroundColor = 'transparent'; desc.style.color = '#CCCCCC' }); desc.addEventListener('click', (e) => { e.stopPropagation(); // Prevents menu from closing const payload = { trigger: hook.trigger }; fetch(webhookUrl, { method: "POST", headers: { "Authorization": "Basic " + btoa(username + ":" + password), "Content-Type": "application/json" }, body: JSON.stringify(payload) }) .then(res => { if (!res.ok) throw new Error(`HTTP ${res.status}`); alert(`✅ ${hook.name} sent! Status: ${res.status}`); }) .catch(err => { alert(`❌ Failed to send ${hook.name}`); console.error(err); }); }); row.appendChild(desc); menu.appendChild(row); }); let isMenuVisible = false; iconContainer.addEventListener('click', () => { isMenuVisible = !isMenuVisible; menu.style.display = isMenuVisible ? 'block' : 'none'; if (!isMenuVisible) { iconContainer.style.left = '-50px'; iconContainer.style.opacity = '0.5'; } }); // Close menu if clicked outside document.addEventListener('click', (e) => { if (!iconContainer.contains(e.target) && !menu.contains(e.target) && !tab.contains(e.target)) { menu.style.display = 'none'; isMenuVisible = false; iconContainer.style.left = '-50px'; } }); // Inject elements document.body.appendChild(tab); document.body.appendChild(iconContainer); document.body.appendChild(menu); })();