add custom protection

This commit is contained in:
fyears 2024-05-25 14:37:37 +08:00
parent d9cab7b1ff
commit 408acb6230
5 changed files with 81 additions and 19 deletions

View File

@ -289,6 +289,9 @@
"settings_protectmodifypercentage_000_desc": "0 (always block)", "settings_protectmodifypercentage_000_desc": "0 (always block)",
"settings_protectmodifypercentage_050_desc": "50 (default)", "settings_protectmodifypercentage_050_desc": "50 (default)",
"settings_protectmodifypercentage_100_desc": "100 (disable the protection)", "settings_protectmodifypercentage_100_desc": "100 (disable the protection)",
"settings_protectmodifypercentage_custom_desc": "custom",
"settings_protectmodifypercentage_customfield": "Custom Abort Sync If Modification Above Percentage",
"settings_protectmodifypercentage_customfield_desc": "You need to enter a number between 0 (inclusive) and 100 (inclusive). Float number is also allowed.",
"setting_syncdirection": "Sync Direction", "setting_syncdirection": "Sync Direction",
"setting_syncdirection_desc": "Which direction should the plugin sync to? Please be aware that only CHANGED files (based on time and size) are synced regardless any option.", "setting_syncdirection_desc": "Which direction should the plugin sync to? Please be aware that only CHANGED files (based on time and size) are synced regardless any option.",
"setting_syncdirection_bidirectional_desc": "Bidirectional (default)", "setting_syncdirection_bidirectional_desc": "Bidirectional (default)",

View File

@ -288,6 +288,9 @@
"settings_protectmodifypercentage_000_desc": "0总是强制中止", "settings_protectmodifypercentage_000_desc": "0总是强制中止",
"settings_protectmodifypercentage_050_desc": "50默认值", "settings_protectmodifypercentage_050_desc": "50默认值",
"settings_protectmodifypercentage_100_desc": "100去除此保护", "settings_protectmodifypercentage_100_desc": "100去除此保护",
"settings_protectmodifypercentage_custom_desc": "自定义",
"settings_protectmodifypercentage_customfield": "如果修改超过自定义百分比则中止同步",
"settings_protectmodifypercentage_customfield_desc": "您需要输入 0~ 100的数字。小数也是可以的。",
"setting_syncdirection": "同步方向", "setting_syncdirection": "同步方向",
"setting_syncdirection_desc": "插件应该向哪里同步?注意每个选项都是只有修改了的文件(基于修改时间和大小判断)才会触发同步动作。", "setting_syncdirection_desc": "插件应该向哪里同步?注意每个选项都是只有修改了的文件(基于修改时间和大小判断)才会触发同步动作。",
"setting_syncdirection_bidirectional_desc": "双向同步(默认)", "setting_syncdirection_bidirectional_desc": "双向同步(默认)",

View File

@ -287,6 +287,9 @@
"settings_protectmodifypercentage_000_desc": "0總是強制中止", "settings_protectmodifypercentage_000_desc": "0總是強制中止",
"settings_protectmodifypercentage_050_desc": "50預設值", "settings_protectmodifypercentage_050_desc": "50預設值",
"settings_protectmodifypercentage_100_desc": "100去除此保護", "settings_protectmodifypercentage_100_desc": "100去除此保護",
"settings_protectmodifypercentage_custom_desc": "自定義",
"settings_protectmodifypercentage_customfield": "如果修改超過自定義百分比則中止同步",
"settings_protectmodifypercentage_customfield_desc": "您需要輸入 0~ 100的數字。小數也是可以的。",
"setting_syncdirection": "同步方向", "setting_syncdirection": "同步方向",
"setting_syncdirection_desc": "外掛應該向哪裡同步?注意每個選項都是隻有修改了的檔案(基於修改時間和大小判斷)才會觸發同步動作。", "setting_syncdirection_desc": "外掛應該向哪裡同步?注意每個選項都是隻有修改了的檔案(基於修改時間和大小判斷)才會觸發同步動作。",
"setting_syncdirection_bidirectional_desc": "雙向同步(預設)", "setting_syncdirection_bidirectional_desc": "雙向同步(預設)",

View File

@ -2168,28 +2168,77 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
}); });
}); });
new Setting(advDiv) const percentage1 = new Setting(advDiv)
.setName(t("settings_protectmodifypercentage")) .setName(t("settings_protectmodifypercentage"))
.setDesc(t("settings_protectmodifypercentage_desc")) .setDesc(t("settings_protectmodifypercentage_desc"));
.addDropdown((dropdown) => {
for (const i of Array.from({ length: 11 }, (x, i) => i * 10)) { const percentage2 = new Setting(advDiv)
let desc = `${i}`; .setName(t("settings_protectmodifypercentage_customfield"))
if (i === 0) { .setDesc(t("settings_protectmodifypercentage_customfield_desc"));
desc = t("settings_protectmodifypercentage_000_desc"); if ((this.plugin.settings.protectModifyPercentage ?? 50) % 10 === 0) {
} else if (i === 50) { percentage2.settingEl.addClass("settings-percentage-custom-hide");
desc = t("settings_protectmodifypercentage_050_desc"); }
} else if (i === 100) { let percentage2Text: TextComponent | undefined = undefined;
desc = t("settings_protectmodifypercentage_100_desc"); percentage2.addText((text) => {
} text.inputEl.type = "number";
dropdown.addOption(`${i}`, desc); percentage2Text = text;
} text
dropdown .setPlaceholder("0 ~ 100")
.setValue(`${this.plugin.settings.protectModifyPercentage ?? 50}`) .setValue(`${this.plugin.settings.protectModifyPercentage ?? 50}`)
.onChange(async (val) => { .onChange(async (val) => {
this.plugin.settings.protectModifyPercentage = Number.parseInt(val); let k = Number.parseFloat(val.trim());
if (Number.isNaN(k)) {
// do nothing!
} else {
if (k < 0) {
k = 0;
} else if (k > 100) {
k = 100;
}
this.plugin.settings.protectModifyPercentage = k;
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}); }
});
});
percentage1.addDropdown((dropdown) => {
for (const i of Array.from({ length: 11 }, (x, i) => i * 10)) {
let desc = `${i}`;
if (i === 0) {
desc = t("settings_protectmodifypercentage_000_desc");
} else if (i === 50) {
desc = t("settings_protectmodifypercentage_050_desc");
} else if (i === 100) {
desc = t("settings_protectmodifypercentage_100_desc");
}
dropdown.addOption(`${i}`, desc);
}
dropdown.addOption(
"custom",
t("settings_protectmodifypercentage_custom_desc")
);
const p = this.plugin.settings.protectModifyPercentage ?? 50;
let initVal = "custom";
if (p % 10 === 0) {
initVal = `${p}`;
} else {
// show custom
percentage2.settingEl.removeClass("settings-percentage-custom");
}
dropdown.setValue(initVal).onChange(async (val) => {
const k = Number.parseInt(val);
if (val === "custom" || Number.isNaN(k)) {
// do nothing until user changes something in custom field
percentage2.settingEl.removeClass("settings-percentage-custom-hide");
} else {
this.plugin.settings.protectModifyPercentage = k;
percentage2.settingEl.addClass("settings-percentage-custom-hide");
percentage2Text?.setValue(`${k}`);
await this.plugin.saveSettings();
}
}); });
});
new Setting(advDiv) new Setting(advDiv)
.setName(t("setting_syncdirection")) .setName(t("setting_syncdirection"))

View File

@ -17,6 +17,10 @@
padding-top: 18px; padding-top: 18px;
} }
.settings-percentage-custom-hide {
display: none;
}
.s3-disclaimer { .s3-disclaimer {
font-weight: bold; font-weight: bold;
} }