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

Content deleted Content added
(bot/CD)
(bot/CD)
 
Line 364:
}));
 
var version = "0.89.0";
var gitAbbrevHash = "d7e185d317b503";
var gitBranch = "mainHEAD";
var gitDate = "TueWed, 419 Feb 2025 1200:3313:5653 +0800";
var gitVersion = "0.89.0+gd7e185dg317b503";
 
/**
Line 428:
upgrade(db, oldVersion, newVersion) {
let currentVersion = oldVersion;
// Adding new stores? Make sure to also add it in `reset()`!
const upgrader = {
0: () => {
Line 515 ⟶ 516:
}
}
});
}
/**
* Reset the Deputy database. Very dangerous!
*/
reset() {
return __awaiter(this, void 0, void 0, function* () {
yield this.db.clear('keyval');
yield this.db.clear('casePageCache');
yield this.db.clear('diffCache');
yield this.db.clear('diffStatus');
yield this.db.clear('pageStatus');
yield this.db.clear('tagCache');
});
}
Line 2,053 ⟶ 2,067:
class Setting {
/**
*
* @param options
* @param options.serialize Serialization function. See {@link Setting#serialize}
Line 2,251 ⟶ 2,264:
DeputyPageToolbarState[DeputyPageToolbarState["Hidden"] = 2] = "Hidden";
})(DeputyPageToolbarState || (DeputyPageToolbarState = {}));
 
/**
* A button that performs an action when clicked. Shown in the preferences screen,
* and acts exactly like a setting, but always holds a value of 'null'.
*/
class Action extends Setting {
/**
* @param onClick
* @param displayOptions
*/
constructor(onClick, displayOptions = {}) {
super({
serialize: () => undefined,
deserialize: () => undefined,
displayOptions: Object.assign({}, displayOptions, { type: 'button' })
});
this.onClick = onClick;
}
}
 
/**
Line 2,315 ⟶ 2,347:
displayOptions: {
type: 'checkbox'
}
}),
resetDatabase: new Action(() => __awaiter(this, void 0, void 0, function* () {
yield window.deputy.storage.reset();
}), {
disabled: () => !window.deputy,
extraOptions: {
flags: ['destructive']
}
}),
resetPreferences: new Action(() => __awaiter(this, void 0, void 0, function* () {
yield MwApi.action.saveOption(UserConfiguration.optionKey, null);
}), {
extraOptions: {
flags: ['destructive']
}
})
Line 2,456 ⟶ 2,503:
UserConfiguration.optionKey = 'userjs-deputy';
 
/* eslint-disable mediawiki/msg-doc */
let InternalConfigurationGroupTabPanel$1;
/**
Line 2,511 ⟶ 2,557:
case 'code':
this.$element.append(this.newCodeField(settingKey, setting, setting.displayOptions.extraOptions));
break;
case 'button':
this.$element.append(this.newButtonField(settingKey, setting, setting.displayOptions.extraOptions));
break;
default:
Line 2,774 ⟶ 2,823:
newCodeField(settingKey, setting, extraFieldOptions) {
return this.newStringLikeField(OO.ui.MultilineTextInputWidget, settingKey, setting, extraFieldOptions);
}
/**
* Creates a new button setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newButtonField(settingKey, setting, extraFieldOptions) {
const isDisabled = setting.isDisabled(this.config.config);
const msgPrefix = `deputy.setting.${this.mode}.${this.config.group}.${settingKey}`;
const desc = mw.message(`${msgPrefix}.description`);
const field = new OO.ui.ButtonWidget(Object.assign({ label: this.getSettingMsg(settingKey, 'name'), disabled: isDisabled !== undefined && isDisabled !== false }, extraFieldOptions));
const layout = new OO.ui.FieldLayout(field, {
align: 'top',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
field.on('click', () => __awaiter(this, void 0, void 0, function* () {
try {
if (yield OO.ui.confirm(mw.msg(`${msgPrefix}.confirm`))) {
yield setting.onClick();
OO.ui.alert(mw.msg(`${msgPrefix}.success`));
}
}
catch (e) {
OO.ui.alert(mw.msg(`${msgPrefix}.failed`));
}
}));
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
};
Line 2,790 ⟶ 2,873:
}
 
let windowManager;
/**
* Opens a temporary window. Use this for dialogs that are immediately destroyed
Line 2,801 ⟶ 2,885:
return __awaiter(this, void 0, void 0, function* () {
return new Promise((res) => {
letvar wm = new OO.ui.WindowManager()_a;
if (!windowManager) {
document.getElementsByTagName('body')[0].appendChild(unwrapWidget(wm));
wm windowManager = new OO.addWindowsui.WindowManager([window]);
const parent = (_a = document.getElementById('mw-teleport-target')) !== null && _a !== void 0 ? _a : document.getElementsByTagName('body')[0];
wm.openWindow(window);
wm.on('closing', (win, closed) => {parent.appendChild(unwrapWidget(windowManager));
}
windowManager.addWindows([window]);
windowManager.openWindow(window);
windowManager.on('closing', (win, closed) => {
closed.then(() => {
if (wmwindowManager) {
const _wm = wmwindowManager;
wmwindowManager = null;
removeElement(unwrapWidget(_wm));
_wm.destroy();
Line 2,862 ⟶ 2,950:
"deputy.setting.user.core.dangerMode.name": "Danger mode",
"deputy.setting.user.core.dangerMode.description": "Live on the edge. This disables most confirmations and warnings given by Deputy, only leaving potentially catastrophic actions, such as page edits which break templates. It also adds extra buttons meant for rapid case processing. Intended for clerk use; use with extreme caution.",
"deputy.setting.user.core.resetDatabase.name": "Reset database",
"deputy.setting.user.core.resetDatabase.description": "Resets the Deputy internal database. This clears all cached data, including saved page and revision statuses that haven't been saved on-wiki. This does not clear your Deputy preferences.",
"deputy.setting.user.core.resetDatabase.confirm": "Are you sure you want to reset the Deputy database? This action cannot be undone.",
"deputy.setting.user.core.resetDatabase.success": "Database reset successfully. Please refresh the page to see changes.",
"deputy.setting.user.core.resetDatabase.failed": "Could not reset the database. If this error persists, please contact the Deputy maintainers.",
"deputy.setting.user.core.resetPreferences.name": "Reset preferences",
"deputy.setting.user.core.resetPreferences.description": "Resets your Deputy preferences. This clears all settings you have saved in Deputy across all browsers.",
"deputy.setting.user.core.resetPreferences.confirm": "Are you sure you want to reset your Deputy preferences? This action cannot be undone.",
"deputy.setting.user.core.resetPreferences.success": "Preferences reset successfully. Please refresh the page to see changes.",
"deputy.setting.user.core.resetPreferences.failed": "Could not reset preferences. If this error persists, please contact the Deputy maintainers.",
"deputy.setting.user.cci": "CCI",
"deputy.setting.user.cci.enablePageToolbar.name": "Enable page toolbar",
Line 3,245 ⟶ 3,343:
InternalConfigurationDialog = (_a = class ConfigurationDialog extends OO.ui.ProcessDialog {
/**
*
* @param data
*/
Line 3,278 ⟶ 3,375:
generateGroupLayouts() {
return Object.keys(this.config.all).map((group) => ConfigurationGroupTabPanel({
$overlay: this.$overlay,
config: this.config,
group
Line 3,283 ⟶ 3,381:
}
/**
*
* @param action
* @return An OOUI Process.
Line 5,706 ⟶ 5,803:
*/
get autosaveHash() {
return `CASE--${this.row.casePage.title.getPrefixedDb()}+H--${this.section.headingName}-${this.section.headingN}+PAGE--${this.row.title.getPrefixedDb()}`;
}
/**
Line 5,875 ⟶ 5,972:
*/
getSavedStatus() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
return (_a = yield window.deputy.storage.db.get('pageStatus', this.autosaveHash);) !== null && _a !== void 0 ? _a :
// Old hash (< v0.9.0)
yield window.deputy.storage.db.get('pageStatus', `CASE--${this.row.casePage.title.getPrefixedDb()}+PAGE--${this.row.title.getPrefixedDb()}`);
});
}
Line 9,624 ⟶ 9,724:
catch (e) {
error('Cannot convert `diff` parameter to URL.', e);
windowOO.CopiedTemplateEditorui.windowManageralert(mw.openWindowmsg('messagedeputy.ante.copied.diffDeprecate.failed', {));
message: mw.msg('deputy.ante.copied.diffDeprecate.failed'),
actions: [OO.ui.MessageDialog.static.actions[0]]
});
}
});
Line 14,149 ⟶ 14,246:
}
}) :
window.CopiedTemplateEditor.windowManager.openWindow('message',// {TODO: i18n
message: OO.ui.alert('There are no templates to merge.',);
actions: [OO.ui.MessageDialog.static.actions[0]]
});
});
const resetButton = new OO.ui.ButtonWidget({
Line 14,320 ⟶ 14,415:
if (unwrapWidget(this.layout)
.querySelector('.oo-ui-flaggedElement-invalid') != null) {
windowOO.CopiedTemplateEditorui.windowManageralert(mw.openWindowmsg('messagedeputy.ante.invalid', {));
message: mw.msg('deputy.ante.invalid'),
actions: [OO.ui.MessageDialog.static.actions[0]]
});
return process;
}