Last active
July 8, 2023 18:54
-
-
Save whaaaley/96994a921ec2ef7cc567030f76460f42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Counter and Timer | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://chat.openai.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com | |
// @grant GM_addStyle | |
// ==/UserScript== | |
(() => { | |
'use strict' | |
let counter = 25 | |
let countdownMinutes = 0 | |
let countdownSeconds = 0 | |
// Add CSS | |
GM_addStyle(` | |
#counterDisplay { | |
position: fixed; | |
top: 6px; | |
right: 16px; | |
background-color: #202123; | |
z-index: 1000; | |
padding: 4px 10px; | |
border-radius: 6px; | |
} | |
`) | |
// Create counter display | |
const counterDisplay = document.createElement('div') | |
counterDisplay.id = 'counterDisplay' | |
counterDisplay.textContent = `Count: ${counter} - Time: ${countdownMinutes}m ${countdownSeconds}s` | |
document.body.appendChild(counterDisplay) | |
// Update counter display | |
const updateDisplay = () => { | |
counterDisplay.textContent = `Count: ${counter} - Time: ${countdownMinutes}m ${countdownSeconds}s` | |
} | |
// Handle countdown | |
const handleCountdown = () => { | |
if (countdownSeconds > 0) { | |
countdownSeconds-- | |
} else if (countdownMinutes > 0) { | |
countdownMinutes-- | |
countdownSeconds = 59 | |
} | |
updateDisplay() | |
} | |
// Check for button existence periodically | |
const checkButtonInterval = setInterval(() => { | |
const button = document.querySelector('div > button:last-child') | |
const textarea = document.querySelector('#prompt-textarea') | |
if (button && textarea) { | |
// Handle button click | |
button.addEventListener('click', () => { | |
counter-- | |
countdownMinutes += 8 | |
updateDisplay() | |
}) | |
// Handle Enter key in textarea | |
textarea.addEventListener('keydown', (event) => { | |
if (event.key === 'Enter') { | |
counter-- | |
countdownMinutes += 8 | |
updateDisplay() | |
} | |
}) | |
// Stop checking for button and textarea | |
clearInterval(checkButtonInterval) | |
} | |
}, 1000) // Check every second | |
// Handle timer | |
setInterval(handleCountdown, 1000) // 1000 milliseconds = 1 second | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment