add new setting for {{scoreStar}} and {{myRatingStar}}

This commit is contained in:
HughWan 2023-12-29 23:09:05 +08:00
parent b4f41bcae8
commit 7539134b05
12 changed files with 165 additions and 12 deletions

@ -13,7 +13,7 @@
# {{title}}
<div style="text-align: center;">{{originalTitle}}</div>
<div style="text-align: center;">⭐⭐⭐⭐⭐</div>
<div style="text-align: center;">{{scoreStar}}</div>
---

@ -1,7 +1,7 @@
{
"id": "obsidian-douban-plugin",
"name": "Douban",
"version": "1.9.9",
"version": "2.0.0",
"minAppVersion": "0.12.0",
"description": "This is a plugin that can import movies/books/musics/notes/games info data from Douban for Obsidian .",
"author": "Wanxp",

@ -1,6 +1,6 @@
{
"name": "obsidian-douban-plugin",
"version": "1.9.9",
"version": "2.0.0",
"description": "This is a plugin for Obsidian (https://obsidian.md) that can import data from Douban (https://www.douban.com/).",
"main": "main.js",
"scripts": {

@ -51,7 +51,7 @@ export const DEFAULT_SETTINGS: DoubanPluginSetting = {
scoreSetting: {
starFull: '⭐',
starEmpty: '☆',
displayStarEmpty: true,
displayStarEmpty: false,
maxStar: 5,
}

@ -0,0 +1,35 @@
import {ButtonComponent, Modal} from "obsidian";
import {i18nHelper} from "../../lang/helper";
export class ConfirmDialogModal extends Modal {
private promise:Promise<any>;
private message:string;
constructor(app: any, message:string, promise: Promise<any>) {
super(app);
this.message = message;
this.promise = promise;
}
onOpen() {
const {contentEl} = this;
contentEl.createEl('h3', {text: i18nHelper.getMessage('110152')});
contentEl.createEl('p', {text: `${this.message}`});
contentEl.createEl('p', {text: i18nHelper.getMessage('125033')});
const controls = contentEl.createDiv("controls");
controls.addClass("obsidian_douban_search_controls")
new ButtonComponent(controls)
.setButtonText(i18nHelper.getMessage('110152'))
.setCta()
.onClick(async () => {
await this.promise;
this.close();
}).setClass( "obsidian_douban_search_button");
new ButtonComponent(controls)
.setButtonText(i18nHelper.getMessage('110005'))
.onClick(() => {
this.close();
}).setClass( "obsidian_douban_cancel_button");
}
}

@ -7,6 +7,7 @@ import DoubanLogoutModel from "../component/DoubanLogoutModel";
import User from "../user/User";
import {createFolderSelectionSetting} from "./TemplateSettingHelper";
import { log } from "../../utils/Logutil";
import {ConfirmDialogModal} from "../component/ConfirmDialogModal";
@ -31,6 +32,7 @@ export function constructAdvancedUI(containerEl: HTMLElement, manager: SettingsM
function showAdvancedSettings(containerEl: HTMLElement, manager: SettingsManager) {
containerEl.empty();
const promise:Promise<any> = new Promise<any>((resolve, reject) => {resolve(null)});
new Setting(containerEl)
.setName(i18nHelper.getMessage('125001'))
.setDesc(i18nHelper.getMessage('125002'))
@ -48,6 +50,48 @@ function showAdvancedSettings(containerEl: HTMLElement, manager: SettingsManager
await manager.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName(i18nHelper.getMessage('125011'))
.setDesc(i18nHelper.getMessage('125012'))
.addButton((buttonComponent) => {
buttonComponent
.setIcon('reset')
.setTooltip(i18nHelper.getMessage('125013'))
.onClick(async (value) => {
showConfirmDialog(i18nHelper.getMessage('125012'),
promise.then(() => {
manager.resetSetting();
}), manager)
});
});
new Setting(containerEl)
.setName(i18nHelper.getMessage('125021'))
.setDesc(i18nHelper.getMessage('125022'))
.addButton((buttonComponent) => {
buttonComponent
.setIcon('reset')
.setTooltip(i18nHelper.getMessage('125022'))
.onClick(async (value) => {
showConfirmDialog(i18nHelper.getMessage('125022'),
promise.then(() => {
manager.clearLoginInfo();
manager.plugin.userComponent.logout()
}), manager)
});
});
new Setting(containerEl)
.setName(i18nHelper.getMessage('125031'))
.setDesc(i18nHelper.getMessage('125032'))
.addButton((buttonComponent) => {
buttonComponent
.setIcon('reset')
.setTooltip(i18nHelper.getMessage('125032'))
.onClick(async (value) => {
showConfirmDialog(i18nHelper.getMessage('125032'), promise.then(() => {
manager.clearSyncCache();
}), manager);
});
});
}
function resetAdvanced( manager: SettingsManager) {
@ -55,3 +99,14 @@ function resetAdvanced( manager: SettingsManager) {
manager.plugin.settings.debugMode = false;
}
function showConfirmDialog(message:string, promise:Promise<any>, manager: SettingsManager) {
new ConfirmDialogModal(manager.plugin.app, message, promise
.then( () => {
manager.plugin.saveSettings();
})
.then( () => {
manager.plugin.settingTab.display();
})
).open();
}

@ -1,5 +1,5 @@
import {i18nHelper} from "../../lang/helper";
import {Setting, TextComponent, ToggleComponent, ValueComponent} from "obsidian";
import {Setting, TextComponent, ToggleComponent} from "obsidian";
import {createFolderSelectionSetting} from "./TemplateSettingHelper";
import {DEFAULT_SETTINGS} from "../../constant/DefaultSettings";
import {
@ -31,7 +31,7 @@ export function showFileExample(containerEl: HTMLElement, manager: SettingsManag
containerEl.empty();
const document = new DocumentFragment();
document.createDiv('file-path-example')
.innerHTML = `文件路径预览<a href="https://book.douban.com/subject/2253379/">《简爱》</a>: ${VariableUtil.replaceSubject(EXAMPLE_SUBJECT_MAP,
.innerHTML = `${i18nHelper.getMessage('121604')}<a href="https://book.douban.com/subject/2253379/">《简爱》</a>: ${VariableUtil.replaceSubject(EXAMPLE_SUBJECT_MAP,
FileUtil.join(manager.plugin.settings.dataFilePath, manager.plugin.settings.dataFileNamePath + ".md"), SupportType.BOOK,
manager)}`;
@ -47,7 +47,7 @@ function scoreSettingDisplay(containerEl: HTMLElement, manager: SettingsManager)
const scoreSettingsUI = containerEl.createDiv('score-settings');
const scoreShowUI = containerEl.createDiv('score-show');
//@ts-ignore
//@ts-ignore
const scoreSetting:ScoreSetting = manager.getSetting('scoreSetting');
scoreSettingsUI.createEl('span', {text: i18nHelper.getMessage('124120')})
const starFullUI = new TextComponent(scoreSettingsUI);

@ -192,4 +192,40 @@ export default class SettingsManager {
}
return false;
}
resetSetting() {
this.settings.scoreSetting = DEFAULT_SETTINGS.scoreSetting;
this.settings.arraySettings = DEFAULT_SETTINGS.arraySettings;
this.settings.arrayStart = DEFAULT_SETTINGS.arrayStart;
this.settings.arrayElementStart = DEFAULT_SETTINGS.arrayElementStart;
this.settings.arraySpiltV2 = DEFAULT_SETTINGS.arraySpiltV2;
this.settings.arrayElementEnd = DEFAULT_SETTINGS.arrayElementEnd;
this.settings.arrayEnd = DEFAULT_SETTINGS.arrayEnd;
this.settings.attachmentPath = DEFAULT_SETTINGS.attachmentPath;
this.settings.bookTemplateFile = DEFAULT_SETTINGS.bookTemplateFile;
this.settings.movieTemplateFile = DEFAULT_SETTINGS.movieTemplateFile;
this.settings.musicTemplateFile = DEFAULT_SETTINGS.musicTemplateFile;
this.settings.noteTemplateFile = DEFAULT_SETTINGS.noteTemplateFile;
this.settings.gameTemplateFile = DEFAULT_SETTINGS.gameTemplateFile;
this.settings.teleplayTemplateFile = DEFAULT_SETTINGS.teleplayTemplateFile;
this.settings.dateFormat = DEFAULT_SETTINGS.dateFormat;
this.settings.timeFormat = DEFAULT_SETTINGS.timeFormat;
this.settings.searchUrl = DEFAULT_SETTINGS.searchUrl;
this.settings.personNameMode = DEFAULT_SETTINGS.personNameMode;
this.settings.dataFilePath = DEFAULT_SETTINGS.dataFilePath;
this.settings.dataFileNamePath = DEFAULT_SETTINGS.dataFileNamePath;
this.settings.statusBar = DEFAULT_SETTINGS.statusBar;
this.settings.debugMode = DEFAULT_SETTINGS.debugMode;
this.settings.cacheImage = DEFAULT_SETTINGS.cacheImage;
this.settings.cacheHighQuantityImage = DEFAULT_SETTINGS.cacheHighQuantityImage;
}
clearLoginInfo() {
this.settings.loginCookiesContent = DEFAULT_SETTINGS.loginHeadersContent;
this.settings.loginHeadersContent = DEFAULT_SETTINGS.loginHeadersContent;
}
clearSyncCache() {
this.settings.syncHandledDataArray = [];
}
}

@ -42,6 +42,8 @@ PS: This file could be delete if you want to.
'110050': `Type`,
'110051': `Number`,
'110052': `Description`,
'110152': `Confirm`,
'exists':`[exists]`,
'unHandle':`[unHandle]`,
@ -227,6 +229,7 @@ PS: This file could be delete if you want to.
'121601': `Note Name`,
'121602': `Nodes created from Obsidian-Douban will use this fileName as template(also support filePath),
If blank, they will be created by default name. support all basic template variables. example: {{type}}/{{title}}`,
'121604': `Note Path Previous`,
'120603': `Display Preview`,
'120604': `ArrayTypeName:`,
'120605': `Template use example propertyName:{{actor`,
@ -251,6 +254,17 @@ PS: This file could be delete if you want to.
'125001': `Debug Mode`,
'125002': `Open Debug Mode, so that this plugin will log some message in console`,
'125011': `Reset Setting`,
'125012': `Reset Setting to default value, but not include \`Custom Variables\``,
'125013': `Reset Setting to default value`,
'125021': `Clear Login Cache`,
'125022': `Clear Login Info, so that you can login again`,
'125031': `Clear Sync Cache`,
'125032': `Clear Sync Cache, It will clear all the sync data, so that you can sync again`,
'125033': `Are you sure you want to perform this operation?`,
//error
'130101': `Fetch Data Error, {0}`,

@ -24,6 +24,8 @@ export default {
'110034': `输出文件夹:`,
'110035': `文档名: (提示:支持参数化以及多级路径, 可用参数见配置界面)`,
'110036': `完成`,
'110152': `确认`,
'110037': `
###
{0}
@ -117,7 +119,16 @@ export default {
'125001': `调试模式`,
'125002': `调试模式开启后,将会在控制台打印此插件的日志信息`,
'125011': `重置设置为默认`,
'125012': `将设置重置为默认值,但不会清除登录信息,也不会清除自定义参数`,
'125021': `清除登录缓存`,
'125022': `清除登录信息,如果你遇到登录问题,可以尝试清除登录缓存,点击按钮将清除所有登录缓存数据`,
'125031': `清除同步缓存`,
'125032': `清除同步缓存,点击按钮将清除所有同步缓存数据(但不会清除已同步的文档)`,
'125033': `确认要执行此操作吗?`,
'124101': `新增`,
@ -236,7 +247,7 @@ export default {
'121601': `笔记名称`,
'121602': `创建的笔记将会使用此名称作为模板, 支持所有'通用'的参数作为名称(如:{{type}}/{{title}}), 且支持路径, 比如: 'MyData/{{title}}'. 如果为空, 笔记将会使用默认名称. `,
'121604': `文件路径预览`,
'120603': `输出效果预览`,
'120604': `数组类型名称:`,
'120605': `模板中使用举例: propertyName:{{actor`,

@ -44,6 +44,7 @@ export default class DoubanPlugin extends Plugin {
public netFileHandler: NetFileHandler;
public statusHolder: GlobalStatusHolder;
public onlineData: DoubanPluginOnlineData;
public settingTab: DoubanSettingTab;
async putToObsidian(context: HandleContext, extract: DoubanSubject) {
@ -231,8 +232,8 @@ export default class DoubanPlugin extends Plugin {
log.debug(i18nHelper.getMessage('100101'));
}
}
this.addSettingTab(new DoubanSettingTab(this.app, this));
this.settingTab = new DoubanSettingTab(this.app, this);
this.addSettingTab(this.settingTab);
this.statusHolder = new GlobalStatusHolder(this.app, this);
}

@ -44,6 +44,7 @@
"1.9.6": "0.12.0",
"1.9.7": "0.12.0",
"1.9.8": "0.12.0",
"1.9.9": "0.12.0"
"1.9.9": "0.12.0",
"2.0.0": "0.12.0"
}