Created
April 1, 2026 19:58
-
-
Save adrian154/dd986390a5d32f7319083555f20a163b 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 Twitter Time Limit | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.1 | |
| // @description Limit Twitter usage | |
| // @author adrian154 | |
| // @match https://x.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com | |
| // @grant GM_setValue | |
| // @grant GM_getValue | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| const TIME_LIMIT = 30*60; // 45 min | |
| const lockout = () => { | |
| const lockoutElem = document.createElement("div"); | |
| lockoutElem.style.position = "fixed"; | |
| lockoutElem.style.left = "0"; | |
| lockoutElem.style.top = "0"; | |
| lockoutElem.style.backgroundColor = "#ff0000"; | |
| lockoutElem.style.width = "100vw"; | |
| lockoutElem.style.height = "100vh"; | |
| lockoutElem.style.display = "flex"; | |
| document.body.append(lockoutElem); | |
| const lockoutInner = document.createElement("div"); | |
| lockoutInner.style.margin = "auto"; | |
| lockoutElem.append(lockoutInner); | |
| const lockoutText = document.createElement("h1"); | |
| lockoutText.textContent = "Twitter Time Limit Reached"; | |
| lockoutInner.append(lockoutText); | |
| }; | |
| let timeSpent = GM_getValue("twitter_time", 0); | |
| const timeTrackingDay = new Date(GM_getValue("twitter_time_date", 0)); | |
| // if in a new day, reset twitter tracking time. | |
| const today = new Date(); | |
| if(today.getDate() != timeTrackingDay.getDate()) { // sort of crude - can fail if you go a whole month without opening the site | |
| timeSpent = 0; | |
| GM_setValue("twitter_time_date", Date.now()); | |
| } | |
| const tick = () => { | |
| if(timeSpent > TIME_LIMIT) { | |
| lockout(); | |
| return; | |
| } | |
| timeSpent++; | |
| GM_setValue("twitter_time", timeSpent); | |
| setTimeout(tick, 1000); | |
| }; | |
| tick(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment