Ztm0929留言 | 贡献
添加Cloudflare网络分析功能
 
Ztm0929留言 | 贡献
无编辑摘要
 
(未显示同一用户的3个中间版本)
第7行: 第7行:
document.head.appendChild(script);
document.head.appendChild(script);
// End Cloudflare Web Analytics
// 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");
        }
    }
});

2025年5月10日 (六) 14:24的最新版本

/* 这里的任何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");
        }
    }
});