MediaWiki:Common.js
MediaWiki界面页面
更多操作
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/*
* Script Name: InputUsername
* Author: Ihojose
*
* Adds the username of the user viewing the page.
* Only works for logged in users.
*
* Added by Spottra 5-Apr-2015:
* Individual users can define "window.disableUsernameReplace = true;" in their
* global.js or local common.js file to disable the replacement for themselves if
* they so desire.
*/
;(function ($, mw) {
'use strict';
var username = mw.config.get('wgUserName');
if (
window.disableUsernameReplace ||
!username
) {
return;
}
window.disableUsernameReplace = true;
var $rail = $('#WikiaRail'),
customSelector = window.UsernameReplaceSelector
? ', ' + window.UsernameReplaceSelector
: '';
function inputUsername($content) {
$content.find('.InputUsername, .insertusername' + customSelector).text(username);
}
mw.hook('wikipage.content').add(inputUsername);
if ($rail.hasClass('loaded')) {
inputUsername($rail);
} else if ($rail.length) {
$rail.on('afterLoad.rail',
inputUsername.bind(null, $rail)
);
}
})(window.jQuery, window.mediaWiki);
/*
* 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 });
}
});
mw.loader.load('/Script:' + wgPageName + '?action=raw&ctype=text/javascript'); // Import page scripts
// mw.loader.load('/MediaWiki:Audio.js'); //Import audio script