MediaWiki:Common.js
来自Fuckrooms Wiki
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
console.log("Hello World!");
/* CSS模板 */
(function() {
document.querySelectorAll('.import-css').forEach(el => {
const css = el.dataset.content;
const hash = el.dataset.styleSha256;
if (css && hash) {
const calcHash = async (text) =>
Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))))
.map(b => b.toString(16).padStart(2, '0'))
.join('');
calcHash(css).then(actualHash => {
if (actualHash === hash) {
const style = document.createElement('style');
style.textContent = css;
document.head.appendChild(style);
console.log('CSS 应用:', css.substring(0, 20) + '...');
} else {
console.error('哈希不匹配', el);
}
}).catch(e => console.error('哈希错误:', e));
} else {
console.warn('跳过无效元素', el);
}
});
})();