MediaWiki:Common.js: Difference between revisions
From VRChat Wiki
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
(()=>{var | (() => { | ||
var __defProp = Object.defineProperty; | |||
var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res); | |||
var __export = (all, symbols) => { | |||
let target = {}; | |||
for (var name in all) __defProp(target, name, { | |||
get: all[name], | |||
enumerable: true | |||
}); | |||
if (symbols) __defProp(target, Symbol.toStringTag, { value: "Module" }); | |||
return target; | |||
}; | |||
function isPage(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; | |||
} | |||
[...document.querySelectorAll(".spoiler")].map((container) => { | |||
const overlay = container.querySelector(".spoiler-overlay"); | |||
overlay === null || overlay === void 0 || overlay.addEventListener("click", () => { | |||
container.dataset.open = ""; | |||
}); | |||
}); | |||
function _objectWithoutPropertiesLoose(r, e) { | |||
if (null == r) return {}; | |||
var t = {}; | |||
for (var n in r) if ({}.hasOwnProperty.call(r, n)) { | |||
if (e.includes(n)) continue; | |||
t[n] = r[n]; | |||
} | |||
return t; | |||
} | |||
function _objectWithoutProperties(e, t) { | |||
if (null == e) return {}; | |||
var o, r, i = _objectWithoutPropertiesLoose(e, t); | |||
if (Object.getOwnPropertySymbols) { | |||
var s = Object.getOwnPropertySymbols(e); | |||
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); | |||
} | |||
return i; | |||
} | |||
var _excluded = ["videoId"]; | |||
[...document.querySelectorAll(".youtube")].map((element) => { | |||
const _element$dataset = element.dataset, { videoId } = _element$dataset, attributes = _objectWithoutProperties(_element$dataset, _excluded); | |||
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); | |||
}); | |||
const __vitePreload = function preload(baseModule, deps, importerUrl) { | |||
let promise = Promise.resolve(); | |||
function handlePreloadError(err$2) { | |||
const e$1 = new Event("vite:preloadError", { cancelable: true }); | |||
e$1.payload = err$2; | |||
window.dispatchEvent(e$1); | |||
if (!e$1.defaultPrevented) throw err$2; | |||
} | |||
return promise.then((res) => { | |||
for (const item of res || []) { | |||
if (item.status !== "rejected") continue; | |||
handlePreloadError(item.reason); | |||
} | |||
return baseModule().catch(handlePreloadError); | |||
}); | |||
}; | |||
function getArticleFromElement(element) { | |||
const { articleId, articleTitle, articleContent } = element.dataset; | |||
if (!articleId || !articleTitle || !articleContent) return null; | |||
return { | |||
id: articleId, | |||
title: articleTitle, | |||
content: atob(articleContent) | |||
}; | |||
} | |||
var ArticleDialog; | |||
var init_article = __esmMin((() => { | |||
ArticleDialog = class extends OO.ui.ProcessDialog { | |||
constructor(article) { | |||
super({ size: "large" }); | |||
this.article = article; | |||
} | |||
initialize() { | |||
super.initialize(); | |||
const content = new OO.ui.PanelLayout({ | |||
expanded: false, | |||
padded: true, | |||
scrollable: true | |||
}); | |||
content.$element.append(this.article.htmlContent); | |||
this.$content.append(content.$element); | |||
return this; | |||
} | |||
getActionProcess(action) { | |||
switch (action) { | |||
case "close": return new OO.ui.Process(() => { | |||
this.close({ action: "close" }); | |||
}); | |||
} | |||
return super.getActionProcess(action); | |||
} | |||
}; | |||
ArticleDialog.static.name = ArticleDialog.name; | |||
ArticleDialog.static.title = "Article Aaa"; | |||
ArticleDialog.static.actions = [{ | |||
action: "close", | |||
flags: "safe", | |||
icon: "close", | |||
label: "Close" | |||
}]; | |||
})); | |||
var init_infopush$1 = __esmMin((() => {})); | |||
function asyncGeneratorStep(n, t, e, r, o, a, c) { | |||
try { | |||
var i = n[a](c), u = i.value; | |||
} catch (n$1) { | |||
e(n$1); | |||
return; | |||
} | |||
i.done ? t(u) : Promise.resolve(u).then(r, o); | |||
} | |||
function _asyncToGenerator(n) { | |||
return function() { | |||
var t = this, e = arguments; | |||
return new Promise(function(r, o) { | |||
var a = n.apply(t, e); | |||
function _next(n$1) { | |||
asyncGeneratorStep(a, r, o, _next, _throw, "next", n$1); | |||
} | |||
function _throw(n$1) { | |||
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n$1); | |||
} | |||
_next(void 0); | |||
}); | |||
}; | |||
} | |||
var init_asyncToGenerator = __esmMin((() => {})); | |||
var infopush_exports = /* @__PURE__ */ __export({}, 1); | |||
var infopushes, windowManager; | |||
var init_infopush = __esmMin((() => { | |||
init_article(); | |||
init_infopush$1(); | |||
init_asyncToGenerator(); | |||
infopushes = document.querySelectorAll(".tpl-infopush"); | |||
console.log({ infopushes }); | |||
windowManager = new OO.ui.WindowManager(); | |||
$(document.body).append(windowManager.$element); | |||
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) { | |||
if (!!item.querySelector("a")) continue; | |||
const article = getArticleFromElement(item); | |||
if (!article) continue; | |||
item.style.cursor = "pointer"; | |||
item.addEventListener("click", _asyncToGenerator(function* () { | |||
if (!windowManager.getWindow(article.id)) { | |||
const articleDialog = new ArticleDialog(article); | |||
windowManager.addWindows({ [article.id]: articleDialog }); | |||
} | |||
yield windowManager.openWindow(article.id); | |||
})); | |||
} | |||
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); | |||
} | |||
})); | |||
if (isPage(["Template:MainPageInfopush", "Main_Page"])) mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).then(() => __vitePreload(() => Promise.resolve().then(() => (init_infopush(), infopush_exports)), void 0, {}.url)); | |||
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")); | |||
var 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)); | |||
var wgUserGroups = mw.config.get("wgUserGroups"); | |||
var 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); | |||
})(); | |||
Revision as of 13:34, 13 December 2025
(() => {
var __defProp = Object.defineProperty;
var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
var __export = (all, symbols) => {
let target = {};
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
if (symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
return target;
};
function isPage(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;
}
[...document.querySelectorAll(".spoiler")].map((container) => {
const overlay = container.querySelector(".spoiler-overlay");
overlay === null || overlay === void 0 || overlay.addEventListener("click", () => {
container.dataset.open = "";
});
});
function _objectWithoutPropertiesLoose(r, e) {
if (null == r) return {};
var t = {};
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
if (e.includes(n)) continue;
t[n] = r[n];
}
return t;
}
function _objectWithoutProperties(e, t) {
if (null == e) return {};
var o, r, i = _objectWithoutPropertiesLoose(e, t);
if (Object.getOwnPropertySymbols) {
var s = Object.getOwnPropertySymbols(e);
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
}
return i;
}
var _excluded = ["videoId"];
[...document.querySelectorAll(".youtube")].map((element) => {
const _element$dataset = element.dataset, { videoId } = _element$dataset, attributes = _objectWithoutProperties(_element$dataset, _excluded);
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);
});
const __vitePreload = function preload(baseModule, deps, importerUrl) {
let promise = Promise.resolve();
function handlePreloadError(err$2) {
const e$1 = new Event("vite:preloadError", { cancelable: true });
e$1.payload = err$2;
window.dispatchEvent(e$1);
if (!e$1.defaultPrevented) throw err$2;
}
return promise.then((res) => {
for (const item of res || []) {
if (item.status !== "rejected") continue;
handlePreloadError(item.reason);
}
return baseModule().catch(handlePreloadError);
});
};
function getArticleFromElement(element) {
const { articleId, articleTitle, articleContent } = element.dataset;
if (!articleId || !articleTitle || !articleContent) return null;
return {
id: articleId,
title: articleTitle,
content: atob(articleContent)
};
}
var ArticleDialog;
var init_article = __esmMin((() => {
ArticleDialog = class extends OO.ui.ProcessDialog {
constructor(article) {
super({ size: "large" });
this.article = article;
}
initialize() {
super.initialize();
const content = new OO.ui.PanelLayout({
expanded: false,
padded: true,
scrollable: true
});
content.$element.append(this.article.htmlContent);
this.$content.append(content.$element);
return this;
}
getActionProcess(action) {
switch (action) {
case "close": return new OO.ui.Process(() => {
this.close({ action: "close" });
});
}
return super.getActionProcess(action);
}
};
ArticleDialog.static.name = ArticleDialog.name;
ArticleDialog.static.title = "Article Aaa";
ArticleDialog.static.actions = [{
action: "close",
flags: "safe",
icon: "close",
label: "Close"
}];
}));
var init_infopush$1 = __esmMin((() => {}));
function asyncGeneratorStep(n, t, e, r, o, a, c) {
try {
var i = n[a](c), u = i.value;
} catch (n$1) {
e(n$1);
return;
}
i.done ? t(u) : Promise.resolve(u).then(r, o);
}
function _asyncToGenerator(n) {
return function() {
var t = this, e = arguments;
return new Promise(function(r, o) {
var a = n.apply(t, e);
function _next(n$1) {
asyncGeneratorStep(a, r, o, _next, _throw, "next", n$1);
}
function _throw(n$1) {
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n$1);
}
_next(void 0);
});
};
}
var init_asyncToGenerator = __esmMin((() => {}));
var infopush_exports = /* @__PURE__ */ __export({}, 1);
var infopushes, windowManager;
var init_infopush = __esmMin((() => {
init_article();
init_infopush$1();
init_asyncToGenerator();
infopushes = document.querySelectorAll(".tpl-infopush");
console.log({ infopushes });
windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
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) {
if (!!item.querySelector("a")) continue;
const article = getArticleFromElement(item);
if (!article) continue;
item.style.cursor = "pointer";
item.addEventListener("click", _asyncToGenerator(function* () {
if (!windowManager.getWindow(article.id)) {
const articleDialog = new ArticleDialog(article);
windowManager.addWindows({ [article.id]: articleDialog });
}
yield windowManager.openWindow(article.id);
}));
}
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);
}
}));
if (isPage(["Template:MainPageInfopush", "Main_Page"])) mw.loader.using(["oojs-ui-core", "oojs-ui-windows"]).then(() => __vitePreload(() => Promise.resolve().then(() => (init_infopush(), infopush_exports)), void 0, {}.url));
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"));
var 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));
var wgUserGroups = mw.config.get("wgUserGroups");
var 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);
})();