Skip to content

Instantly share code, notes, and snippets.

@chfour
Last active August 22, 2021 16:33
Show Gist options
  • Save chfour/f7b62d58ec952a2e5730ddd8d09f0eb2 to your computer and use it in GitHub Desktop.
Save chfour/f7b62d58ec952a2e5730ddd8d09f0eb2 to your computer and use it in GitHub Desktop.
fancy script to get info about videos on a youtube channel
(hi=>{tm=chfour=>[chfour/3600
<<0,(chfour%3600)/60<<0||"00"
,Math.round(chfour%60)||"00"]
.filter(Boolean).map(chfour=>
chfour.toString().padStart(2,
"0")).join`:`;all=Array.from(
document.querySelectorAll`sp\
an.ytd-thumbnail-overlay-tim\
e-status-renderer`,eeeeeeee=>
eeeeeeee.innerText.split(":")
.reverse().map(a=>parseInt(a)
)).map(aa=>aa[0]+aa[1]*60+(aa
[2]||0)*3600);tot=all.reduce(
(a,b)=>a+b,10)-10;alert(`avg\
\u2000${tm(tot/all["length"])
}\nmax\u2000${tm(Math.max(...
all)<<0)}\nmin\u2000${tm(Math
.min(...all))}\ntotal\u2000${
tm(tot)}\n${all["length"]+1-1
}\u2000videos`);})("chfour");
/*https://chfour.github.io/*/

wait, what am I looking at, exactly?

This is an obfuscated script that, when executed on the "Videos" page of a Youtube channel, will display:

  • average video length,
  • the duration of the longest video,
  • the duration of the shortest video,
  • video count.

The goal was not the lowest character count possible ("codegolfing"), but rather to obfuscate the code and make it "look nice". I just wanted to see if I could do it.

Important thing to note: you need to load all the videos. Holding [End] on your keyboard will work. Hold it until you reach the end of the page.

Below is the original script, a single-line version (single-line.js), as well as a ready-made, URI-encoded bookmarklet (bookmarklet.txt).

(hi=>{tm=chfour=>[chfour/3600
<<0,(chfour%3600)/60<<0||"00"
,Math.round(chfour%60)||"00"]
.filter(Boolean).map(chfour=>
chfour.toString().padStart(2,
"0")).join`:`;all=Array.from(
document.querySelectorAll`sp\
an.ytd-thumbnail-overlay-tim\
e-status-renderer`,eeeeeeee=>
eeeeeeee.innerText.split(":")
.reverse().map(a=>parseInt(a)
)).map(aa=>aa[0]+aa[1]*60+(aa
[2]||0)*3600);tot=all.reduce(
(a,b)=>a+b,10)-10;alert(`avg\
\u2000${tm(tot/all["length"])
}\nmax\u2000${tm(Math.max(...
all)<<0)}\nmin\u2000${tm(Math
.min(...all))}\ntotal\u2000${
tm(tot)}\n${all["length"]+1-1
}\u2000videos`);})("chfour");
/*https://chfour.github.io/*/
javascript:%28hi%3D%3E%7Btm%3Dchfour%3D%3E%5Bchfour%2F3600%3C%3C0%2C%28chfour%253600%29%2F60%3C%3C0%7C%7C%2200%22%2CMath.round%28chfour%2560%29%7C%7C%2200%22%5D.filter%28Boolean%29.map%28chfour%3D%3Echfour.toString%28%29.padStart%282%2C%220%22%29%29.join%60%3A%60%3Ball%3DArray.from%28document.querySelectorAll%60span.ytd-thumbnail-overlay-time-status-renderer%60%2Ceeeeeeee%3D%3Eeeeeeeee.innerText.split%28%22%3A%22%29.reverse%28%29.map%28a%3D%3EparseInt%28a%29%29%29.map%28aa%3D%3Eaa%5B0%5D%2Baa%5B1%5D%2A60%2B%28aa%5B2%5D%7C%7C0%29%2A3600%29%3Btot%3Dall.reduce%28%28a%2Cb%29%3D%3Ea%2Bb%2C10%29-10%3Balert%28%60avg%5Cu2000%24%7Btm%28tot%2Fall%5B%22length%22%5D%29%7D%5Cnmax%5Cu2000%24%7Btm%28Math.max%28...all%29%3C%3C0%29%7D%5Cnmin%5Cu2000%24%7Btm%28Math.min%28...all%29%29%7D%5Cntotal%5Cu2000%24%7Btm%28tot%29%7D%5Cn%24%7Ball%5B%22length%22%5D%2B1-1%7D%5Cu2000videos%60%29%3B%7D%29%28%22chfour%22%29%3B%2F%2Ahttps%3A%2F%2Fchfour.github.io%2F%2A%2F%0A
(hi=>{tm=chfour=>[chfour/3600<<0,(chfour%3600)/60<<0||"00",Math.round(chfour%60)||"00"].filter(Boolean).map(chfour=>chfour.toString().padStart(2,"0")).join`:`;all=Array.from(document.querySelectorAll`span.ytd-thumbnail-overlay-time-status-renderer`,eeeeeeee=>eeeeeeee.innerText.split(":").reverse().map(a=>parseInt(a))).map(aa=>aa[0]+aa[1]*60+(aa[2]||0)*3600);tot=all.reduce((a,b)=>a+b,10)-10;alert(`avg\u2000${tm(tot/all["length"])}\nmax\u2000${tm(Math.max(...all)<<0)}\nmin\u2000${tm(Math.min(...all))}\ntotal\u2000${tm(tot)}\n${all["length"]+1-1}\u2000videos`);})("chfour");/*https://chfour.github.io/*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment