From 3a540c096abaada60b2339e46b627068557745ad Mon Sep 17 00:00:00 2001 From: darren Date: Tue, 28 Oct 2025 13:55:04 +0000 Subject: [PATCH] Add cams.js --- cams.js | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 cams.js diff --git a/cams.js b/cams.js new file mode 100644 index 0000000..2e63aeb --- /dev/null +++ b/cams.js @@ -0,0 +1,139 @@ +// ==UserScript== +// @name MaxDockedCams Control +// @namespace http://tampermonkey.net/ +// @version 1.0 +// @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); + +})(); \ No newline at end of file