Last active
November 3, 2015 06:11
-
-
Save karronoli/1583400 to your computer and use it in GitHub Desktop.
b.hatena.ne.jp/video + niconico customize
This file contains hidden or 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== | |
// @name test | |
// @namespace http://d.hatena.ne.jp/karronoli | |
// @description add nicovideo info to b.hatena.ne.jp/video | |
// @include http://b.hatena.ne.jp/video | |
// @version 1.0 | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
let nico_link = document.evaluate( | |
'//a[contains(@href, "nicovideo.jp/")][@class="entry-link"]', | |
document, null, 7, null); | |
for (let i = 0; i < nico_link.snapshotLength; ++i) (function (nl) { | |
let [target] = nl.pathname.match(/[^\/]+$/); | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: 'http://ext.nicovideo.jp/api/getthumbinfo/' + target, | |
data: '', | |
onload: function(res) { | |
let rt = res.responseText; | |
let test = rt.match(/<(video_id)>(.+)<\/\1>/); | |
if (!test || test[2] != target) return ; | |
let info = [ | |
{view_counter: rt.match(/<(view_counter)>(.+)<\/\1>/)[2]}, | |
{comment_num: rt.match(/<(comment_num)>(.+)<\/\1>/)[2]}, | |
{length: rt.match(/<(length)>(.+)<\/\1>/)[2]} | |
]; | |
let ul = document.createElement('ul'), | |
k0 = function (o) {return Object.keys(o)[0]}; | |
ul.innerHTML = info.reduce(function(p, c) { | |
return p + '<li>' + k0(c) + ' : ' + c[k0(c)] + '</li>'; | |
}, ''); | |
nl.parentNode.appendChild(ul); | |
} | |
}); | |
})(nico_link.snapshotItem(i)) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
work on Firefox 11.0 & Greasemonkey 0.9.18 by version 1.0