MediaWiki:Common.js:修订间差异
外观
无编辑摘要 |
无编辑摘要 |
||
| 第3行: | 第3行: | ||
if(!window.SLOADED){ | if(!window.SLOADED){ | ||
window.SLOADED = {} | window.SLOADED = {} | ||
window.RELOAD = true; | |||
}else{ | |||
window.RELOAD = false; | |||
} | } | ||
function hook(document){ | |||
const scripts = document.querySelectorAll('script[src*="load.php"][src*="modules=startup"]'); | |||
scripts.forEach(script => script.remove()); | scripts.forEach(script => script.remove()); | ||
} | var scene = document.createElement("div"); | ||
document.body.appendChild(scene); | |||
scene.id = "scene"; | |||
scene.dataset.turboPermanent="true"; | |||
scene.style.zIndex = -100; | |||
scene.style.position = "fixed"; | |||
scene.id = "parallax-bg"; | |||
scene.style.inset = "-300px"; | |||
var img = document.createElement("img"); | |||
scene.appendChild(img); | |||
img.src = "/_nuxt/bg-1.DbZGBWF5.jpg"; | |||
img.dataset.depth = 0.5; | |||
} | |||
hook(document); | |||
// ========== 2. 在 Turbo 渲染新页面之前,删除新页面中的 startup 脚本 ========== | // ========== 2. 在 Turbo 渲染新页面之前,删除新页面中的 startup 脚本 ========== | ||
document.addEventListener('turbo:before-render', (event) => { | document.addEventListener('turbo:before-render', (event) => { | ||
hook(event.detail.newBody.ownerDocument) | |||
}); | }); | ||
| 第34行: | 第49行: | ||
loadScript("https://cdnjs.cloudflare.com/ajax/libs/parallax/3.1.0/parallax.min.js").then(function(){ | loadScript("https://cdnjs.cloudflare.com/ajax/libs/parallax/3.1.0/parallax.min.js").then(function(){ | ||
if(window.RELOAD) | |||
new Parallax(scene); | |||
}); | }); | ||
2026年8月20日 (四) 06:53的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
(function(){
if(!window.SLOADED){
window.SLOADED = {}
window.RELOAD = true;
}else{
window.RELOAD = false;
}
function hook(document){
const scripts = document.querySelectorAll('script[src*="load.php"][src*="modules=startup"]');
scripts.forEach(script => script.remove());
var scene = document.createElement("div");
document.body.appendChild(scene);
scene.id = "scene";
scene.dataset.turboPermanent="true";
scene.style.zIndex = -100;
scene.style.position = "fixed";
scene.id = "parallax-bg";
scene.style.inset = "-300px";
var img = document.createElement("img");
scene.appendChild(img);
img.src = "/_nuxt/bg-1.DbZGBWF5.jpg";
img.dataset.depth = 0.5;
}
hook(document);
// ========== 2. 在 Turbo 渲染新页面之前,删除新页面中的 startup 脚本 ==========
document.addEventListener('turbo:before-render', (event) => {
hook(event.detail.newBody.ownerDocument)
});
function loadScript(url, options={}, dataset={}) {
return new Promise((resolve, reject) => {
if(window.SLOADED[url]) resolve()
const script = document.createElement('script');
script.src = url;
script.async = "async";
Object.assign(script, options);
Object.assign(script.dataset, dataset);
script.onload = () => {window.SLOADED[url] = true ;resolve()};
script.onerror = (e) => reject(e)
document.head.appendChild(script);
});
}
loadScript("https://cdnjs.cloudflare.com/ajax/libs/parallax/3.1.0/parallax.min.js").then(function(){
if(window.RELOAD)
new Parallax(scene);
});
loadScript("https://cdn.jsdelivr.net/npm/@hotwired/turbo@latest/dist/turbo.es2017-esm.min.js",
{
type: "module"
}
);
})()