User:GuoPC/js/TSIndicator.js
注意:在您儲存之後您必須清除瀏覽器快取才可看到最新的變動。
- Firefox / Safari:按住「Shift」時點選「重新整理」,或按「Ctrl-F5」或「Ctrl-R」 (Mac則為「⌘-R」)
- Google Chrome:按「Ctrl-Shift-R」 (Mac 則為「⌘-Shift-R」)
- Internet Explorer:按住「Ctrl」時點選「重新整理」,或按「Ctrl-F5」
- Opera:進入「工具→偏好設定」中清除快取。
- 如果您已登入但該頁面出現未登入狀態,請嘗試在網址列的URL最後新增代碼
?_=1
來訪問最新頁面。
$(() => (async () => {
if (mw.config.get("wgNamespaceNumber") != -1 && $('.mw-parser-output style[data-mw-deduplicate]').length > 0) {
await mw.loader.using(["mediawiki.api", "oojs-ui"]);
let list = $('<ol>').attr('style', 'font-size: 0.9em; margin-left: 2em; list-style: decimal;');
let tsrevs = [];
$('.mw-parser-output style[data-mw-deduplicate]').each(function () {
let revid = $(this).attr('data-mw-deduplicate');
if (revid) {
tsrevs.push(revid.slice(16));
}
});
insertTSI();
$('#pc-templatestyles-button > .oo-ui-buttonElement-button').on('click', async () => {
if (list.children().length > 0) {
return;
} else {
const TITLES = await getPageTitleByDiff(tsrevs.join('|'));
for (let i = 0; i < tsrevs.length; i++) {
let line = $('<li>')
.append($('<a>').text(TITLES[i]).attr({
href: '/' + TITLES[i],
target: '_blank',
rel: 'noopener noreferrer'
}));
list.append(line);
}
$('#pc-templatestyles-list-loading').hide();
$('#pc-templatestyles-list').append(list);
}
});
} else {
return;
}
// 通過API查詢修訂版本ID對應的頁面標題
async function getPageTitleByDiff(revids) {
const API = new mw.Api();
let revtitles = [];
return await API.get({
action: "query",
format: "json",
prop: "info",
revids: revids
}).then((res) => {
for (const PAGE of Object.values(res.query.pages)) {
revtitles.push(PAGE.title);
};
return revtitles;
});
}
// 構造並插入PopupButton
function insertTSI() {
const TSILoading = new OO.ui.ProgressBarWidget({
id: "pc-templatestyles-list-loading",
progress: false
})
const TSIMain = new OO.ui.PopupButtonWidget({
icon: 'puzzle',
iconTitle: wgULS('模板樣式表', '模板樣式表'),
flags: 'progressive',
framed: false,
id: "pc-templatestyles-button",
popup: {
head: true,
label: $(`<strong>${wgULS('此頁面使用的模板樣式表', '此頁面使用的模板樣式表')}</strong>`),
$content: $('<div>').attr('id', 'pc-templatestyles-list').append(TSILoading.$element),
padded: true,
align: mw.config.get('skin') == 'moeskin' ? ($(window).width() > 768 ? 'backwards' : 'center') : 'center',
autoFlip: false
}
});
let pos = '';
switch (mw.config.get('skin')) {
case 'moeskin':
pos = $('.moe-indicators').length > 0 ? '.moe-indicators' : '0';
break;
case 'vector':
default:
pos = $('.mw-indicators');
}
if (pos == '0') {
mw.loader.addStyleTag(`
#pc-templatestyles {
display: flex;
justify-content: center;
align-items: center;
float: right;
height: 42px;
margin: 10px 5px 5px 5px;
}
@media (max-width: 768px) {
#pc-templatestyles {
float: none;
margin: 0 0 5px 0;
height: auto;
order: 5;
}
.header-title-extra {
order: 6;
}
#moe-article-header-title {
display: flex;
flex-direction: column;
}
}
`);
const ELE = $('<div>').attr('id', 'pc-templatestyles').append(TSIMain.$element);
$('#moe-article-header-title').prepend(ELE);
} else {
$(pos).append(TSIMain.$element);
}
}
})());
此頁面最後編輯於 2024年6月27日 (星期四) 14:21。