Files
scripts/cams.js
2025-10-28 14:01:48 +00:00

139 lines
5.1 KiB
JavaScript

// ==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 = `
<div style="font-family: Arial, sans-serif;">
<h3 style="margin: 0 0 15px 0; color: #333;">Set MaxDockedCams</h3>
<p style="margin: 0 0 10px 0; color: #666;">Enter a number:</p>
<input type="number" id="maxDockedInput" style="width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; box-sizing: border-box;" placeholder="Enter number" />
<div style="margin-top: 15px; text-align: right;">
<button id="cancelBtn" style="padding: 8px 15px; margin-right: 10px; background: #ccc; color: #333; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;">Cancel</button>
<button id="okBtn" style="padding: 8px 15px; background: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;">OK</button>
</div>
</div>
`;
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);
})();