跳转到内容

MediaWiki:Common.js:修订间差异

来自天明的百科全书
Ztm0929留言 | 贡献
无编辑摘要
标签已被回退
Ztm0929留言 | 贡献
无编辑摘要
标签手工回退
 
第28行: 第28行:
     }
     }
});
});
document.addEventListener("DOMContentLoaded", async () => {
  // 选择要替换的 SVG img
  const poweredSvgImg = document.querySelector('#footer-poweredbyico img[alt="Powered by MyWiki"]');
  if (!poweredSvgImg) return;
  const resp = await fetch(poweredSvgImg.src);
  const svgText = await resp.text();
  // 创建内联 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]);
  });
}

2025年9月9日 (二) 03:48的最新版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// Cloudflare Web Analytics
var script = document.createElement('script');
script.defer = true;
script.src = 'https://static.cloudflareinsights.com/beacon.min.js';
script.setAttribute('data-cf-beacon', '{"token": "6180aa28fe1943b48c4059a5056f4738"}');
document.head.appendChild(script);
// End Cloudflare Web Analytics

$(function () {
    // 只在 Special:Search 页面运行
    if (mw.config.get("wgCanonicalSpecialPageName") === "Search") {
        const searchTerm = mw.util.getParamValue("search");
        const googleUrl = "https://www.google.com/search?q=" + encodeURIComponent(searchTerm);

        const $googleLink = $("<p>").html(
            `你也可以到 <a href="${googleUrl}" target="_blank" rel="noopener">Google 中搜索“${searchTerm}”</a>。`
        );

        // 优先在有搜索结果时插入
        if ($(".mw-search-results").length) {
            $googleLink.insertAfter(".mw-search-results");
        }
        // 否则在没有结果提示后插入
        else if ($(".mw-search-nonefound").length) {
            $googleLink.insertAfter(".mw-search-nonefound");
        }
    }
});