MediaWiki:Common.js:修订间差异

来自Fuckrooms Wiki
已还原芙璃Fully讨论)的编辑至最后由Iopk123451修订的版本
标签回退
页面内容被替换为“console.log("Hello World!");”
标签替换
第1行: 第1行:
(function() {
console.log("Hello World!");
  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 });
    }
});
 
 
/* 参见[[模板:ResourceLoader]]*/
/* 将相关代码用改为DOM加载完成后运行,解决部分情况
模板:ResourceLoader加载不完全的问题 -- 芙兰朵露琪露诺 2021/8/11*/
 
 
function templateResourceLoader() {
$('.resourceLoader').each(function() {
var $x = $(this);
var text = $.trim($x.text());
if (!text) return;
//加载模块
if ($x.data('isModule') == true)
return mw.loader.load(text);
//自动补充MediaWiki命名空间
var ns = text.match('^.*?:');
if (!ns) text = 'MediaWiki:' + text;
//加载CSS样式表
var mime = ($x.data('mime') || "text/javascript").toLowerCase();
if (mime == "text/css") {
if (text.slice(-4).toLowerCase() !== '.css') text = text + '.css';
//if ($x.data('debug') !== true) text = text + '&debug=false';
return mw.loader.load("//wiki.biligame.com/umamusume/index.php?title="+text+"&action=raw&ctype=text/css", "text/css");
}
//加载JS脚本
if (ns && ns[0].toLowerCase() !== 'mediawiki:') {
return console.log('ResourceLoader: 不允许加载MediaWiki以外的js脚本');
}
if (text.slice(-3).toLowerCase() !== '.js') text = text + '.js';
//加载ES6模块
if ($x.data('isModuleEs6') == true)
return loadModuleES6("//wiki.biligame.com/umamusume/index.php?title="+text+"&action=raw&ctype=text/javascript", function() {
console.log("ResourceLoader: 加载ES6模块 => " + text);
});
//加载React模块
if ($x.data('isModuleReact')) {
if ($x.data('isModuleReact')[0]) {
    $.getScript("//wiki.biligame.com/umamusume/index.php?title=MediaWiki:React.development.min.js&action=raw&ctype=text/javascript", function() {
$.getScript("//wiki.biligame.com/umamusume/index.php?title=MediaWiki:React-dom.development.min.js&action=raw&ctype=text/javascript", function() {
console.log("ReactENV => React/ReactDOM Loaded! React is Available For This Page!");
console.log("%c React开发提示 %c 请务必在JS编辑界面右下角使用React同步器同步编译你的JSX代码,否则它将不起任何作用", "color: #fff; padding: 5px 0; background: blue;", "padding: 5px 5px 5px 0; background: #e5e5ff; color:blue");
    $('.resourceLoader').each(function() {
var $xr = $(this);
var textr = $.trim($xr.text());
if (!textr) return;
//自动为React模块补充MediaWiki命名空间与-babel后缀
var nsr = textr.match('^.*?:');
if (!nsr) textr = 'MediaWiki:' + textr.slice(0, -3);
textr += '-babel.js';
if ($xr.data('isModuleReact') && $xr.data('isModuleReact')[1]) {
loadModuleES6("//wiki.biligame.com/umamusume/index.php?title="+textr+"&action=raw&ctype=text/javascript", function() {
console.log("ResourceLoader: 加载React模块 => " + textr);
});
}
});
});
    });
return;
}
}
//加载普通脚本
console.log('ResourceLoader: 加载JS => ' + text);
//if ($x.data('debug') !== true) text = text + '&debug=false';
return mw.loader.load("//wiki.biligame.com/umamusume/index.php?title="+text+"&action=raw&ctype=text/javascript", "text/javascript");
});
}
 
if (document.readyState == 'loading') {
document.addEventListener('DOMContentLoaded', templateResourceLoader);
} else {
templateResourceLoader();
}
 
//加载ES6模块
function loadModuleES6(src, callback) {
var script = document.createElement('script'),
head = document.getElementsByTagName('head')[0];
script.type = 'module';
script.charset = 'UTF-8';
script.src = src;
if (script.addEventListener) {
script.addEventListener('load', function () {
callback();
}, false);
} else if (script.attachEvent) {
script.attachEvent('onreadystatechange', function () {
var target = window.event.srcElement;
if (target.readyState == 'loaded') {
callback();
}
});
}
head.appendChild(script);
}

2025年8月5日 (二) 04:54的版本

console.log("Hello World!");