MediaWiki:Common.js:修订间差异
来自Fuckrooms Wiki
无编辑摘要 |
Iopk123451(留言 | 贡献) 无编辑摘要 |
||
| 第80行: | 第80行: | ||
})(); | })(); | ||
importScript('MediaWiki:Importjs/'+ wgPageName + '.js'); | importScript('MediaWiki:Importjs/'+ wgPageName + '.js'); | ||
/* | |||
* Script Name: Template CSS | |||
* Author: Fandom Backrooms | |||
*/ | |||
(function () { | |||
const eles = document.querySelectorAll('.js-action-play'); | |||
eles.forEach(function (e) { | |||
const targetId = e.getAttribute('data-media-id'); | |||
if (!targetId) { | |||
console.error('No data-media-id present on element', e); | |||
return; | |||
} | |||
const target = document.getElementsByClassName('media-id-' + targetId)[0]; | |||
if (!target) { | |||
console.error('No element found with .media-id-' + targetId, e); | |||
return; | |||
} | |||
e.addEventListener('click', function () { | |||
console.log(target); | |||
if (target.paused || target.ended) { | |||
target.play(); | |||
} else { | |||
target.pause(); | |||
} | |||
}); | |||
}); | |||
})(); | |||
mw.loader.load(["mediawiki.util", "mediawiki.Title"]); | |||
mw.hook("wikipage.content").add(function () { | |||
$("span.import-css").each(function () { | |||
mw.util.addCSS($(this).attr("data-css")); | |||
}); | |||
$(".sitenotice-tab-container").each(function() { | |||
var container = $(this); | |||
function switchTab(offset) { | |||
return function() { | |||
var tabs = container.children(".sitenotice-tab").toArray(); | |||
var no = Number(container.find(".sitenotice-tab-no")[0].innerText) + offset; | |||
var count = tabs.length; | |||
if (no < 1) no = count; | |||
else if (no > count) no = 1; | |||
for (var i = 0; i < count; i++) | |||
tabs[i].style.display = (i + 1 == no ? null : "none"); | |||
container.find(".sitenotice-tab-no")[0].innerText = no; | |||
}; | |||
} | |||
container.find(".sitenotice-tab-arrow.prev").click(switchTab(-1)); | |||
container.find(".sitenotice-tab-arrow.next").click(switchTab(1)); | |||
}); | |||
}); | |||
$.getJSON(mw.util.wikiScript("index"), { | |||
title: "MediaWiki:Custom-import-scripts.json", | |||
action: "raw" | |||
}).done(function (result, status) { | |||
if (status != "success" || typeof (result) != "object") return; | |||
var scripts = result[mw.config.get("wgPageName")]; | |||
if (scripts) { | |||
if (typeof (scripts) == "string") scripts = [scripts]; | |||
importArticles({ type: "script", articles: scripts }); | |||
} | |||
}); | |||
2025年6月2日 (一) 05:09的版本
(function() {
var importCssDivs = document.querySelectorAll('div.import-css');
importCssDivs.forEach(function(div) {
var cssContent = div.textContent || div.innerText;
if (cssContent) {
var styleTag = document.createElement('style');
styleTag.type = 'text/css';
styleTag.appendChild(document.createTextNode(cssContent));
document.head.appendChild(styleTag);
}
});
})();
importScript('MediaWiki:Importjs/'+ wgPageName + '.js');
(function(){
if (!document.getElementById('snow-style')) {
const style = document.createElement('style');
style.id = 'snow-style';
style.textContent = `
@keyframes snowFall {
0% { transform: translateY(-110px) rotate(0deg); }
100% { transform: translateY(calc(100vh + 130px)) rotate(9000deg); }
}
.snowflake {
position: fixed;
top: -130px;
z-index: 9999;
pointer-events: none;
user-select: none;
animation-timing-function: linear;
}
`;
document.head.appendChild(style);
}
function createSnowflake() {
const snowflake = document.createElement('div');
snowflake.className = 'snowflake';
const icons = ['🍀','☘️','🍃','🌿'];
snowflake.innerHTML = icons[Math.floor(Math.random() * 4)];
const size = Math.random() * 16 + 8;
const left = Math.random() * 100;
const duration = Math.random() * 8 + 8;
snowflake.style.cssText = `
font-size: ${size}px;
left: ${left}%;
animation: snowFall ${duration}s linear 1; // 移除delay参数
opacity: ${Math.random() * 0.5 + 0.5};
color: hsl(${Math.random() * 360}, 100%, 90%);
`;
snowflake.addEventListener('animationend', function() {
snowflake.remove();
});
document.body.appendChild(snowflake);
}
let interval = setInterval(createSnowflake, 250);
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
clearInterval(interval);
} else {
interval = setInterval(createSnowflake, 250);
}
});
for (let i = 0; i < 10; i++) {
createSnowflake();
}
})();
importScript('MediaWiki:Importjs/'+ wgPageName + '.js');
/*
* Script Name: Template CSS
* Author: Fandom Backrooms
*/
(function () {
const eles = document.querySelectorAll('.js-action-play');
eles.forEach(function (e) {
const targetId = e.getAttribute('data-media-id');
if (!targetId) {
console.error('No data-media-id present on element', e);
return;
}
const target = document.getElementsByClassName('media-id-' + targetId)[0];
if (!target) {
console.error('No element found with .media-id-' + targetId, e);
return;
}
e.addEventListener('click', function () {
console.log(target);
if (target.paused || target.ended) {
target.play();
} else {
target.pause();
}
});
});
})();
mw.loader.load(["mediawiki.util", "mediawiki.Title"]);
mw.hook("wikipage.content").add(function () {
$("span.import-css").each(function () {
mw.util.addCSS($(this).attr("data-css"));
});
$(".sitenotice-tab-container").each(function() {
var container = $(this);
function switchTab(offset) {
return function() {
var tabs = container.children(".sitenotice-tab").toArray();
var no = Number(container.find(".sitenotice-tab-no")[0].innerText) + offset;
var count = tabs.length;
if (no < 1) no = count;
else if (no > count) no = 1;
for (var i = 0; i < count; i++)
tabs[i].style.display = (i + 1 == no ? null : "none");
container.find(".sitenotice-tab-no")[0].innerText = no;
};
}
container.find(".sitenotice-tab-arrow.prev").click(switchTab(-1));
container.find(".sitenotice-tab-arrow.next").click(switchTab(1));
});
});
$.getJSON(mw.util.wikiScript("index"), {
title: "MediaWiki:Custom-import-scripts.json",
action: "raw"
}).done(function (result, status) {
if (status != "success" || typeof (result) != "object") return;
var scripts = result[mw.config.get("wgPageName")];
if (scripts) {
if (typeof (scripts) == "string") scripts = [scripts];
importArticles({ type: "script", articles: scripts });
}
});