Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ニコニコ動画のwatchページのタブを追加する関数
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 };
}
// ニコニコ大百科という名前のタブを作る (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
You can’t perform that action at this time.