MediaWiki:Common.js:修订间差异

天明留言 | 贡献
测试页脚色彩
标签已被回退
天明留言 | 贡献
无编辑摘要
标签已被回退
第30行: 第30行:


document.addEventListener("DOMContentLoaded", async () => {
document.addEventListener("DOMContentLoaded", async () => {
   const img = document.querySelector('img[alt="Powered by MyWiki"]');
  // 选择要替换的 SVG img
   if (img) {
   const poweredSvgImg = document.querySelector('#footer-poweredbyico img[alt="Powered by MyWiki"]');
    const resp = await fetch(img.src);
   if (!poweredSvgImg) return;
    const svgText = await resp.text();
 
    const wrapper = document.createElement("a");
  const resp = await fetch(poweredSvgImg.src);
    wrapper.href = "https://ztm0929.me/";
  const svgText = await resp.text();
    wrapper.innerHTML = svgText;
 
    img.replaceWith(wrapper);
  // 创建内联 SVG
   }
  const wrapper = document.createElement("a");
  wrapper.href = "https://ztm0929.me/";
  wrapper.className = "cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled";
  wrapper.target = "_blank";
  wrapper.innerHTML = svgText;
 
  // 替换原来的 img
  poweredSvgImg.replaceWith(wrapper);
 
  // 设置默认颜色
  setLogoMode(document.body.classList.contains('skin-theme-clientpref-night') ? 'night' : 'day');
 
  // 可选:监听用户点击按钮切换主题
  document.querySelector('#toggle-theme')?.addEventListener('click', () => {
    const mode = document.body.classList.contains('skin-theme-clientpref-night') ? 'day' : 'night';
    document.body.classList.toggle('skin-theme-clientpref-night');
    document.body.classList.toggle('skin-theme-clientpref-day');
    setLogoMode(mode);
   });
});
});
// 动态修改 SVG 填充颜色
function setLogoMode(mode) {
  const svg = document.querySelector('#footer-poweredbyico a svg');
  if (!svg) return;
  const fills = {
    day: ['#666', '#333', '#1a1a1a', '#000'],  // path1~path4
    night: ['#999', '#ccc', '#e6e6e6', '#fff']
  };
  ['path1','path2','path3','path4'].forEach((cls, idx) => {
    const el = svg.querySelector('.' + cls);
    if (el) el.setAttribute('fill', fills[mode][idx]);
  });
}