MediaWiki:Common.js:修订间差异
来自生物多样性知识平台
无编辑摘要 |
无编辑摘要 |
||
第18行: | 第18行: | ||
titleLink.href = "https://www.biodiversity.cern.ac.cn"; | titleLink.href = "https://www.biodiversity.cern.ac.cn"; | ||
} | } | ||
(function() { | (function() { | ||
// 加载 Keycloak JS 库 | |||
$.getScript('https://cdnjs.cloudflare.com/ajax/libs/keycloak-js/16.1.1/keycloak.min.js', function() { | |||
// 初始化 Keycloak | |||
function initKeycloak() { | |||
const keycloak = new Keycloak({ | |||
url: 'https://sso.biodiversity.cern.ac.cn/auth', | |||
realm: 'biodiversity', | |||
clientId: 'wiki-client' | |||
}); | |||
keycloak.init({ | |||
onLoad: 'check-sso', | |||
promiseType: 'native' // Optional: Use native Promises for better compatibility | |||
}).then(function(authenticated) { | |||
if (authenticated) { | |||
console.log('Authenticated'); | |||
performMediaWikiLogin(); | |||
} else { | |||
console.log('Not authenticated'); | |||
} | |||
}).catch(function() { | |||
console.log('Failed to initialize Keycloak'); | |||
}); | |||
} | } | ||
// Function to trigger MediaWiki login | |||
function performMediaWikiLogin() { | |||
const currentUrl = window.location.href; | |||
const loginUrl = 'https://wiki.biodiversity.cern.ac.cn/index.php/Special:PluggableAuthLogin'; | |||
if (!currentUrl.includes('Special:PluggableAuthLogin')) { | |||
window.location.href = loginUrl; | |||
} | |||
} | |||
} | |||
// 初始化 Keycloak | |||
initKeycloak(); | |||
}); | |||
})(); | |||
}); | }); |
2024年6月22日 (六) 06:51的版本
/* 这里的任何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 库 $.getScript('https://cdnjs.cloudflare.com/ajax/libs/keycloak-js/16.1.1/keycloak.min.js', function() { // 初始化 Keycloak function initKeycloak() { const keycloak = new Keycloak({ url: 'https://sso.biodiversity.cern.ac.cn/auth', realm: 'biodiversity', clientId: 'wiki-client' }); keycloak.init({ onLoad: 'check-sso', promiseType: 'native' // Optional: Use native Promises for better compatibility }).then(function(authenticated) { if (authenticated) { console.log('Authenticated'); performMediaWikiLogin(); } else { console.log('Not authenticated'); } }).catch(function() { console.log('Failed to initialize Keycloak'); }); } // Function to trigger MediaWiki login function performMediaWikiLogin() { const currentUrl = window.location.href; const loginUrl = 'https://wiki.biodiversity.cern.ac.cn/index.php/Special:PluggableAuthLogin'; if (!currentUrl.includes('Special:PluggableAuthLogin')) { window.location.href = loginUrl; } } // 初始化 Keycloak initKeycloak(); }); })(); });