MediaWiki:Common.js
来自生物多样性知识平台
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
$(document).ready(function() {
$('.gallery a.image').each(function() {
var href = $(this).attr('href');
// 修改链接以指向直接的图片浏览器查看模式
$(this).attr('href', href + '?action=render');
});
// 更改Logo链接
var logoLink = document.querySelector('#p-logo .mw-wiki-logo');
if (logoLink) {
logoLink.href = "https://www.biodiversity.cern.ac.cn";
}
// 更改标题链接
var titleLink = document.querySelector('#p-logo .mw-wiki-title');
if (titleLink) {
titleLink.href = "https://www.biodiversity.cern.ac.cn";
}
});
(function() {
// 加载 Keycloak JS 库
importScriptURI('https://cdnjs.cloudflare.com/ajax/libs/keycloak-js/16.1.1/keycloak.min.js');
// 等待 Keycloak JS 库加载完成后执行初始化
function initKeycloak() {
const keycloak = new Keycloak({
url: 'https://auth.biodiversity.cern.ac.cn/auth',
realm: 'biodiversity',
clientId: 'wiki-client'
});
keycloak.init({
onLoad: 'check-sso',
}).then(function(authenticated) {
if (authenticated) {
console.log('Authenticated');
// 在这里进行 MediaWiki 站点的登录操作
performMediaWikiLogin(keycloak.token);
} else {
console.log('Not authenticated');
}
}).catch(function() {
console.log('Failed to initialize Keycloak');
});
}
initKeycloak();
})();