跳转到内容

MediaWiki:Common.js

来自SCR公司
Kakushi留言 | 贡献2026年1月7日 (三) 01:07的版本

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */

document.addEventListener('DOMContentLoaded', () => {
  document.querySelectorAll('.scr-collapse-header').forEach(header => {
    const content = header.nextElementSibling;
    const textOpen = header.dataset.open;
    const textClose = header.dataset.close;

    header.addEventListener('click', () => {
      const expanded = content.style.maxHeight && content.style.maxHeight !== '0px';

      if (expanded) {
        content.style.maxHeight = '0';
        header.textContent = textOpen;
      } else {
        content.style.maxHeight = content.scrollHeight + 'px';
        header.textContent = textClose;
      }
    });
  });
});