Untitled
unknown
javascript
a year ago
2.1 kB
6
Indexable
// ==UserScript== // @name KG_MainChatReload // @namespace http://tampermonkey.net/ // @version 2024-01-02 // @description Fix the issue with the chat lost connection by reloading the page // @author Patcher // @match *://klavogonki.ru/g* // @icon https://www.google.com/s2/favicons?sz=64&domain=klavogonki.ru // @grant none // ==/UserScript== (function() { // Select the input element var inputElement = document.querySelector('.text'); // Array to store logs var lostChatConnections = JSON.parse(localStorage.getItem('lostChatConnections')) || []; // Function to format date as "year-month-day | HH:mm:ss" const formatLogDate = (date) => { const options = { year: 'numeric', month: '2-digit', day: '2-digit' }; const formattedDate = date.toLocaleDateString('en-US', options); const timeOptions = { hour: '2-digit', minute: '2-digit', second: '2-digit' }; const formattedTime = date.toLocaleTimeString('en-US', timeOptions); return `${formattedDate} | ${formattedTime}`; }; // Function to add a log entry with the formatted date const addLog = () => { const currentDate = new Date(); const formattedLog = formatLogDate(currentDate); lostChatConnections.push(formattedLog); localStorage.setItem('lostChatConnections', JSON.stringify(lostChatConnections)); } // Use MutationObserver to observe changes to the attributes of the input element const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { // Check if 'disabled' attribute is present if (inputElement.disabled) { // Add log entry addLog(); // Set a timeout before reload (1 second in this example) setTimeout(() => location.reload(), 1000); } }); }); // Configure and start the MutationObserver const observerConfig = { attributes: true }; observer.observe(inputElement, observerConfig); })();
Editor is loading...
Leave a Comment