MediaWiki:Common.js:修订间差异
来自Fuckrooms Wiki
页面内容被替换为“console.log("Hello World!");” 标签:替换 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | |||
console.log("Hello World!"); | 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); | |||
} | |||
}); | |||
})(); | |||
2025年8月5日 (二) 05:10的版本
/* 这里的任何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);
}
});
})();