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

Message

The document is a user script that creates a privacy curtain feature for web pages, activated by a keyboard shortcut (Ctrl + \) or after 30 seconds of user inactivity. It includes functionality to display a countdown timer for the curtain activation and ensures the script does not run on YouTube. The curtain smoothly transitions in and out, providing a visual privacy layer when triggered.

Uploaded by

danufa11.11.11
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)
7 views3 pages

Message

The document is a user script that creates a privacy curtain feature for web pages, activated by a keyboard shortcut (Ctrl + \) or after 30 seconds of user inactivity. It includes functionality to display a countdown timer for the curtain activation and ensures the script does not run on YouTube. The curtain smoothly transitions in and out, providing a visual privacy layer when triggered.

Uploaded by

danufa11.11.11
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 Curtain
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Ctrl+\ and 30 sec idle activates curtain
// @author ferris
// @match *://*/*
// @grant none
// ==/UserScript==

(function () {
'use strict';

// Check if the current site is YouTube


const currentDomain = window.location.hostname;
if (currentDomain.includes('youtube.com')) {
return; // Exit the script entirely if on YouTube
}

// Create the privacy curtain


const curtain = document.createElement('div');
curtain.id = 'privacy-curtain';
curtain.style.cssText = `
position: fixed;
top: 0;
right: -100%; /* Start off-screen */
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0); /* Fully transparent initially */
z-index: 9999;
transition: right 0.5s ease-in-out, background-color 0.5s ease-in-out; /*
Smooth sliding and opacity transition */
`;

// Append the curtain to the body


document.body.appendChild(curtain);

// Function to toggle the privacy curtain


function toggleCurtain() {
if (curtain.style.right === '-100%' || curtain.style.right === '') {
// Slide in and make fully black
curtain.style.right = '0'; // Slide into view
setTimeout(() => {
curtain.style.backgroundColor = 'rgba(0, 0, 0, 1)'; // Gradually
become fully opaque
}, 10); // Small delay to allow sliding animation to start first
} else {
// Slide out and make transparent
curtain.style.backgroundColor = 'rgba(0, 0, 0, 0)'; // Gradually become
transparent
setTimeout(() => {
curtain.style.right = '-100%'; // Slide out of view after
transparency transition
}, 500); // Match the duration of the CSS transition
}
}

// Add keyboard shortcut (Ctrl + \)


document.addEventListener('keydown', (event) => {
if (event.ctrlKey && event.key === '\\') {
event.preventDefault(); // Prevent any default behavior
toggleCurtain();
}
});

// Variables for inactivity detection


let inactivityTimer;
let countdownInterval; // Track the countdown interval
const inactivityTimeout = 30000; // 30 seconds
let lastActivityTime = Date.now(); // Track the last user activity time

// Create the numeric timer display


const timerDisplay = document.createElement('div');
timerDisplay.id = 'timer-display';
timerDisplay.style.cssText = `
position: fixed;
bottom: 20px;
left: 20px;
padding: 5px 10px;
background-color: rgba(0, 0, 0, 0.7);
color: white;
font-family: Arial, sans-serif;
font-size: 14px;
border-radius: 5px;
z-index: 10000;
display: none; /* Initially hidden */
`;
document.body.appendChild(timerDisplay);

// Function to reset the inactivity timer


function resetInactivityTimer() {
const currentTime = Date.now();

// Only reset the timer if enough time has passed since the last activity
if (currentTime - lastActivityTime > 500) { // 500ms debounce threshold
clearTimeout(inactivityTimer); // Clear any existing timer
clearInterval(countdownInterval); // Clear any existing countdown
interval
lastActivityTime = currentTime; // Update the last activity time

timerDisplay.style.display = 'block'; // Show the timer display


updateNumericTimer(inactivityTimeout / 1000); // Reset the timer
display to 30 seconds

// Set a new timer


inactivityTimer = setTimeout(() => {
toggleCurtain(); // Activate the curtain after inactivity timeout
timerDisplay.style.display = 'none'; // Hide the timer display
}, inactivityTimeout);
}
}

// Function to update the numeric timer


function updateNumericTimer(seconds) {
let remainingTime = Math.ceil(seconds); // Start with the total seconds
timerDisplay.textContent = `Curtain in: ${remainingTime}s`; // Display the
initial time
// Clear any existing countdown interval before starting a new one
clearInterval(countdownInterval);

countdownInterval = setInterval(() => {


remainingTime -= 1; // Decrease the remaining time by 1 second
if (remainingTime >= 0) {
timerDisplay.textContent = `Curtain in: ${remainingTime}s`; //
Update the display
} else {
clearInterval(countdownInterval); // Stop the countdown when time
reaches 0
}
}, 1000); // Update every 1 second
}

// Debounce user activity events


const debounceReset = () => {
resetInactivityTimer();
};

// Reset the timer on user activity


document.addEventListener('mousemove', debounceReset);
document.addEventListener('mousedown', debounceReset);
document.addEventListener('keydown', debounceReset);
document.addEventListener('scroll', debounceReset);

// Initialize the inactivity timer


resetInactivityTimer();
})();

You might also like