Last active
December 27, 2015 09:09
-
-
Save critical-bug/7301357 to your computer and use it in GitHub Desktop.
ニコニコ動画でプレーヤー下部のプレイリストに各動画のマイリス率を表示する userscript。Chrome で動く版。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @license magnet:?xt=urn:btih:5305d91886084f776adcf57509a648432709a7c7&dn=x11.txt | |
// @name mlratio | |
// @description put Mylist ratio (= # of lists the video saved / # of video views) in playlist | |
// @namespace http://twitter.com/criticabug | |
// @include http://www.nicovideo.jp/watch/* | |
// @grant none | |
// @run-at document-end | |
// @version 1.10 | |
// ==/UserScript== | |
(function (w) { | |
'use strict'; | |
var extractNumber = function (elem) { | |
return parseInt(elem.innerText.replace(',',''), 10); | |
}; | |
var container = w.document.querySelector('#playlistContainerInner'); | |
var elems = container.querySelectorAll('li.playlistItem .videoInformation'); | |
var len = elems.length; | |
if (len == 0) { | |
console.warn('videoInformation not found'); | |
} | |
var i; | |
for (i = 0; i < len; i++) { | |
(function (vInformation) { | |
// closure | |
var mylist = vInformation.querySelector('li.videoMylist span'); | |
mylist.addEventListener('DOMSubtreeModified', function (event) { | |
var view = vInformation.querySelector('li.videoView span'); | |
if (isNaN(extractNumber(view)) || isNaN(extractNumber(mylist)) || vInformation.querySelector('li.videoMlratio')) { | |
return; | |
} | |
var li = w.document.createElement('li'); | |
li.className = 'videoMlratio' | |
li.innerHTML = 'マイ率:<span>' + Math.round(1000.0 * extractNumber(mylist) / extractNumber(view)) / 10.0 + '</span>%'; | |
vInformation.appendChild(li); | |
}); | |
})(elems[i]); | |
} | |
})(typeof unsafeWindow === 'undefined' ? window : unsafeWindow); | |
// @license-end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment