Difference between revisions of "MediaWiki:Common.js"
From UKTAPS.CO.UK Wiki
| Line 2: | Line 2: | ||
$(document).ready(function() { | $(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'); | var currentPage = mw.config.get('wgPageName'); | ||
| − | // | + | // 调试用:如果在浏览器控制台看到这个,说明代码已加载 |
| − | console.log('Current Page Name | + | console.log('Current Page Name for Canonical check: ' + currentPage); |
| − | |||
| − | |||
| − | |||
| − | |||
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 | + | 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!');
}
});