Created
October 20, 2010 11:42
-
-
Save gifnksm/636265 to your computer and use it in GitHub Desktop.
ニコニコ動画のwatchページのタブを追加する関数
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
function nicovideo_createPanel(id, labelText) { | |
let panelID = 'itab_' + id; | |
let 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); | |
let panel = document.createElement('div'); | |
panel.id = panelID; | |
panel.className = 'info'; | |
document.querySelector('.info_frm').appendChild(panel); | |
unsafeWindow.cont = unsafeWindow.$$('.info_frm .info'); | |
const act = unsafeWindow.act; | |
label.addEventListener('click', function(e) { | |
e.preventDefault(); | |
Array.forEach(document.querySelectorAll('#itab td a'), | |
function(elm) elm.classList.remove(act)); | |
label.classList.add(act); | |
Array.forEach(document.querySelectorAll('.info_frm .info'), | |
function(elm) elm.id === panelID | |
? elm.classList.add(act) | |
: elm.classList.remove(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) | |
let { panel, label } = nicovideo_createPanel('nicopedia', 'ニコニコ大百科'); | |
// タブのパネルに表示する内容を指定する | |
panel.appendChild(document.createTextNode('hogehoge')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment