youtube playlist statitics

statirics the total,longest,shortest time of youtube playlist video

当前为 2017-06-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name youtube playlist statitics
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description statirics the total,longest,shortest time of youtube playlist video
  6. // @author Youer
  7. // @match https://www.youtube.com/playlist?list=*
  8. // @grant none
  9. // @require https://code.jquery.com/jquery-2.2.4.min.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. //'use strict';
  14. console.log("excuted");
  15. //var allSpan = document.getElementsByTagName("tbody")[0].getElementsByTagName("span");
  16. var allSpan = $("ul").find("tbody").find('span[aria-label]');
  17. // Total seconds
  18. var sumAll = 0;
  19. var vidTime = 0;
  20. var timeList = [];
  21.  
  22. for(var i=0;i<allSpan.length;i++) {
  23. var sp = allSpan[i];
  24. var spText = sp.innerText;
  25. var sumOne = 0;
  26. if (spText.indexOf(":") >= 0) {
  27. var spTextLis = spText.split(":");
  28. var lg = spTextLis.length;
  29. for (var j=0; j < lg; j++){
  30. var m = Math.pow(60, (lg - 1 - j));
  31. vidTime = parseInt(spTextLis[j]) * m;
  32. sumOne += vidTime;
  33. }
  34. } else {
  35. vidTime = parseInt(spText);
  36. sumOne += vidTime;
  37. }
  38. timeList.push(sumOne);
  39. sumAll += sumOne;
  40. }
  41. // console somethings
  42. console.log("The playlist is total: " + sumAll/3600 + " hours");
  43. console.log("average time of all: " + (sumAll / allSpan.length));
  44. console.log("longest video time(minutes): " + (Math.max.apply(Math, timeList)) / 60);
  45. console.log("shortest video time(minutes): " + (Math.min.apply(Math, timeList)) / 60);
  46. })();