Last active
May 24, 2024 09:07
-
-
Save mortenson/f928d2ba672b8dcc3e16e6a308336587 to your computer and use it in GitHub Desktop.
Another simple chrome extension to track your YouTube watch time
This file contains 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
{ | |
"manifest_version": 3, | |
"name": "count daily youtube watch time", | |
"description": "made by sam", | |
"version": "0.0.1", | |
"content_scripts": [ | |
{ | |
"matches": [ | |
"https://www.youtube.com/*" | |
], | |
"js": ["timer.js"] | |
} | |
] | |
} |
This file contains 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
// Displays a watch time in the corner of your screen. | |
const timeName = 'sam_watchTime_' + (new Date().setHours(0, 0, 0, 0)); | |
setInterval(() => { | |
localStorage.setItem(timeName, parseInt(localStorage.getItem(timeName) || 0) + 500); | |
}, 500); | |
window.addEventListener('load', () => { | |
setTimeout(() => { | |
const timerElem = document.createElement('div'); | |
timerElem.setAttribute('style', 'position:fixed;right:0;bottom:0;color:white;background:black;font-size:20px;'); | |
document.body.append(timerElem); | |
setInterval(() => { | |
const total = Math.floor((parseInt(localStorage.getItem(timeName) || 0) / 1000) / 60); | |
timerElem.innerText = `Watched for: ${total} minutes today`; | |
}, 1000); | |
}, 2000) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to count the total time (and maybe even the number of videos watched) in a month, to make sure the premium subscription was worth it? :)