Skip to content

Instantly share code, notes, and snippets.

@st98
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save st98/d11200a770117a4e63d6 to your computer and use it in GitHub Desktop.

Select an option

Save st98/d11200a770117a4e63d6 to your computer and use it in GitHub Desktop.
ニコニコ動画のマイリストの合計再生時間を出力するヤツ。
(function () {
if (!(String.prototype.repeat)) {
String.prototype.repeat = function (n) {
if (n < 0) throw RangeError('Invalid repeat count');
return Array(n + 1).join(this);
};
}
function zfill(s, n) {
if (s.length >= n) return s;
return ('0'.repeat(n) + s).slice(-n);
}
var s = 0;
[].forEach.call(document.getElementsByClassName('vinfo_length'), function (e) {
var v = e.firstChild.firstChild.nodeValue;
v.split(':').reverse().forEach(function (c, i) {
s += parseInt(c, 10) * Math.pow(60, i);
});
});
console.log([s / 3600, (s % 3600) / 60, s % 60].map(function (a) {
return zfill(String(Math.floor(a)), 2);
}).join(':'));
})();
(function(){String.prototype.repeat||(String.prototype.repeat=function(a){if(0>a)throw RangeError("Invalid repeat count");return Array(a+1).join(this)});var b=0;[].forEach.call(document.getElementsByClassName("vinfo_length"),function(a){a.firstChild.firstChild.nodeValue.split(":").reverse().forEach(function(a,c){b+=parseInt(a,10)*Math.pow(60,c)})});console.log([b/3600,b%3600/60,b%60].map(function(a){a=String(Math.floor(a));a=2<=a.length?a:("0".repeat(2)+a).slice(-2);return a}).join(":"))})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment