選択範囲内にあるニコニコ動画(らしきビデオ)の情報を取得するGreasemonkey
「Fast Look up nicoinfo」を2番煎じですが、ためらわず公開します。
選択範囲内の文字やリンク先に、ニコニコ動画のビデオID(sm\d+)らしき文字を見つけると、画面下に情報をポップアップします。
ポップアップをクリックしたり、画面のどこか適当なところをクリックすると表示が消えます。
確かめてないのですが、参考にさせてもらった「Fast Look up Alc」や「Fast Look up goo」などに干渉しそうです。
JavaScriptを公開するのによいところがないかなぁ。
// ==UserScript== // @name Fast Look up nicoinfo // @namespace http://d.hatena.ne.jp/AOI-CAT/ // @include * // @exclude http://www.nicovideo.jp/thumb* // @version 0.1 // ==/UserScript== /* * Based on: * Fast Look up Alc by cho45 * http://userscripts.org/scripts/show/12024 * Fast Look up goo by gan2 * http://d.hatena.ne.jp/gan2 * * Special thanks: * NicoVideo thuminfo Check by Sore_0 * http://d.hatena.ne.jp/Sore_0/ * */ (function(){ var popup = []; window.addEventListener("mouseup", function(evt) { if (!window.getSelection()) return; var selection = window.getSelection().toString(); var re = new RegExp(/sm\d+/); var vid = selection.match(re); if (vid == null) { selection = getSelectedInnerHTML(); vid = selection.match(re); if (vid == null) return; } GM_xmlhttpRequest({ method: 'GET', url: 'http://www.nicovideo.jp/api/getthumbinfo/' + vid, onload: function(req) { var dom = (new DOMParser()).parseFromString(req.responseText, 'text/xml'); var apiStat = dom.getElementsByTagName('nicovideo_thumb_response')[0].getAttribute('status'); if (apiStat != "ok") return; var t = function(xmlTagName) { return dom.getElementsByTagName(xmlTagName)[0].textContent; } var title = t('title'); var desc = t('description'); var img = t('thumbnail_url'); var retrieve = t('first_retrieve'); var wurl = t('watch_url'); var len = t('length'); var cnt = t('view_counter'); var cmt = t('comment_num'); var lst = t('mylist_counter'); var lcmt = t('last_res_body'); var [year, month, day, hour, minute, sec] = retrieve.replace( /[-:T]/g,',' ).replace( /\+.+$/,'' ).split(','); var html = '<table><tr><td>'+ '<a href="%WURL%" target="_blank">'+ '<img alt="%TITLE%" src="%IMG%" class="thumb_img_normal" height="70" width="94">'+ '</a></td><td>'+ '<p class="TXT10"><strong>%Y%/%M%/%D% %H%:%N%:%S%</strong> 投稿 </p>'+ '<p class="TXT12"><a href="%WURL%" target="_blank" class="video">%TITLE%</a>'+ '<br> %DESC%</p>'+ '</td></tr><tr><td>'+ '<p class="TXT10"><strong>%LEN%</strong>'+ '<br> 再生:<strong>%CNT%</strong>'+ '<br> コメント:<strong>%CMT%</strong>'+ '<br> マイリスト:<strong>%LST%</strong></p></td>'+ '<td><div class="thumb_res">'+ '<p class="TXT12"><strong>%LCMT%</strong></p></div></td></tr></table>'; html = html.replace(/%TITLE%/g,title).replace(/%WURL%/g,wurl).replace(/%IMG%/g,img ).replace(/%LEN%/,len).replace(/%DESC%/,desc ).replace(/%CNT%/,cnt).replace(/%CMT%/,cmt).replace(/%LST%/,lst ).replace(/%LCMT%/,lcmt ).replace(/%Y%/,year).replace(/%M%/,month).replace(/%D%/,day ).replace(/%H%/,hour).replace(/%N%/,minute).replace(/%S%/,sec ).replace( /class="thumb_res"/g, 'style="background: #FFF none repeat scroll 0%;'+ 'border: 2px solid #CCC; margin-top: 4px; padding: 6px;"' ).replace( /class="TXT10"/g, 'style="font-size: 10px;line-height:14px;"' ).replace( /class="TXT12"/g, 'style="font-size: 12px;line-height:16px;"' ).replace( /<img /g, '<img style="border: 0px none;" '); var div = document.createElement('div'); div.style.position = 'fixed'; div.style.bottom = '0'; div.style.left = '0'; div.style.right = '0'; div.style.border = '1px solid #000'; div.style.background = '#FFF'; div.style.color = '#000'; div.style.maxHeight = '50%'; div.style.overflow = 'auto'; div.style.opacity = '1.0'; div.style.textAlign = 'left'; div.style.zIndex = '10000' div.addEventListener('click', function(e) { e.stopPropagation(); }, false); div.addEventListener('click', function(e) { div.style.display = 'none'; }, false); div.innerHTML = html; document.body.appendChild(div); popup.push(div); } }); }, false); document.body.addEventListener('click', function(evt) { var p; while(p = popup.pop()) { p.parentNode.removeChild(p); } }, false); function getSelectedInnerHTML() { var sel = window.getSelection(); if (sel) { var oRange = sel.getRangeAt(0); var df = oRange.cloneContents(); var div = document.createElement('div'); div.appendChild(df); return div.innerHTML; } } })();