Difference between revisions of "MediaWiki:Common.js"

From UKTAPS.CO.UK Wiki
Jump to: navigation, search
Line 2: Line 2:
  
 
$(document).ready(function() {
 
$(document).ready(function() {
     // 使用 encodeURIComponent 匹配,或者直接检查页面标题的真实名称
+
     // 这里的 Key 必须与 MediaWiki 内部识别的页面名称完全一致
 +
    var seoMap = {
 +
        'Installation_Guide:_Three_Way_Kitchen_Taps': 'https://www.uktaps.co.uk/three-way-kitchen-taps-c-23_28.html'
 +
    };
 +
 
 
     var currentPage = mw.config.get('wgPageName');
 
     var currentPage = mw.config.get('wgPageName');
 
      
 
      
     // 我们用 console.log 把当前名称打印出来,方便调试
+
     // 调试用:如果在浏览器控制台看到这个,说明代码已加载
     console.log('Current Page Name is: ' + currentPage);
+
     console.log('Current Page Name for Canonical check: ' + currentPage);
 
 
    var seoMap = {
 
        'How_to_Connect_3_Way_Kitchen_Filter_Taps_&_Under-Sink_Pipework': 'https://www.uktaps.co.uk/three-way-kitchen-taps-c-23_28.html'
 
    };
 
  
 
     if (seoMap[currentPage]) {
 
     if (seoMap[currentPage]) {
Line 17: Line 17:
 
         link.setAttribute('href', seoMap[currentPage]);
 
         link.setAttribute('href', seoMap[currentPage]);
 
         document.head.appendChild(link);
 
         document.head.appendChild(link);
         console.log('SEO: Canonical tag injected for ' + currentPage);
+
         console.log('SEO: Canonical tag successfully injected!');
 
     }
 
     }
 
});
 
});

Revision as of 13:15, 15 June 2026

/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function() {
    // 这里的 Key 必须与 MediaWiki 内部识别的页面名称完全一致
    var seoMap = {
        'Installation_Guide:_Three_Way_Kitchen_Taps': 'https://www.uktaps.co.uk/three-way-kitchen-taps-c-23_28.html'
    };

    var currentPage = mw.config.get('wgPageName');
    
    // 调试用:如果在浏览器控制台看到这个,说明代码已加载
    console.log('Current Page Name for Canonical check: ' + currentPage);

    if (seoMap[currentPage]) {
        var link = document.createElement('link');
        link.setAttribute('rel', 'canonical');
        link.setAttribute('href', seoMap[currentPage]);
        document.head.appendChild(link);
        console.log('SEO: Canonical tag successfully injected!');
    }
});