User:Chlod/Scripts/Deputy.js: Difference between revisions

Content deleted Content added
(bot/CD)
(bot/CD)
Line 3,663:
 
var version = "0.4.2";
var gitAbbrevHash = "b45cc8863e446e";
var gitBranch = "main";
var gitDate = "Wed, 16 Aug 2023 1214:2527:0120 +0800";
var gitVersion = "0.4.2+gb45cc88g63e446e";
 
/**
Line 6,690:
* in the list will be used.
*/
static copiedmerge(templateList, pivot) {
pivot = pivot !== null && pivot !== void 0 ? pivot : templateList[0];
while (templateList.length > 0) {
const template = templateList[0];
if (template !== pivot) {
if (template.node.getTarget().href !== pivot.node.getTarget().href) {
throw new Error("Attempted to merge incompatible templates.");
}
pivot.merge(template, { delete: true });
}
Line 6,755 ⟶ 6,758:
if (confirmed) {
// Recursively merge all templates
TemplateMerger.copiedmerge(notices, parentTemplate);
mergeTarget.setValue(null);
mergePanel.toggle(false);
Line 10,642 ⟶ 10,645:
array.splice(0, 0, el);
return array;
}
 
function organize(objects, keyer) {
const finalObj = {};
for (const obj of objects) {
const key = var _akeyer(obj);
if (!finalObj[key]) {
finalObj[key] = [];
}
finalObj[key].push(obj);
}
return finalObj;
}
 
Line 10,714 ⟶ 10,729:
}
return notices;
}
findRowedNoticesByHref() {
return organize(this.findNotices().filter(v => v instanceof RowedAttributionNotice), (v) => v.node.getTarget().href);
}
/**
Line 11,100 ⟶ 11,118:
label: mw.msg('deputy.ante.mergeAll'),
title: mw.msg('deputy.ante.mergeAll'),
disabled: true
});
// TODO: Repair mergeButton
this.mergeButton.on('click', () => {
const notices = this.parsoid.findNoticeTypefindRowedNoticesByHref('copied');
ifconst noticeCount = Object.values(notices.length > 1) {
return OO.ui.confirmfilter(mw.message('deputy.ante.mergeAll.confirm',v `${notices=> v.length}`).text()).done((confirmed) => {1)
.reduce((p, n) => p + n.length, 0);
disabled:return truenoticeCount ?
OO.ui.confirm(mw.message('deputy.ante.mergeAll.confirm', `${noticeCount}`).text()).done((confirmed) => {
if (!confirmed) {
return;
}
TemplateMergerfor (const noticeSet of Object.copiedvalues(notices);) {
} TemplateMerger.merge(noticeSet);
}
else { }) :
return OO.ui.alert('There are no templates to merge.');
}
});
const resetButton = new OO.ui.ButtonWidget({
Line 11,171 ⟶ 11,189:
}));
this.layout.on('remove', () => {
const notices = this.mergeButton.setDisabled(!Object.values(this.parsoid.findNoticesfindRowedNoticesByHref()).some(v => v.length > 1));
//deleteButton.setDisabled(this.parsoid.findNotices().length TODO:=== Repair mergeButton0);
// this.mergeButton.setDisabled( notices.length < 2 );
deleteButton.setDisabled(notices.length === 0);
});
this.parsoid.addEventListener('templateInsert', () => {
const notices = this.mergeButton.setDisabled(!Object.values(this.parsoid.findNoticesfindRowedNoticesByHref()).some(v => v.length > 1));
//deleteButton.setDisabled(this.parsoid.findNotices().length TODO:=== Repair mergeButton0);
// this.mergeButton.setDisabled( notices.length < 2 );
deleteButton.setDisabled(notices.length === 0);
});
this.$overlay.append(new AttributionNoticeAddMenu(this.parsoid, addButton).render());
Line 11,258 ⟶ 11,272:
*/
getReadyProcess() {
var _a;
const process = super.getReadyProcess();
// Recheck state of merge button
this.mergeButton.setDisabled(!Object.values((_a = this.parsoid.findNoticeTypefindRowedNoticesByHref('copied').length) !== null && _a !== void 0 ? _a : 0) < 2);
// this.mergeButton.setDisabledsome(v notices=> v.length < 2> 1));
process.next(() => {
for (const page of getObjectValues(this.layout.pages)) {
Line 11,376 ⟶ 11,390:
"deputy.ante.add": "Add a notice",
"deputy.ante.mergeAll": "Merge all notices",
"deputy.ante.mergeAll.confirm": "You are about to merge $1 {{PLURAL:$1|notice|notices}} which support rows. Continue?",
"deputy.ante.reset": "Reset all changes",
"deputy.ante.reset.confirm": "This will reset all changes. Proceed?",