スキップしてメイン コンテンツに移動

Operaで使えるニコニコ大百科ポップアップを更新

昨日のコードだと、FirefoxとChromeでは動かなかったから動くようにちょっち修正。
後、見た目とかを一部修正。
影は面倒だからつけなかった。
Flashに重なると表示されないのはブラウザの仕様。あきらめてください。
これがドラッグできると良いよね。
え? 作れ?
面倒。

// ==UserScript==
// @name Popup Nico Dict for Iframe
// @namespace http://gigi-net.net
// @include http://dic.nicovideo.jp/*
// @include http://www.nicovideo.jp/watch/*
// @author giginet modified Arc Cosine
// @version 1.1
// ==/UserScript==
(function(){
/** simple version of $X
* $X(exp);
* $X(exp, context);
* @source http://gist.github.com/3242.txt
*/
var $X = function (exp, context) {
context || (context = document);
var expr = (context.ownerDocument || context).createExpression(exp, function (prefix) {
return document.createNSResolver(context.documentElement || context).lookupNamespaceURI(prefix) ||
context.namespaceURI || document.documentElement.namespaceURI || "";
});
var result = expr.evaluate(context, XPathResult.ANY_TYPE, null);
switch (result.resultType) {
case XPathResult.STRING_TYPE : return result.stringValue;
case XPathResult.NUMBER_TYPE : return result.numberValue;
case XPathResult.BOOLEAN_TYPE: return result.booleanValue;
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
// not ensure the order.
var ret = [], i = null;
while (i = result.iterateNext()) ret.push(i);
return ret;
}
return null;
}


var tip = null;

var init = function(){
if( checkOption() ){
createNicoDic();
}else{
popup();
}
};

var createNicoDic = function(){
document.getElementById("container").style.display = 'none';
//clear div
var cap = document.getElementsByTagName("h1")[0].innerHTML;
var desc = document.getElementById("article");
var article= desc.innerHTML;

//置き換え用の適当な文字列生成
var rand_st ="st"+(new Date()).getTime();
var rand_ed ="ed"+(new Date()).getTime();

//ページメニューを消去
article =article.replace(/<div id..page-menu.>.*<.div>/i,"");

//見出しを適当な文字に変換
article =article.replace(/<h2.*?>/gm,rand_st);
article =article.replace(/<.h2>/gm,rand_ed);
//ページメニューを消去
article =article.replace(/<div id..page-menu.>.*<.div>/,"");
//タグを全消去
article =article.replace(/<.*?>/mg,"");
//適当な文字を見出しに戻す
article =article.replace(new RegExp(rand_st,"gm"),"<br>【");
article =article.replace(new RegExp(rand_ed,"gm"),"】<br>");
//空の見出しを削除
article =article.replace(/<br>【.*】<br>\s*<br>【/gm,"【");

var ARTICLE_LENGTH = 300;
showText = article.substring(0,ARTICLE_LENGTH-1);
if(article.length>=ARTICLE_LENGTH){
showText +="...";
}
//タイトルを追加
showText ="<h1>"+cap+"</h1>"+showText;
var descDiv = document.body.appendChild(document.createElement('div'));
descDiv.style.display = 'block';
descDiv.style.fontSize='10pt';
descDiv.style.fontFamily='sans-serif';
descDiv.style.textAlign='left';
descDiv.style.lineheight='110%';
descDiv.style.color='#333333';
descDiv.style.paddingLeft='16px';
descDiv.style.paddingRight='5px';
descDiv.style.height = "220px";
descDiv.style.background = 'cornsilk';
descDiv.innerHTML = showText;
};
var popup = function(){
var loc = location.href.match(/nicovideo\.jp\/watch/);
if(loc){
var iconList = $X('//div[@id="video_tags"]/p[@class="tag_txt"]/nobr/a/img[@class="txticon"]');
for( var i=0, l=iconList.length; i<l; i++ ) (function(list){
var link = list.parentNode.href;
list.addEventListener( 'mouseover', function(e){ showTips(e,link); }, false );
list.addEventListener( 'mouseout', function(){ hideTips(); }, false );
})(iconList[i]);
}
};
var checkOption = function(){
var loc =location.href.match(/popup=true/);
if( !loc ){
return false;
}
return true;
};
var showTips = function(e,link){
if( tip != null ){ hideTips(); };
tip = document.createElement("div");
var findPos = function(e){ return { "x":e.clientX, "y": e.clientY }; };
var pos = findPos(e);
tip.style.top = pos.y - 240 +'px';
tip.style.left = pos.x + 20 + 'px';
tip.style.width = '340px';
tip.style.height = '220px';
tip.style.zIndex = '10002';
tip.style.position = 'absolute';
tip.addEventListener( "click", hideTips, false );

var iframe = tip.appendChild(document.createElement("iframe"));
iframe.src = link + "?popup=true";
iframe.width = "340px";
iframe.height= "220px";
iframe.frameborder = "0";
iframe.scrolling = 'no';
iframe.style.zIndex = '10000';

var closeBox = tip.appendChild(document.createElement("div"));
closeBox.style.position = 'absolute';
closeBox.style.top = "2px";
closeBox.style.marginLeft = "2px";
closeBox.style.border = "sold 1px #fcfcfc";
closeBox.style.zIndex = "10003";
closeBox.style.width = '16px';
closeBox.style.height = '16px';
closeBox.style.background= '#333333';
closeBox.style.color= '#ffffff';
closeBox.style.fontWeight= 'bold';
closeBox.appendChild(document.createTextNode('X'));
closeBox.addEventListener( "click", hideTips, false );
document.body.appendChild(tip);

};
var hideTips = function(){
tip.parentNode.removeChild(tip);
tip = null;
}

//fire
var timer = setTimeout(init,1000);
})();

コメント

このブログの人気の投稿

EFIブートローダを移動した話

EFIブートローダを移動した HX90に環境を整え終わってから、アホな事をしたので、その記録を残す。 SSD: Cドライブ SSD: Dドライブ(データストレージ用) + ESP※ SSD: Eドライブ(データストレージ用) ※ESP(EFI System Partition) インストールした時、こんな構成だった。 ESPがDドライブにあるのが気持ち悪かったので、これを削除した。 そしたら、BIOS画面が出るだけになり、Windowsが起動しなくなった。 移動手順 この時の自分はMBRをふっ飛ばした時と同じ現象だと思ったので、MBRというキーワードで検索したが、今はEFIブートローダーと呼んでいるらしい。 【Win10】任意のディスクにEFIブートローダをインストールする 色々検索した結果この記事が参考になった。 Diskpartを使って、パーティションを新たに分割し、bcdbootを実行して、無事に事なきを得た。 パーティションの分割はこんな感じ Diskpart Select volume 0 shrink desired = 200 Select disk 0 Create partition EFI size=200 Format quick fs=fat32 label="ESP" Assign letter=P exit EFIブートローダーのインストールはこんな感じ bcdboot C:\Windows /s P: /f UEFI ちなみに、自分の環境だけの問題なのだが、コマンドラインで、「\」を入力するのができなかった。我が家のキーボードはHHKBだけなので、日本語配列を無理やり適用されると、バックスラッシュが入力できないという不具合が生じる。 結局、コマンドプロンプトからマウスで範囲選択してコピーして貼り付けるという荒業でクリアした。 普通の人は、何も考えずに、\を入力すれば良い。 最終的に SSD: Cドライブ + ESP※ SSD: Dドライブ(データストレージ用) SSD: Eドライブ(データストレージ用) ※ESP(EFI System Partition) という構成に切り替えることができた。

PlemolJP導入

PlemolJP を導入した 思い立つことがあり、 PlemolJP をインストールする事にした。 自分は、PowerLine を使っているので、PlemolJP Nerd Fonts 版である、PlemolJP_NF をダウンロードしてインストールした PlemolJP の releases から、PlemolJP_NF_vx.x.x.zip をダウンロードする。 zip を展開し、PlemolJPConsoleNF-Regular.ttf をインストールする set guifont=PlemolJP_Console_NF:h18 を gvimrc に書く(フォントサイズはお好きに) ちなみに、これは Windows 限定の設定なので、Mac や Linux などで導入する際には、別の方法をオススメする。 余談 gvimrc に指定するフォント名が微妙にわかりづらい。 普段は、 set guioptions-=m してメニューバーは出していないが、今回は :set guioptions+=m を実行して、編集 → フォント設定からフォントを選び、フォント名に入力されている文字列をコピペして、スペース部分をアンダースコアで置き換えた。 この辺のルールとかに詳しい人にぜひとも教えて欲しい所。 導入した感想 今までの Powerline フォントはいまいちなのが多かったが、PlemolJP の表示は非常に良い。 今後はこちらをメインで使って行きたい。 あと、僕はヱビス派です。