MediaWiki:Common.js:修订间差异
来自Fuckrooms Wiki
Defaultuser6(留言 | 贡献) (暂时)禁用影响性能的飘落对象,优化后重新加回 |
Defaultuser6(留言 | 贡献) 添加替代性CSS加载 |
||
| 第1行: | 第1行: | ||
(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 { | } else { | ||
console.error('哈希不匹配', el); | |||
} | } | ||
}); | }).catch(e => console.error('哈希错误:', e)); | ||
} else { | |||
console.warn('跳过无效元素', el); | |||
} | |||
}); | |||
})(); | |||
importScript('MediaWiki:Importjs/'+ wgPageName + '.js'); | importScript('MediaWiki:Importjs/'+ wgPageName + '.js'); | ||
2025年4月25日 (五) 12:14的版本
(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);
}
});
})();
importScript('MediaWiki:Importjs/'+ wgPageName + '.js');