// ==UserScript==
// @name Bro3 SkillText Popup
// @namespace bro3_skilltext_popup
// @description ブラウザ三国志用デッキ内スキル詳細ポップアップ
// @include http://*.3gokushi.jp/card/deck.php*
// ==/UserScript==
//
// 2012-09-16 ver. 2.00 内部処理の変更
// 2010-10-06 ver. 1.02 次のLvまでに必要な経験値表示の追加(exp行)
// ポップアップ表示該当行のどこでもポップアップするように修正
// 2010-09-26 ver. 1.01 mixi版仕様変更に伴い表示ボックスの場所とサイズを変更
// 2010-09-18 ver. 1.00 公開
(function() {
setStyle();
setMouseAction();
//---- 処理終了
/**
* スタイルの指定
*/
function setStyle() {
var css = '' +
'div#popStatusBox {' +
' position: absolute;' +
' z-index: 1;' +
' width: 144px;' +
' text-align: left;' +
'}' +
'div#popStatusBox span {' +
' float: right;' +
' line-height: 1.4;' +
' padding: 2px 3px;' +
' border: 1px solid #bfbfbf;' +
' color: #000;' +
' font-size: 10px;' +
' background: #fff;' +
'}' +
// カードがセット出来ない場合の画像サイズ指定
'form#deck_file div.statusDetail img.aboutdeck {' +
' width: 78px;' +
'}';
addStyle(css);
}
/**
* headにスタイルを埋め込む
* @param css スタイル
*/
function addStyle(css) {
var head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
/**
* マウスオーバー、マウスアウトのアクションを設定する
*/
function setMouseAction() {
var td = xpath('//table[contains(concat(" ", normalize-space(@class), " "), "statusParameter2")]//td');
for (var i = 0, len = td.snapshotLength; i < len; i++) {
// ステータスをポップアップ表示する
td.snapshotItem(i).addEventListener('mouseover',
function (e) {
var bros = xpath('./preceding-sibling::th', e.currentTarget);
var type = bros.snapshotItem(0).innerHTML;
var target = xpath('./ancestor::div[contains(concat(" ", normalize-space(@class), " "), "cardStatusDetail")]//div[contains(concat(" ", normalize-space(@class), " "), "cardWrapper2col")]', e.currentTarget);
var text = getText(target.snapshotItem(0), type);
if (text) {
openWindow(e.currentTarget, 'popStatusBox', text, [-160, 5]);
}
},
false);
// ポップアップしたステータスを非表示にする
td.snapshotItem(i).addEventListener('mouseout',
function () {
closeWindow(document.getElementById('popStatusBox'));
},
false);
}
}
function getText(element, type) {
var text = '';
var target;
if (type.indexOf('スキル') !== -1) {
target = xpath('.//div[contains(concat(" ", normalize-space(@class), " "), "skill' + type.slice(-1) + '")]', element);
if (target.snapshotItem(0)) {
text = '' + target.snapshotItem(0).innerHTML.replace(/ /g, '
') + '';
}
}
else if (type.indexOf('exp') !== -1) {
target = xpath('.//span[contains(concat(" ", normalize-space(@class), " "), "ex")]', element);
if (target.snapshotItem(0)) {
text = '' + target.snapshotItem(0).innerHTML.split(' | ')[1].replace(':', ': ') + '';
}
}
return text;
}
/**
* 指定文字列をポップアップ表示する
* @param element 基準となる要素
* @param id ポップアップする要素のID
* @param text 表示する文字列
* @param position 基準からの位置
*/
function openWindow(element, id, text, position) {
var x = (position && position[0]) ? position[0] : 0;
var y = (position && position[1]) ? position[1] : 0;
var popBox = document.createElement('div');
popBox.id = id;
popBox.innerHTML = text;
element.style.position = 'relative';
document.body.appendChild(popBox);
popBox.style.left = (element.offsetLeft + element.offsetWidth + x) + 'px';
popBox.style.top = (element.offsetTop + element.offsetHeight + y) + 'px';
}
/**
* 指定された要素を削除する
* @param element 要素
*/
function closeWindow(element) {
if (element) {
element.parentNode.removeChild(element);
}
}
/**
* XPath
* @param query XPath構文
* @param e ルートとなる要素
* @return XPathResultオブジェクト
*/
function xpath() {
var e;
var query;
switch (arguments.length) {
case 1:
e = document;
query = arguments[0];
break;
case 2:
e = arguments[1];
query = arguments[0];
break;
default:
e = document;
query = 'null';
break;
}
return document.evaluate(query, e, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
}
}
)();