Skip to content

Instantly share code, notes, and snippets.

@mortenson
Last active May 24, 2024 09:07
Show Gist options
  • Save mortenson/f928d2ba672b8dcc3e16e6a308336587 to your computer and use it in GitHub Desktop.
Save mortenson/f928d2ba672b8dcc3e16e6a308336587 to your computer and use it in GitHub Desktop.
Another simple chrome extension to track your YouTube watch time
{
"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"]
}
]
}
// 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)
});
@kopeboy
Copy link

kopeboy commented May 24, 2024

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? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment