Show Youtube Video Length Time

Shows Youtube video length in hours, minutes, and seconds

  1. // ==UserScript==
  2. // @name Show Youtube Video Length Time
  3. // @namespace Jefferson Scher
  4. // @icon https://cdn1.iconfinder.com/data/icons/iconsweets2/40/timer.png
  5. // @include *youtube.com*
  6. // @version 1.01
  7. // @description Shows Youtube video length in hours, minutes, and seconds
  8. // ==/UserScript==
  9.  
  10. function ShowRunningTime(e){
  11. if (window.self != window.top) return;
  12. var emb = document.querySelector('#movie_player');
  13. if (!emb){
  14. window.setTimeout(ShowRunningTime, 250); // doesn't work??
  15. return;
  16. }
  17. var fvars = emb.getAttribute("flashvars");
  18. fvars = fvars.substr(fvars.indexOf("length_seconds=") + "length_seconds=".length);
  19. var trt = fvars.split("&")[0];
  20. var vidtitle = document.getElementById("watch-headline-title");
  21. if (trt > 0 && vidtitle){
  22. var min = Math.floor(parseInt(trt)/60);
  23. var sec = parseInt(trt) - (min * 60);
  24. vidtitle.appendChild(document.createTextNode(" (runtime: " + min + ":" + sec + ")"));
  25. }
  26. }
  27. ShowRunningTime();