本网站正在建设中(~ ̄▽ ̄)~

  • 你好~!欢迎来到中文歌声合成个人收集站-VCPedia.cn!
  • 若发现页面信息有误投稿至本站,请联系管理员。

MediaWiki:Common.js

VCPedia.cn ——关于中文歌声合成的一切。
MilkBoy讨论 | 贡献2025年2月25日 (二) 11:34的版本
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索

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

  • 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
  1. /* <pre> */
  2. /**
  3. * -------------------------------------------------------------------------
  4. * 此页面为全站的js常态加载脚本,如果你不知道你要修改的代码的作用和实现,请不要修改!
  5. * -------------------------------------------------------------------------
  6. */
  7. "use strict";
  8. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  9. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  10. return new (P || (P = Promise))(function (resolve, reject) {
  11. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  12. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  13. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  14. step((generator = generator.apply(thisArg, _arguments || [])).next());
  15. });
  16. };
  17. var __generator = (this && this.__generator) || function (thisArg, body) {
  18. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  19. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  20. function verb(n) { return function (v) { return step([n, v]); }; }
  21. function step(op) {
  22. if (f) throw new TypeError("Generator is already executing.");
  23. while (_) try {
  24. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  25. if (y = 0, t) op = [op[0] & 2, t.value];
  26. switch (op[0]) {
  27. case 0: case 1: t = op; break;
  28. case 4: _.label++; return { value: op[1], done: false };
  29. case 5: _.label++; y = op[1]; op = [0]; continue;
  30. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  31. default:
  32. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  33. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  34. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  35. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  36. if (t[2]) _.ops.pop();
  37. _.trys.pop(); continue;
  38. }
  39. op = body.call(thisArg, _);
  40. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  41. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  42. }
  43. };
  44. (function () { return __awaiter(void 0, void 0, void 0, function () {
  45. function startScroll() {
  46. $("body > #content > #siteNotice .scrollDiv:not(.scrolling), #moe-sitenotice-container > .moe-sitenotice .scrollDiv:not(.scrolling)").addClass("scrolling").each(function (_, ele) {
  47. var self = $(ele);
  48. self.children().each(function (_, child) {
  49. if (child.innerHTML.trim() === "") {
  50. child.remove();
  51. }
  52. });
  53. var children = self.children();
  54. if (children.length === 0) {
  55. return;
  56. }
  57. var firstChild = children.first();
  58. var firstChildHeight = firstChild.outerHeight();
  59. self.height(firstChildHeight);
  60. children.slice(1).css("top", "".concat(Math.ceil(firstChildHeight), "px"));
  61. firstChild.css("top", "0");
  62. });
  63. }
  64. function autoScroll() {
  65. setInterval(function () {
  66. if (!document.hidden) {
  67. $("body > #content > #siteNotice .scrollDiv.scrolling, #moe-sitenotice-container > .moe-sitenotice .scrollDiv.scrolling").each(function (_, ele) {
  68. var self = $(ele);
  69. if (self.css("font-weight") === "700") {
  70. return;
  71. }
  72. var children = self.children();
  73. var all = self.add(children);
  74. if (children.length === 1) {
  75. return;
  76. }
  77. var firstChild = children.first();
  78. var firstChildHeight = firstChild.outerHeight();
  79. var secondChild = firstChild.next();
  80. var secondChildHeight = secondChild.outerHeight();
  81. var otherChild = children.slice(2);
  82. var maxHeight = Math.max(firstChildHeight, secondChildHeight);
  83. otherChild.each(function (_, child) {
  84. maxHeight = Math.max(maxHeight, $(child).outerHeight());
  85. });
  86. all.addClass("animation");
  87. self.height(maxHeight);
  88. firstChild.css("top", "-".concat(firstChildHeight, "px"));
  89. secondChild.css("top", "".concat((maxHeight - secondChildHeight) / 2, "px"));
  90. otherChild.css("top", "".concat(Math.ceil(maxHeight), "px"));
  91. setTimeout(function () {
  92. all.removeClass("animation");
  93. firstChild.appendTo(self).css("top", Math.ceil(maxHeight));
  94. }, 400);
  95. });
  96. }
  97. }, 5000);
  98. }
  99. function multimediaViewer() {
  100. var _scrollTo = window.scrollTo;
  101. var flag = location.hash.startsWith("#/media/");
  102. window.scrollTo = function scrollTo(x_option, y) {
  103. if (flag) {
  104. console.info("Prevent multimediaViewer called");
  105. }
  106. else if (y === undefined) {
  107. _scrollTo(x_option);
  108. }
  109. else {
  110. _scrollTo(x_option, y);
  111. }
  112. };
  113. setInterval(function () {
  114. $("a.image img[data-file-width], a.image img[data-file-height], .mw-mmv-filepage-buttons a.mw-mmv-view-expanded").not(".multimediaViewerScrollSet").each(function (_, ele) {
  115. ele.addEventListener("click", function (e) {
  116. if ($(e.target).closest(".TabLabelText")[0] || $(e.target).closest("a").closest(".mw-customtoggle")[0]) {
  117. e.preventDefault();
  118. e.stopPropagation();
  119. e.stopImmediatePropagation();
  120. $($(e.target).closest(".TabLabelText")[0] || $(e.target).closest("a").closest(".mw-customtoggle")[0]).trigger("click");
  121. return false;
  122. }
  123. flag = true;
  124. }, {
  125. capture: true
  126. });
  127. $(ele).addClass("multimediaViewerScrollSet");
  128. });
  129. if (document.querySelector(".mw-mmv-close")) {
  130. if (mw.config.get("wgMultimediaViewerInjected") !== "on") {
  131. mw.config.set("wgMultimediaViewerInjected", "on");
  132. $(".mw-mmv-image").off("click")[0].addEventListener("click", function (e) {
  133. if ($(e.target).is("img")) {
  134. window.open($(e.target).attr("src").replace(/(img\.moegirl\.org\.cn\/common\/)thumb\/([a-z\d]+\/[a-z\d]+\/)([^/]+)\/\d+px-\3/i, "$1$2$3"), "_blank").focus();
  135. e.preventDefault();
  136. e.stopPropagation();
  137. e.stopImmediatePropagation();
  138. return false;
  139. }
  140. else if ($(e.target).closest(".error-box")[0]) {
  141. return;
  142. }
  143. $(".mw-mmv-close").trigger("click");
  144. }, {
  145. capture: true
  146. });
  147. }
  148. }
  149. else if (mw.config.get("wgMultimediaViewerInjected") === "on") {
  150. flag = false;
  151. mw.config.set("wgMultimediaViewerInjected", "off");
  152. }
  153. }, 137);
  154. }
  155. function noticeActivityClose() {
  156. return __awaiter(this, void 0, void 0, function () {
  157. var noticeActivity, topNoticeId_1, children_1, button_1, link_1, status_1, localStorageValue;
  158. return __generator(this, function (_a) {
  159. switch (_a.label) {
  160. case 0:
  161. noticeActivity = $("body > #content #notice-activity");
  162. if (!(noticeActivity.length > 0)) return [3, 2];
  163. return [4, mw.loader.using(["user.options"])];
  164. case 1:
  165. _a.sent();
  166. if (+mw.user.options.get("gadget-noticeActivity") === 1) {
  167. noticeActivity.hide();
  168. return [2];
  169. }
  170. topNoticeId_1 = noticeActivity.data("topNoticeId");
  171. noticeActivity.css("position", "relative");
  172. children_1 = noticeActivity.children();
  173. button_1 = $("<span>");
  174. button_1.css({
  175. position: "absolute",
  176. right: "1rem",
  177. top: "50%",
  178. transform: "translate(0,-50%)",
  179. fontSize: "1rem"
  180. });
  181. link_1 = $("<a>");
  182. link_1.attr({
  183. href: "javascript:void(0);"
  184. }).text("隐藏活动通知");
  185. button_1.append("[").append(link_1).append("]");
  186. noticeActivity.append(button_1);
  187. status_1 = true;
  188. link_1.on("click", function () {
  189. if (status_1) {
  190. status_1 = false;
  191. children_1.hide();
  192. noticeActivity.css({
  193. height: "0px",
  194. overflow: "visible"
  195. });
  196. button_1.css("transform", "translate(0,0)");
  197. localStorage.setItem("AnnTools-notice-activity", topNoticeId_1);
  198. link_1.text("显示活动通知");
  199. }
  200. else {
  201. status_1 = true;
  202. children_1.show();
  203. noticeActivity.css({
  204. height: "auto",
  205. overflow: "visible"
  206. });
  207. button_1.css("transform", "translate(0,-50%)");
  208. localStorage.removeItem("AnnTools-notice-activity");
  209. link_1.text("隐藏活动通知");
  210. }
  211. });
  212. localStorageValue = localStorage.getItem("AnnTools-notice-activity");
  213. if (localStorageValue === topNoticeId_1) {
  214. link_1.trigger("click");
  215. }
  216. _a.label = 2;
  217. case 2: return [2];
  218. }
  219. });
  220. });
  221. }
  222. function parseLocalStorageItemAsArray(key) {
  223. try {
  224. var result = JSON.parse(localStorage.getItem(key));
  225. return Array.isArray(result) ? result : [];
  226. }
  227. catch (_a) {
  228. return [];
  229. }
  230. }
  231. function topNoticeScroll() {
  232. var siteNotice = $("body.skin-vector > #content > #siteNotice, body.skin-moeskin > #app > #moe-full-container > #moe-main-container > main > #moe-global-sidenav #moe-sidenav-sitenotice");
  233. var noticeType = {
  234. pinnedAnnouncement: "置顶公告",
  235. newAnnouncement: "7日内新公告",
  236. discussing: "新的讨论中提案、申请",
  237. voting: "新的投票中提案、申请",
  238. voted: "新的已投票结束提案、申请",
  239. };
  240. var newNotices = [];
  241. Object.keys(noticeType).forEach(function (type){
  242. var id = type;
  243. var links = siteNotice.find("#topNotice-".concat(type)).find("a");
  244. var existLinks = parseLocalStorageItemAsArray("AnnTools-top-notice-exist-".concat(id));
  245. var currentLinks = [];
  246. var newLinks = [];
  247. links.each(function (_, link){
  248. var href = link.href;
  249. var text = link.text.trim();
  250. currentLinks.push(href);
  251. if (!existLinks.includes(href)) {
  252. newLinks.push({
  253. href: href,
  254. text: text,
  255. });
  256. }
  257. });
  258. localStorage.setItem("AnnTools-top-notice-exist-".concat(id), JSON.stringify(currentLinks));
  259. if (newLinks.length > 0) {
  260. newNotices.push({
  261. type: noticeType[id],
  262. links: newLinks,
  263. });
  264. }
  265. });
  266. if (newNotices.length > 0) {
  267. $("#mw-notification-area").appendTo("body");
  268. var notification_1 = $("<dl>");
  269. newNotices.forEach(function (newNotice) {
  270. notification_1.append("<dt class=\"mw-parser-output\" style=\"font-weight: 400;\">".concat(newNotice.type, "\uFF1A</dt>"));
  271. var dd = $("<dd>");
  272. var ul = $("<ul>");
  273. dd.css("marginLeft", ".9em");
  274. newNotice.links.forEach(function(link) {
  275. var li = $("<li>");
  276. var a = $("<a>");
  277. a.attr({
  278. href: link.href,
  279. target: "_blank",
  280. "class": "external",
  281. }).text(link.text);
  282. a.appendTo(li);
  283. li.appendTo(ul);
  284. });
  285. ul.appendTo(dd);
  286. dd.appendTo(notification_1);
  287. });
  288. notification_1.find("a").on("click",function(e) {
  289. e.stopImmediatePropagation();
  290. e.stopPropagation();
  291. });
  292. mw.notify(notification_1, {
  293. autoHide: false,
  294. title: "有新的站务通知(点击通知空白处关闭)",
  295. });
  296. }
  297. }
  298. function hashJump() {
  299. return __awaiter(this, void 0, void 0, function () {
  300. var hash;
  301. return __generator(this, function (_a) {
  302. switch (_a.label) {
  303. case 0: return [4, mw.loader.using(["jquery.makeCollapsible"])];
  304. case 1:
  305. _a.sent();
  306. $(".mw-collapsible").makeCollapsible();
  307. hash = location.hash;
  308. location.hash = "";
  309. location.hash = hash;
  310. return [2];
  311. }
  312. });
  313. });
  314. }
  315. var copyRightsNameSpaces, wgUserGroups, isMGPMGUser, getResponseHeader;
  316. return __generator(this, function (_a) {
  317. switch (_a.label) {
  318. case 0:
  319. copyRightsNameSpaces = [
  320. 0,
  321. 4,
  322. 8,
  323. 10,
  324. 12,
  325. 274,
  326. 828,
  327. ];
  328. wgUserGroups = mw.config.get("wgUserGroups");
  329. isMGPMGUser = wgUserGroups.includes("patroller") || wgUserGroups.includes("sysop");
  330. getResponseHeader = XMLHttpRequest.prototype.getResponseHeader;
  331. XMLHttpRequest.prototype.getResponseHeader = function (name) {
  332. return "\n".concat(this.getAllResponseHeaders().toLowerCase()).includes("\n".concat(name.toLowerCase(), ": ")) ? getResponseHeader.bind(this)(name) : (console.info("Refused to get unsafe header \"".concat(name, "\"\n"), this, "\n", new Error().stack), null);
  333. };
  334. return [4, $.ready];
  335. case 1:
  336. _a.sent();
  337. startScroll();
  338. autoScroll();
  339. multimediaViewer();
  340. if (mw.config.get("wgMainPageTitle") === mw.config.get("wgPageName") && mw.config.get("wgAction") === "view") {
  341. $("body").addClass("mainpage");
  342. }
  343. $.extend({
  344. ucFirst: function (_s) {
  345. var s = "".concat(_s);
  346. return s.charAt(0).toUpperCase() + s.substring(1);
  347. }
  348. });
  349. $(".reference-text > ul,.reference-text > ol").each(function (_, ele) {
  350. if (ele.parentElement.childNodes[0] === ele) {
  351. $(ele).addClass("listInRef");
  352. }
  353. });
  354. if ($(".mw-collapsible")[0] && location.hash !== "") {
  355. hashJump();
  356. }
  357. noticeActivityClose();
  358. if (wgUserGroups.includes("user")) {
  359. topNoticeScroll();
  360. }
  361. $(window).on("load", function () {
  362. $(".mw-helplink").each(function (_, ele) {
  363. if (!ele.href.endsWith("/zh")) {
  364. ele.href += "/zh";
  365. }
  366. });
  367. });
  368. return [2];
  369. }
  370. });
  371. }); })();
  372. /* </pre> */