// ==UserScript== // @name cams // @namespace http://tampermonkey.net/ // @version 1.0.1 // @description Set maxDockedCamsForUser with a custom dialog // @author You // @match https://chat.fabswingers.com/* // @updateURL https://git.upto.im/geekery/scripts/raw/branch/main/meta.js // @downloadURL https://git.upto.im/geekery/scripts/raw/branch/main/cams.js // @grant none // @run-at document-idle // ==/UserScript== (function() { 'use strict'; const BUTTON_ID = 'maxDockedCamsButton_SINGLETON'; const LOCK_KEY = 'maxDockedCams_scriptLock'; // Try to acquire lock const lockValue = Date.now().toString(); if (localStorage.getItem(LOCK_KEY)) { console.log('MaxDockedCams: Another instance already running, exiting'); return; } localStorage.setItem(LOCK_KEY, lockValue); window.addEventListener('beforeunload', function() { if (localStorage.getItem(LOCK_KEY) === lockValue) { localStorage.removeItem(LOCK_KEY); } }); // Create custom dialog function showCustomPrompt() { // Create overlay const overlay = document.createElement('div'); overlay.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 9999999; display: flex; align-items: center; justify-content: center;'; // Create dialog box const dialog = document.createElement('div'); dialog.style.cssText = 'background: white; padding: 20px; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.5); min-width: 300px;'; // Add content dialog.innerHTML = `

Set MaxDockedCams

Enter a number:

`; overlay.appendChild(dialog); document.body.appendChild(overlay); const input = document.getElementById('maxDockedInput'); const okBtn = document.getElementById('okBtn'); const cancelBtn = document.getElementById('cancelBtn'); // Focus input setTimeout(() => input.focus(), 100); // Handle OK button okBtn.onclick = function() { const value = input.value; if (value === '') { alert('Please enter a number'); return; } const number = parseInt(value, 10); if (!isNaN(number)) { window.maxDockedCamsForUser = number; console.log(`maxDockedCamsForUser set to: ${number}`); overlay.remove(); alert(`maxDockedCamsForUser successfully set to ${number}`); } else { alert('Please enter a valid number'); } }; // Handle Cancel button cancelBtn.onclick = function() { console.log('User cancelled'); overlay.remove(); }; // Handle Enter key input.onkeypress = function(e) { if (e.key === 'Enter') { okBtn.click(); } }; // Handle Escape key overlay.onkeydown = function(e) { if (e.key === 'Escape') { cancelBtn.click(); } }; } // Wait and create button setTimeout(function() { document.querySelectorAll(`[id^="maxDockedCamsButton"]`).forEach(btn => btn.remove()); const button = document.createElement('button'); button.id = BUTTON_ID; button.textContent = 'Set MaxDockedCams'; button.type = 'button'; button.style.cssText = 'position: fixed; top: 10px; right: 10px; z-index: 999999; padding: 8px 12px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; box-shadow: 0 2px 5px rgba(0,0,0,0.3);'; button.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); showCustomPrompt(); }); document.body.appendChild(button); console.log('MaxDockedCams button created'); setInterval(function() { const buttons = document.querySelectorAll(`#${BUTTON_ID}`); if (buttons.length > 1) { for (let i = 1; i < buttons.length; i++) { buttons[i].remove(); } } }, 500); }, 100); })();