Skip to content

Instantly share code, notes, and snippets.

@juwoong
Last active April 2, 2019 09:19
Show Gist options
  • Save juwoong/ca6ba58014170a07317576e2f16fc86f to your computer and use it in GitHub Desktop.
Save juwoong/ca6ba58014170a07317576e2f16fc86f to your computer and use it in GitHub Desktop.
Get Playlists playtime
String.prototype.format = function() {
a = this;
for (k in arguments) {
a = a.replace("{" + k + "}", arguments[k])
}
return a
}
var playList = document.getElementsByTagName('ytd-two-column-browse-results-renderer');
playList = playList[0];
var musics = playList.getElementsByClassName('ytd-thumbnail-overlay-time-status-renderer');
var musicList = Array.prototype.slice.call(musics);
var allSecs = 0;
for(let i=0; i<musicList.length; i++){
const v = musicList[i];
const innerValue = v.innerHTML.replace(/\n/g, "").replace(/\s+/, "");
const innerTimes = innerValue.split(':');
for(let j=0; j<innerTimes.length; j++) {
allSecs += innerTimes[j] * ( 60 ** (innerTimes.length - j - 1));
}
}
var hour = Math.floor(allSecs/(60**2));
var minute = Math.floor((allSecs%(60**2))/60);
var second = allSecs%60;
var title = document.getElementById('title').innerText;
var result_string = "플레이리스트 \"{3}\"의 재생 시간은\n{0}시간 {1}분 {2}초 입니다.";
console.log(result_string.format(hour, minute, second, title));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment