MediaWiki:Common.js
From UKTAPS.CO.UK Wiki
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* 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!');
}
});