全站通知:
用户:646195980/FoldTable.js
刷
历
编
跳到导航
跳到搜索
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/**
* FoldTable.js | Inspiration comes from https://wiki.biligame.com/gt/?curid=17735
* Author: 飞小RAN (https://wiki.biligame.com/gt/User:646195980)
* License: See https://wiki.biligame.com/gt/User:646195980#License
* 15折 怎么折 都只能看评分
**/
(function() {
'use strict';
document.querySelectorAll('.foldtable').forEach(table => {
let data = {
intro: '选择展示竖列:<span class="fold-list">',
outro: '</span>',
list: []
};
let num = 0;
table.querySelector('thead tr').children.forEach(col => {
num++;
col.classList.add('fold-col');
col.classList.add(`col-${num}`);
});
const ch = table.querySelector('.col-1').clientHeight;
table.dataset.fold.split(',').forEach(fold => {
data.list.push({
num: fold.split(':')[0],
title: table.querySelector(`.col-${fold.split(':')[0]}`).textContent?table.querySelector(`.col-${fold.split(':')[0]}`).textContent:fold.split(':')[0],
hide: fold.split(':')[1] || '0'
});
});
let shtml = '';
shtml += data.intro;
data.list.forEach(i => {
let m = '';
if(i.hide === '2') {
m = 'fold-mshow';
table.classList.add(`fold-m${i.num}`);
}
if(i.hide === '1') {
table.classList.add(`fold-${i.num}`);
}
shtml += `<button class="fold-button ${i.hide?'':'fold-show'} ${m}" title="${i.title}" data-col="${i.num}" data-hide="${i.hide}">${i.title}</button>`;
});
shtml += data.outro;
let sdiv = document.createElement('div');
sdiv.classList.add('fold-box');
sdiv.innerHTML = shtml;
table.style.marginTop = ch;
sdiv.style.marginTop = -ch;
table.querySelector('thead').prepend(sdiv);
table.querySelectorAll('.fold-list .fold-button').forEach(col => {
let cum = col.dataset.col;
col.addEventListener('click', function(e) {
col.classList.remove(`fold-mshow`);
table.classList.remove(`fold-m${cum}`);
col.classList.toggle(`fold-show`);
table.classList.toggle(`fold-${cum}`);
});
});
});
})();