User:AnYiLin/js/ArticleInfo.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**
* Copyright (c) 2020-present, 安忆.
*
* @author 安忆 [[zh:U:安忆]]
* @file ArticleInfo.js
* @license GPL v3
*/
(function articleInfo() {
var element;
if (document.body.classList.contains('skin-cologneblue') || document.body.classList.contains('skin-nostalgia')) {
element = document.getElementById('mw-content-text');
} else if (document.body.classList.contains('skin-minerva') && !document.body.classList.contains('page-Main_Page')) {
element = document.getElementById('mw-content-subtitle');
} else {
element = document.getElementById('contentSub');
}
if (element && RLCONF.wgAction === 'view' && RLCONF.wgIsArticle && RLCONF.wgCurRevisionId !== 0 && RLCONF.wgRevisionId !== 0 && RLCONF.wgCurRevisionId === RLCONF.wgRevisionId) {
var style = document.createElement('style');
style.id = 'css-xtools';
style.appendChild(document.createTextNode('#xtools,.skin-minerva #xtools+#mw-content-subtitle .subpages,.skin-timeless #xtools+#contentSub .subpages{font-size:.8em;line-height:1;width:auto}.skin-minerva #xtools+#mw-content-subtitle{margin:0}.skin-minerva #xtools,.skin-timeless #xtools,.skin-timeless #xtools+#contentSub .subpages{border:solid #eaecf0;border-width:1px 0;padding:.4em 0}.skin-minerva #xtools+#mw-content-subtitle .subpages,.skin-timeless #xtools+#contentSub .subpages{padding:.4em 0 .4em 19px}'));
document.head.appendChild(style);
element.insertAdjacentHTML('beforebegin', '<div class="noprint" id="xtools"><span id="xtools_result"></span></div>');
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://xtools.wmcloud.org/api/page/articleinfo/' + mw.config.get('wgDBname') + '/' + RLCONF.wgPageName.replace(/["%&?+\\]/g, escape) + '?format=html&uselang=' + mw.config.get('wgUserLanguage'));
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
document.getElementById('xtools_result').insertAdjacentHTML('afterbegin', xhr.responseText);
} else if (xhr.readyState === 4) {
var text = ['zh', 'zh-hans', 'zh-cn', 'zh-sg'].indexOf(mw.config.get('wgUserLanguage')) !== -1 ? '加载失败' : '載入失敗';
document.getElementById('xtools_result').insertAdjacentHTML('afterbegin', '<span style="line-height:20px;margin-left:19px">ArticleInfo' + text + '</span>');
}
};
}
})();