0% found this document useful (0 votes)
50 views3 pages

Jawad TLS

Uploaded by

jdragon-z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views3 pages

Jawad TLS

Uploaded by

jdragon-z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

// ==UserScript==

// @name Refresh Timer Control with Notification


// @namespace http://tampermonkey.net/
// @version 1.0
// @description Add a continuous timer control panel with sound notification for
appointments and auto-refresh
// @author You
// @match https://fr.tlscontact.com/appointment/ma/maOUD2fr/17247736
// @match https://fr.tlscontact.com/visa/ma*
// @match https://fr.tlscontact.com/visa/ma
// @grant none
// ==/UserScript==

(function() {
'use strict';

const style = `
#controlPanel {
position: fixed;
top: 10px;
right: 10px;
background: #fff;
border: 1px solid #000;
padding: 10px;
z-index: 9999;
font-size: 12px;
}
#controlPanel button {
display: block;
margin: 5px;
padding: 10px;
border: none;
color: white;
cursor: pointer;
}
#controlPanel #startButton {
background: green;
}
#controlPanel #stopButton {
background: red;
}
#controlPanel #setRateButton {
background: blue;
}
#controlPanel #timer {
display: block;
margin-top: 10px;
}
#controlPanel #rateInput {
margin-top: 10px;
width: 60px;
}
`;

const styleSheet = document.createElement("style");


styleSheet.type = "text/css";
styleSheet.innerText = style;
document.head.appendChild(styleSheet);
const controlPanel = document.createElement('div');
controlPanel.id = 'controlPanel';
controlPanel.innerHTML = `
<button id="startButton">Start Refresh</button>
<button id="stopButton">Stop Refresh</button>
<input id="rateInput" type="number" value="10" min="1" step="1" /> seconds
<button id="setRateButton">Set Refresh Rate</button>
<div id="timer">Auto-refresh stopped.</div>
`;
document.body.appendChild(controlPanel);

// Adding notification sound


const notificationSound = new Audio('C:\Users\jaouad\Downloads\Music'); // Bell
sound

let refreshTimeout;
let refreshRate = parseInt(localStorage.getItem('refreshRate')) || 10000;
let isRefreshing = localStorage.getItem('isRefreshing') === 'true';
let timeRemaining = parseInt(localStorage.getItem('timeRemaining')) ||
refreshRate;

function updateTimer() {
const seconds = Math.ceil(timeRemaining / 1000);
document.getElementById('timer').innerText = `Next refresh in ${seconds}
seconds.`;
}

function scheduleRefresh() {
refreshTimeout = setInterval(() => {
timeRemaining -= 1000;
updateTimer();

if (timeRemaining <= 0) {
localStorage.setItem('timeRemaining', refreshRate);
notificationSound.play().catch(error => {
console.error('Error playing sound:', error);
});
location.reload();
}
localStorage.setItem('timeRemaining', timeRemaining);
}, 1000);
}

function startRefreshing() {
if (!isRefreshing) {
isRefreshing = true;
localStorage.setItem('isRefreshing', 'true');
localStorage.setItem('timeRemaining', refreshRate);
scheduleRefresh();
}
}

function stopRefreshing() {
if (isRefreshing) {
isRefreshing = false;
clearInterval(refreshTimeout);
localStorage.setItem('isRefreshing', 'false');
document.getElementById('timer').innerText = 'Auto-refresh stopped.';
}
}

function setRefreshRate() {
const rate = parseInt(document.getElementById('rateInput').value, 10);
if (!isNaN(rate) && rate > 0) {
refreshRate = rate * 1000;
localStorage.setItem('refreshRate', refreshRate);
timeRemaining = refreshRate;
if (isRefreshing) {
clearInterval(refreshTimeout);
scheduleRefresh();
}
}
}

document.getElementById('startButton').addEventListener('click',
startRefreshing);
document.getElementById('stopButton').addEventListener('click',
stopRefreshing);
document.getElementById('setRateButton').addEventListener('click',
setRefreshRate);

if (isRefreshing) {
scheduleRefresh();
}

updateTimer();
})();

You might also like