-
-
Save azu/845920 to your computer and use it in GitHub Desktop.
ニコニコ動画のwatchページのタブを追加する関数(Firefox依存なし)
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
// http://blog.livedoor.jp/eeu/archives/55316335.html | |
var addClassName = function(el, className) { | |
var reg = new RegExp('(^| +)' + className + '($| +)'); | |
if (!reg.test(el.className)) | |
el.className += ' ' + className; | |
}; | |
var removeClassName = function(el, className) { | |
var reg = new RegExp('(^| +)' + className + '($| +)'); | |
el.className = el.className.replace(reg, ' '); | |
}; | |
function nicovideo_createPanel(id, labelText) { | |
var panelID = 'itab_' + id; | |
var label = document.createElement('a'); | |
label.href = '#' + panelID; | |
label.innerHTML = '<div>' + labelText + '</div>'; | |
// remove extra <a>...</a> | |
label.firstChild.textContent = labelText; | |
document.querySelector('#itab td').appendChild(label); | |
var panel = document.createElement('div'); | |
panel.id = panelID; | |
panel.className = 'info'; | |
document.querySelector('.info_frm').appendChild(panel); | |
//unsafeWindow.cont = unsafeWindow.$$('.info_frm .info'); | |
var act = "in";// unsafeWindow.act | |
label.addEventListener('click', function(e) { | |
e.preventDefault(); | |
Array.forEach(document.querySelectorAll('#itab td a'), function(elm) { | |
removeClassName(elm, act) | |
}); | |
addClassName(label, act); | |
Array.forEach(document.querySelectorAll('.info_frm .info'), function(elm) { | |
elm.id === panelID | |
? addClassName(elm, act) | |
: removeClassName(elm, act) | |
}); | |
}, false); | |
return { label: label, panel: panel }; | |
} |
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
// ニコニコ大百科という名前のタブを作る (panel.id == nicopedia) | |
var nicovideo_createPanel_res = nicovideo_createPanel('nicopedia', 'ニコニコ大百科'), | |
panel = nicovideo_createPanel_res.panel, | |
label = nicovideo_createPanel_res.label; | |
// タブのパネルに表示する内容を指定する | |
panel.appendChild(document.createTextNode('hogehoge')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment