MediaWiki:Common.js: Difference between revisions

From VRChat Wiki
m fix?: does not support optional accessors?
Tag: Reverted
m fix?: don't minify
Tag: Reverted
Line 1: Line 1:
(function () {
(function() {
function e(e) {
 
let [t, n] = mw.config.get("wgPageName").split("/");
 
return !(!t || !e.includes(t) || !n || mw.config.get("wgPageContentLanguage") != n);
//#region src/whitelist.ts
function isWhitelistedPage(pages) {
const [pageName, pageLanguage] = mw.config.get("wgPageName").split("/");
if (!pageName || !pages.includes(pageName)) return false;
if (!pageLanguage || mw.config.get("wgPageContentLanguage") != pageLanguage) return false;
return true;
}
}
e(["Template:MainPageInfopush", "Main_Page"]) && mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).done(() => {
 
var e = new OO.ui.WindowManager();
//#endregion
$(document.body).append(e.$element);
//#region src/templates/infopush.ts
function t(t) {
(() => {
var { articleTitle: n, articleContent: r } = t.dataset;
if (!isWhitelistedPage(["Template:MainPageInfopush", "Main_Page"])) return;
function i(e) {
mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).done(() => {
i.super.call(this, e), this.config = e || {};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
function showArticle(element) {
var { articleTitle, articleContent } = element.dataset;
function ArticleDialog(config) {
ArticleDialog.super.call(this, config);
this.config = config || {};
}
OO.inheritClass(ArticleDialog, OO.ui.ProcessDialog);
ArticleDialog.static.name = "ArticleDialog";
ArticleDialog.static.title = articleTitle;
ArticleDialog.static.size = "large";
ArticleDialog.static.actions = [{
action: "close",
flags: "safe",
icon: "close",
label: "Close"
}];
ArticleDialog.prototype.initialize = function() {
ArticleDialog.super.prototype.initialize.apply(this, arguments);
this.content = new OO.ui.PanelLayout({
$content: atob(articleContent),
expanded: false,
padded: true,
scrollable: true
});
this.$body.append(this.content.$element);
};
ArticleDialog.prototype.getActionProcess = function(action) {
if (action === "close") return new OO.ui.Process(function() {
this.close({ action: "close" });
}, this);
return ArticleDialog.super.prototype.getActionProcess.call(this, action);
};
var dialog = new ArticleDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
}
}
OO.inheritClass(i, OO.ui.ProcessDialog), i.static.name = "ArticleDialog", i.static.title = n, i.static.size = "large", i.static.actions = [{
const infopushes = document.querySelectorAll(".tpl-infopush");
action: "close",
for (const infopush of infopushes) {
flags: "safe",
const content = infopush.querySelector(".tpl-infopush-content");
icon: "close",
const items = content.querySelectorAll(".tpl-infopush-item");
label: "Close"
const total = items.length;
}], i.prototype.initialize = function () {
for (const item of items) {
i.super.prototype.initialize.apply(this, arguments), this.content = new OO.ui.PanelLayout({
const { articleId } = item.dataset;
$content: atob(r),
if (!articleId || !!item.querySelector("a")) continue;
expanded: !1,
item.style.cursor = "pointer";
padded: !0,
item.addEventListener("click", () => showArticle(item));
scrollable: !0
}
}), this.$body.append(this.content.$element);
const navigation = infopush.querySelector(".tpl-infopush-navigation");
}, i.prototype.getActionProcess = function (e) {
let currentOffset = 0;
return e === "close" ? new OO.ui.Process(function () {
function showSlide(index) {
this.close({ action: "close" });
currentOffset = (index + total) % total;
}, this) : i.super.prototype.getActionProcess.call(this, e);
content.style.transform = `translateX(-${currentOffset * 100}%)`;
};
}
var a = new i();
const autoAdvanceEvery = 5e3;
e.addWindows([a]), e.openWindow(a);
let autoAdvanceInterval;
}
function resetAutoAdvance() {
let n = document.querySelectorAll(".tpl-infopush");
if (autoAdvanceInterval) clearInterval(autoAdvanceInterval);
for (let e of n) {
autoAdvanceInterval = setInterval(function() {
let n = e.querySelector(".tpl-infopush-content"), r = n.querySelectorAll(".tpl-infopush-item"), i = r.length;
showSlide(currentOffset + 1);
for (let e of r) {
}, autoAdvanceEvery);
let { articleId: n } = e.dataset;
}
!n || e.querySelector("a") || (e.style.cursor = "pointer", e.addEventListener("click", () => t(e)));
navigation.querySelector(".tpl-infopush-navigation-previous").addEventListener("click", () => {
showSlide(currentOffset - 1);
resetAutoAdvance();
});
navigation.querySelector(".tpl-infopush-navigation-next").addEventListener("click", () => {
showSlide(currentOffset + 1);
resetAutoAdvance();
});
resetAutoAdvance();
showSlide(0);
}
}
let a = e.querySelector(".tpl-infopush-navigation"), o = 0;
function s(e) {
o = (e + i) % i, n.style.transform = `translateX(-${o * 100}%)`;
}
let c;
function l() {
c && clearInterval(c), c = setInterval(function () {
s(o + 1);
}, 5e3);
}
a.querySelector(".tpl-infopush-navigation-previous").addEventListener("click", () => {
s(o - 1), l();
}), a.querySelector(".tpl-infopush-navigation-next").addEventListener("click", () => {
s(o + 1), l();
}), l(), s(0);
}
}), [...document.querySelectorAll(".spoiler")].map((e) => {
e.querySelector(".spoiler-overlay").addEventListener("click", () => {
e.dataset.open = "";
});
});
}), [...document.querySelectorAll(".youtube")].map((e) => {
})();
let { videoId: t, ...n } = e.dataset, r = document.createElement("iframe");
 
r.setAttribute("width", "560"), r.setAttribute("height", "315"), r.setAttribute("frameborder", "0"), r.setAttribute("allow", [
//#endregion
//#region src/templates/spoiler.ts
[...document.querySelectorAll(".spoiler")].map((container) => {
container.querySelector(".spoiler-overlay")?.addEventListener("click", () => {
container.dataset.open = "";
});
});
 
//#endregion
//#region src/templates/youtube.ts
[...document.querySelectorAll(".youtube")].map((element) => {
const { videoId, ...attributes } = element.dataset;
const iframe = document.createElement("iframe");
iframe.setAttribute("width", String(560));
iframe.setAttribute("height", String(315));
iframe.setAttribute("frameborder", String(0));
iframe.setAttribute("allow", [
"accelerometer",
"accelerometer",
"autoplay",
"autoplay",
Line 69: Line 116:
"picture-in-picture",
"picture-in-picture",
"web-share"
"web-share"
].join("; ")), r.setAttribute("referrerpolicy", "strict-origin-when-cross-origin"), r.setAttribute("allowfullscreen", "true"), Object.entries(n).map(([e, t]) => t && r.setAttribute(e, t)), r.setAttribute("style", e.getAttribute("style") || ""), r.src = `https://www.youtube-nocookie.com/embed/${t}?rel=0`, e.replaceWith(r);
].join("; "));
iframe.setAttribute("referrerpolicy", "strict-origin-when-cross-origin");
iframe.setAttribute("allowfullscreen", String(true));
Object.entries(attributes).map(([key, value]) => value && iframe.setAttribute(key, value));
iframe.setAttribute("style", element.getAttribute("style") || "");
iframe.src = `https://www.youtube-nocookie.com/embed/${videoId}?rel=0`;
element.replaceWith(iframe);
});
});
var t = document.createElement("script");
 
t.setAttribute("defer", "defer"), t.setAttribute("data-domain", "wiki.vrchat.com"), t.setAttribute("event-page-name", mw.config.get("wgTitle")), t.setAttribute("event-page-language", mw.config.get("wgPageContentLanguage"));
//#endregion
let n = mw.config.get("wgFormattedNamespaces");
//#region src/plausible.ts
t.setAttribute("event-page-namespace", n[mw.config.get("wgNamespaceNumber")]), t.setAttribute("event-theme", mw.config.get("skin")), t.setAttribute("event-action", mw.config.get("wgAction")), t.setAttribute("event-is-logged-in", String(mw.config.get("wgUserName") !== null));
var script = document.createElement("script");
let r = mw.config.get("wgUserGroups"), i = r.includes("community-mod") || r.includes("moderator") || r.includes("sysop");
script.setAttribute("defer", "defer");
t.setAttribute("event-is-maintainer", String(i)), t.src = "https://plausible.io/js/script.pageview-props.outbound-links.js", document.head.appendChild(t);
script.setAttribute("data-domain", "wiki.vrchat.com");
script.setAttribute("event-page-name", mw.config.get("wgTitle"));
script.setAttribute("event-page-language", mw.config.get("wgPageContentLanguage"));
const namespaces = mw.config.get("wgFormattedNamespaces");
script.setAttribute("event-page-namespace", namespaces[mw.config.get("wgNamespaceNumber")]);
script.setAttribute("event-theme", mw.config.get("skin"));
script.setAttribute("event-action", mw.config.get("wgAction"));
script.setAttribute("event-is-logged-in", String(mw.config.get("wgUserName") !== null));
const wgUserGroups = mw.config.get("wgUserGroups");
const maintainer = wgUserGroups.includes("community-mod") || wgUserGroups.includes("moderator") || wgUserGroups.includes("sysop");
script.setAttribute("event-is-maintainer", String(maintainer));
script.src = "https://plausible.io/js/script.pageview-props.outbound-links.js";
document.head.appendChild(script);
 
//#endregion
})();
})();

Revision as of 04:27, 12 December 2025

(function() {


//#region src/whitelist.ts
	function isWhitelistedPage(pages) {
		const [pageName, pageLanguage] = mw.config.get("wgPageName").split("/");
		if (!pageName || !pages.includes(pageName)) return false;
		if (!pageLanguage || mw.config.get("wgPageContentLanguage") != pageLanguage) return false;
		return true;
	}

//#endregion
//#region src/templates/infopush.ts
	(() => {
		if (!isWhitelistedPage(["Template:MainPageInfopush", "Main_Page"])) return;
		mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).done(() => {
			var windowManager = new OO.ui.WindowManager();
			$(document.body).append(windowManager.$element);
			function showArticle(element) {
				var { articleTitle, articleContent } = element.dataset;
				function ArticleDialog(config) {
					ArticleDialog.super.call(this, config);
					this.config = config || {};
				}
				OO.inheritClass(ArticleDialog, OO.ui.ProcessDialog);
				ArticleDialog.static.name = "ArticleDialog";
				ArticleDialog.static.title = articleTitle;
				ArticleDialog.static.size = "large";
				ArticleDialog.static.actions = [{
					action: "close",
					flags: "safe",
					icon: "close",
					label: "Close"
				}];
				ArticleDialog.prototype.initialize = function() {
					ArticleDialog.super.prototype.initialize.apply(this, arguments);
					this.content = new OO.ui.PanelLayout({
						$content: atob(articleContent),
						expanded: false,
						padded: true,
						scrollable: true
					});
					this.$body.append(this.content.$element);
				};
				ArticleDialog.prototype.getActionProcess = function(action) {
					if (action === "close") return new OO.ui.Process(function() {
						this.close({ action: "close" });
					}, this);
					return ArticleDialog.super.prototype.getActionProcess.call(this, action);
				};
				var dialog = new ArticleDialog();
				windowManager.addWindows([dialog]);
				windowManager.openWindow(dialog);
			}
			const infopushes = document.querySelectorAll(".tpl-infopush");
			for (const infopush of infopushes) {
				const content = infopush.querySelector(".tpl-infopush-content");
				const items = content.querySelectorAll(".tpl-infopush-item");
				const total = items.length;
				for (const item of items) {
					const { articleId } = item.dataset;
					if (!articleId || !!item.querySelector("a")) continue;
					item.style.cursor = "pointer";
					item.addEventListener("click", () => showArticle(item));
				}
				const navigation = infopush.querySelector(".tpl-infopush-navigation");
				let currentOffset = 0;
				function showSlide(index) {
					currentOffset = (index + total) % total;
					content.style.transform = `translateX(-${currentOffset * 100}%)`;
				}
				const autoAdvanceEvery = 5e3;
				let autoAdvanceInterval;
				function resetAutoAdvance() {
					if (autoAdvanceInterval) clearInterval(autoAdvanceInterval);
					autoAdvanceInterval = setInterval(function() {
						showSlide(currentOffset + 1);
					}, autoAdvanceEvery);
				}
				navigation.querySelector(".tpl-infopush-navigation-previous").addEventListener("click", () => {
					showSlide(currentOffset - 1);
					resetAutoAdvance();
				});
				navigation.querySelector(".tpl-infopush-navigation-next").addEventListener("click", () => {
					showSlide(currentOffset + 1);
					resetAutoAdvance();
				});
				resetAutoAdvance();
				showSlide(0);
			}
		});
	})();

//#endregion
//#region src/templates/spoiler.ts
	[...document.querySelectorAll(".spoiler")].map((container) => {
		container.querySelector(".spoiler-overlay")?.addEventListener("click", () => {
			container.dataset.open = "";
		});
	});

//#endregion
//#region src/templates/youtube.ts
	[...document.querySelectorAll(".youtube")].map((element) => {
		const { videoId, ...attributes } = element.dataset;
		const iframe = document.createElement("iframe");
		iframe.setAttribute("width", String(560));
		iframe.setAttribute("height", String(315));
		iframe.setAttribute("frameborder", String(0));
		iframe.setAttribute("allow", [
			"accelerometer",
			"autoplay",
			"clipboard-write",
			"encrypted-media",
			"gyroscope",
			"picture-in-picture",
			"web-share"
		].join("; "));
		iframe.setAttribute("referrerpolicy", "strict-origin-when-cross-origin");
		iframe.setAttribute("allowfullscreen", String(true));
		Object.entries(attributes).map(([key, value]) => value && iframe.setAttribute(key, value));
		iframe.setAttribute("style", element.getAttribute("style") || "");
		iframe.src = `https://www.youtube-nocookie.com/embed/${videoId}?rel=0`;
		element.replaceWith(iframe);
	});

//#endregion
//#region src/plausible.ts
	var script = document.createElement("script");
	script.setAttribute("defer", "defer");
	script.setAttribute("data-domain", "wiki.vrchat.com");
	script.setAttribute("event-page-name", mw.config.get("wgTitle"));
	script.setAttribute("event-page-language", mw.config.get("wgPageContentLanguage"));
	const namespaces = mw.config.get("wgFormattedNamespaces");
	script.setAttribute("event-page-namespace", namespaces[mw.config.get("wgNamespaceNumber")]);
	script.setAttribute("event-theme", mw.config.get("skin"));
	script.setAttribute("event-action", mw.config.get("wgAction"));
	script.setAttribute("event-is-logged-in", String(mw.config.get("wgUserName") !== null));
	const wgUserGroups = mw.config.get("wgUserGroups");
	const maintainer = wgUserGroups.includes("community-mod") || wgUserGroups.includes("moderator") || wgUserGroups.includes("sysop");
	script.setAttribute("event-is-maintainer", String(maintainer));
	script.src = "https://plausible.io/js/script.pageview-props.outbound-links.js";
	document.head.appendChild(script);

//#endregion
})();