MediaWiki:Common.js

MediaWiki界面页面

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */

// Baidu Analytics - 百度统计
mw.loader.getScript('https://hm.baidu.com/hm.js?c21e068c67c3cc2811344dc36f841afd');
// Microsoft Clarity
(function(c,l,a,r,i,t,y){
        c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
        t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
        y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "gr962b4lwq");

// 仅修改首頁
if (mw.config.get('wgIsMainPage') === true) {
	// 根據darkmode加上styles
	var setHomeStyles = function() {
		// 判断darkmode
		if (document.documentElement.classList.contains('skin-citizen-dark')) {
			// 是dark,用这个
			document.querySelector('#home-card-kook').style.backgroundColor= '#497A20';
			document.querySelector('#home-card-QQ').style.backgroundColor= '#1883A6';
			document.documentElement.style.setProperty('--hero-image', 'url(https://citizenwiki.cn/images/c/cb/Spirit_E1_flying_fast_over_Orison.webp)');
		} else {
			// 不是dark,用这个
			document.querySelector('#home-card-kook').style.backgroundColor= '#7acc35';
			document.querySelector('#home-card-QQ').style.backgroundColor= '#24c8fd';
			document.documentElement.style.setProperty('--hero-image', 'url(https://citizenwiki.cn/images/f/f2/890Jump_beach.jpg.webp)');
		}
	};

	// 找到我们要插入新div之后的element
	var mwBody = document.getElementById('content');
	// 新建一个div
	var newDiv = document.createElement('div');
	// 给新插入的element设个class名
	newDiv.setAttribute('class', 'header-hero');
	// 加上html内容
	newDiv.innerHTML = '<div class="header-hero-image" style="background-image: linear-gradient(to top, var(--color-surface-0), transparent 150%), var(--hero-image);background-size: cover;background-position: center center;height: 36vh;position: absolute;inset: 0;"></div>';

	// 将新 div 插入 content 之前
	mwBody.parentNode.insertBefore(newDiv, mwBody);

	setHomeStyles();

	// 檢查class是否有變化
	var handleClassChange = function(mutations) {
		// Loop through the mutations array
		for (var i = 0; i < mutations.length; i++) {
				var mutation = mutations[i];
				// Check if the mutation is an attribute change and the attribute is class
				if (mutation.type === "attributes" && mutation.attributeName === "class") {
					setHomeStyles();
				}
			}
	};
	var observer = new MutationObserver(handleClassChange);
	// 觀察<html>
	observer.observe(document.documentElement, { attributes: true });
}
我们提供服务需要使用Cookie。您使用我们的服务,即表示您同意我们使用Cookie。