diff --git a/src/org/wanxp/constant/Constsant.ts b/src/org/wanxp/constant/Constsant.ts index 35fceda..0d83d0b 100644 --- a/src/org/wanxp/constant/Constsant.ts +++ b/src/org/wanxp/constant/Constsant.ts @@ -101,15 +101,34 @@ export enum TemplateKey { } export enum SupportType { - ALL = "all", - MOVIE = 'movie', - BOOK = 'book', - MUSIC = 'music', - NOTE = 'note', - GAME = 'game', - TELEPLAY = 'teleplay', - THEATER = 'theater', + all = "all", + movie = 'movie', + book = 'book', + music = 'music', + note = 'note', + game = 'game', + teleplay = 'teleplay', + theater = 'theater', } +export const SupportTypeMap:object = { + "all": SupportType.all, + "movie": SupportType.movie, + "book": SupportType.book, + "music": SupportType.music, + "note": SupportType.note, + "game": SupportType.game, + "teleplay": SupportType.teleplay, + "theater": SupportType.theater, + "ALL": SupportType.all, + "MOVIE": SupportType.movie, + "BOOK": SupportType.book, + "MUSIC": SupportType.music, + "NOTE": SupportType.note, + "GAME": SupportType.game, + "TELEPLAY": SupportType.teleplay, + "THEATER": SupportType.theater, +} + export enum PropertyName { //base @@ -183,12 +202,12 @@ export enum PropertyName { */ // @ts-ignore export const SearchTypeRecords: { [key in SupportType]: string } = { - [SupportType.ALL]: i18nHelper.getMessage('ALL'), - [SupportType.MOVIE]: i18nHelper.getMessage('MOVIE_AND_TELEPLAY'), - [SupportType.BOOK]: i18nHelper.getMessage('BOOK'), - [SupportType.MUSIC]: i18nHelper.getMessage('MUSIC'), - [SupportType.NOTE]: i18nHelper.getMessage('NOTE'), - [SupportType.GAME]: i18nHelper.getMessage('GAME'), + [SupportType.all]: i18nHelper.getMessage('ALL'), + [SupportType.movie]: i18nHelper.getMessage('MOVIE_AND_TELEPLAY'), + [SupportType.book]: i18nHelper.getMessage('BOOK'), + [SupportType.music]: i18nHelper.getMessage('MUSIC'), + [SupportType.note]: i18nHelper.getMessage('NOTE'), + [SupportType.game]: i18nHelper.getMessage('GAME'), // [SupportType.THEATER]: i18nHelper.getMessage('THEATER'), } @@ -233,7 +252,7 @@ export const SyncTypeRecords: { [key in SyncType | string]: string } = { // [SyncType.broadcast]: i18nHelper.getMessage('504104'), // [SyncType.note]: i18nHelper.getMessage('504105'), [SyncType.music]: i18nHelper.getMessage('504106'), - // [SyncType.game]: i18nHelper.getMessage('504108'), + [SyncType.game]: i18nHelper.getMessage('504108'), } /** @@ -376,13 +395,13 @@ sec-ch-ua-platform: "Windows" export const ONLINE_SETTING_DEFAULT: DoubanPluginOnlineSettings = { properties: [ { - type: SupportType.BOOK, + type: SupportType.book, name: PropertyName.comment, selectors: ['#interest_sect_level > div > span:nth-child(7)' ] }, { - type: SupportType.MOVIE, + type: SupportType.movie, name: PropertyName.comment, selectors: ['#interest_sect_level > div > span:nth-child(8)', '#interest_sect_level > div > span:nth-child(7)', @@ -497,4 +516,35 @@ export const SyncConditionTypeRecords: { [key in SyncConditionType|string]: stri [SyncConditionType.CUSTOM_ITEM]: i18nHelper.getMessage('110076'), [SyncConditionType.CUSTOM_TIME]: i18nHelper.getMessage('110074'), -} \ No newline at end of file +} + + +export const DoubanSearchResultSubject_EMPTY: DoubanSearchResultSubject = { + id: '', + title: i18nHelper.getMessage('150107'), + score: null, + cast: '', + type: 'navigate', + desc: '-', + url: 'https://www.douban.com', + image: "", + imageUrl: "", + publisher: "", + datePublished: undefined, + genre: [] +}; + +export const DoubanSearchResultSubject_TIP_EMPTY: DoubanSearchResultSubject = { + id: '', + title: i18nHelper.getMessage('150108'), + score: null, + cast: '', + type: 'navigate', + desc: '-', + url: 'https://www.douban.com', + image: "", + imageUrl: "", + publisher: "", + datePublished: undefined, + genre: [] +}; \ No newline at end of file diff --git a/src/org/wanxp/constant/DefaultSettings.ts b/src/org/wanxp/constant/DefaultSettings.ts index e84eaa4..36a3fe7 100644 --- a/src/org/wanxp/constant/DefaultSettings.ts +++ b/src/org/wanxp/constant/DefaultSettings.ts @@ -38,12 +38,12 @@ export const DEFAULT_SETTINGS: DoubanPluginSetting = { statusBar: true, debugMode: false, customProperties: [ - {name: 'myType', value: 'movie', field: SupportType.MOVIE}, - {name: 'myType', value: 'book', field: SupportType.BOOK}, - {name: 'myType', value: 'music', field: SupportType.MUSIC}, - {name: 'myType', value: 'note', field: SupportType.NOTE}, - {name: 'myType', value: 'game', field: SupportType.GAME}, - {name: 'myType', value: 'teleplay', field: SupportType.TELEPLAY}, + {name: 'myType', value: 'movie', field: SupportType.movie}, + {name: 'myType', value: 'book', field: SupportType.book}, + {name: 'myType', value: 'music', field: SupportType.music}, + {name: 'myType', value: 'note', field: SupportType.note}, + {name: 'myType', value: 'game', field: SupportType.game}, + {name: 'myType', value: 'teleplay', field: SupportType.teleplay}, ], loginCookiesContent: '', loginHeadersContent: '', @@ -57,7 +57,8 @@ export const DEFAULT_SETTINGS: DoubanPluginSetting = { starEmpty: '☆', displayStarEmpty: false, maxStar: 5, - } + }, + searchDefaultType: SupportType.all, } diff --git a/src/org/wanxp/constant/DoubanUserState.ts b/src/org/wanxp/constant/DoubanUserState.ts index a8d7ba9..f0b7675 100644 --- a/src/org/wanxp/constant/DoubanUserState.ts +++ b/src/org/wanxp/constant/DoubanUserState.ts @@ -66,14 +66,14 @@ export const DoubanSubjectStateRecords_THEATER: { [key in DoubanSubjectState]: s } export const DoubanSubjectStateRecords: { [key in SupportType]: Record } = { - [SupportType.ALL]:DoubanSubjectStateRecords_ALL, - [SupportType.MOVIE]:DoubanSubjectStateRecords_MOVIE, - [SupportType.BOOK]:DoubanSubjectStateRecords_BOOK, - [SupportType.MUSIC]:DoubanSubjectStateRecords_MUSIC, - [SupportType.NOTE]:DoubanSubjectStateRecords_NOTE, - [SupportType.GAME]:DoubanSubjectStateRecords_GAME, - [SupportType.TELEPLAY]:DoubanSubjectStateRecords_TELEPLAY, - [SupportType.THEATER]:DoubanSubjectStateRecords_THEATER, + [SupportType.all]:DoubanSubjectStateRecords_ALL, + [SupportType.movie]:DoubanSubjectStateRecords_MOVIE, + [SupportType.book]:DoubanSubjectStateRecords_BOOK, + [SupportType.music]:DoubanSubjectStateRecords_MUSIC, + [SupportType.note]:DoubanSubjectStateRecords_NOTE, + [SupportType.game]:DoubanSubjectStateRecords_GAME, + [SupportType.teleplay]:DoubanSubjectStateRecords_TELEPLAY, + [SupportType.theater]:DoubanSubjectStateRecords_THEATER, } @@ -109,7 +109,7 @@ export const DoubanSubjectStateRecords_BOOK_SYNC: { [key in DoubanSubjectState]: // @ts-ignore export const DoubanSubjectStateRecords_GAME_SYNC: { [key in DoubanSubjectState]: string } = { // @ts-ignore - [ALL]: i18nHelper.getMessage('500004'), + // [ALL]: i18nHelper.getMessage('500004'), [DoubanSubjectState.wish]: i18nHelper.getMessage('500602'), [DoubanSubjectState.do]: i18nHelper.getMessage('500603'), [DoubanSubjectState.collect]: i18nHelper.getMessage('500604'), @@ -146,32 +146,32 @@ export const DoubanSubjectStateRecords_SYNC: { [key in SyncType]: Record = new Map ( - [['我看过这部电视剧', SupportType.TELEPLAY], - ['我最近看过这部电视剧', SupportType.TELEPLAY], - ['我想看这部电视剧', SupportType.TELEPLAY], - ['我在看这部电视剧', SupportType.TELEPLAY], - ['我最近在看这部电视剧', SupportType.TELEPLAY], + [['我看过这部电视剧', SupportType.teleplay], + ['我最近看过这部电视剧', SupportType.teleplay], + ['我想看这部电视剧', SupportType.teleplay], + ['我在看这部电视剧', SupportType.teleplay], + ['我最近在看这部电视剧', SupportType.teleplay], - ['我最近看过这部电影', SupportType.MOVIE], - ['我看过这部电影', SupportType.MOVIE], - ['我想看这部电影', SupportType.MOVIE], + ['我最近看过这部电影', SupportType.movie], + ['我看过这部电影', SupportType.movie], + ['我想看这部电影', SupportType.movie], - ['我读过这本书', SupportType.BOOK], - ['我想读这本书', SupportType.BOOK], - ['我在读这本书', SupportType.BOOK], - ['我最近在读这本书', SupportType.BOOK], + ['我读过这本书', SupportType.book], + ['我想读这本书', SupportType.book], + ['我在读这本书', SupportType.book], + ['我最近在读这本书', SupportType.book], - ['我最近听过这张唱片', SupportType.MUSIC], - ['我听过这张唱片', SupportType.MUSIC], - ['我想听这张唱片', SupportType.MUSIC], - ['我在听这张唱片', SupportType.MUSIC], - ['我最近在听这张唱片', SupportType.MUSIC], + ['我最近听过这张唱片', SupportType.music], + ['我听过这张唱片', SupportType.music], + ['我想听这张唱片', SupportType.music], + ['我在听这张唱片', SupportType.music], + ['我最近在听这张唱片', SupportType.music], - ['我最近玩过这个游戏', SupportType.GAME], - ['我玩过这个游戏', SupportType.GAME], - ['我想玩这个游戏', SupportType.GAME], - ['我在玩这个游戏', SupportType.GAME], - ['我最近在玩这个游戏', SupportType.GAME],] + ['我最近玩过这个游戏', SupportType.game], + ['我玩过这个游戏', SupportType.game], + ['我想玩这个游戏', SupportType.game], + ['我在玩这个游戏', SupportType.game], + ['我最近在玩这个游戏', SupportType.game],] ) diff --git a/src/org/wanxp/douban/component/DoubanSyncModal.ts b/src/org/wanxp/douban/component/DoubanSyncModal.ts index 37e9d73..5c9de39 100644 --- a/src/org/wanxp/douban/component/DoubanSyncModal.ts +++ b/src/org/wanxp/douban/component/DoubanSyncModal.ts @@ -235,6 +235,7 @@ ${syncStatus.getHandle() == 0? '...' : i18nHelper.getMessage('110042') + ':' + T this.showScopeDropdown(contentEl, DoubanSubjectStateRecords_TELEPLAY_SYNC, config, disable); break; case SyncType.game: + config.scope = DoubanSubjectState.collect; this.showScopeDropdown(contentEl, DoubanSubjectStateRecords_GAME_SYNC, config, disable); break; } diff --git a/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts b/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts index 6f0ca6d..9c0f7b5 100644 --- a/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts +++ b/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts @@ -389,22 +389,22 @@ export default abstract class DoubanAbstractLoadHandler private getTemplateKey():TemplateKey { let templateKey: TemplateKey; switch (this.getSupportType()) { - case SupportType.MOVIE: + case SupportType.movie: templateKey = TemplateKey.movieTemplateFile; break; - case SupportType.BOOK: + case SupportType.book: templateKey = TemplateKey.bookTemplateFile; break; - case SupportType.MUSIC: + case SupportType.music: templateKey = TemplateKey.musicTemplateFile; break; - case SupportType.TELEPLAY: + case SupportType.teleplay: templateKey = TemplateKey.teleplayTemplateFile; break; - case SupportType.GAME: + case SupportType.game: templateKey = TemplateKey.gameTemplateFile; break; - case SupportType.NOTE: + case SupportType.note: templateKey = TemplateKey.noteTemplateFile; break; default: diff --git a/src/org/wanxp/douban/data/handler/DoubanBookLoadHandler.ts b/src/org/wanxp/douban/data/handler/DoubanBookLoadHandler.ts index 60f8f37..2c376aa 100644 --- a/src/org/wanxp/douban/data/handler/DoubanBookLoadHandler.ts +++ b/src/org/wanxp/douban/data/handler/DoubanBookLoadHandler.ts @@ -17,7 +17,7 @@ export default class DoubanBookLoadHandler extends DoubanAbstractLoadHandler { - getSupportType(): SupportType.ALL { - return SupportType.ALL; + getSupportType(): SupportType.all { + return SupportType.all; } parseVariable(beforeContent: string, variableMap:Map, extract: DoubanSubject, context: HandleContext): void { diff --git a/src/org/wanxp/douban/data/handler/DoubanTeleplayLoadHandler.ts b/src/org/wanxp/douban/data/handler/DoubanTeleplayLoadHandler.ts index f6229ad..32227f7 100644 --- a/src/org/wanxp/douban/data/handler/DoubanTeleplayLoadHandler.ts +++ b/src/org/wanxp/douban/data/handler/DoubanTeleplayLoadHandler.ts @@ -21,7 +21,7 @@ export class DoubanTeleplayLoadHandler extends DoubanAbstractLoadHandler, extract: DoubanTeleplaySubject, context: HandleContext): void { diff --git a/src/org/wanxp/douban/data/handler/DoubanTheaterLoadHandler.ts b/src/org/wanxp/douban/data/handler/DoubanTheaterLoadHandler.ts index faa3cef..d88fa71 100644 --- a/src/org/wanxp/douban/data/handler/DoubanTheaterLoadHandler.ts +++ b/src/org/wanxp/douban/data/handler/DoubanTheaterLoadHandler.ts @@ -17,7 +17,7 @@ export default class DoubanTheaterLoadHandler extends DoubanAbstractLoadHandler< } getSupportType(): SupportType { - return SupportType.THEATER; + return SupportType.theater; } getHighQuantityImageUrl(fileName: string): string { diff --git a/src/org/wanxp/douban/data/model/SearchPage.ts b/src/org/wanxp/douban/data/model/SearchPage.ts index 6a27f6f..164ed0f 100644 --- a/src/org/wanxp/douban/data/model/SearchPage.ts +++ b/src/org/wanxp/douban/data/model/SearchPage.ts @@ -5,10 +5,10 @@ import {SearchPageTypeOf} from "./SearchPageTypeOf"; export class SearchPage extends SearchPageTypeOf { public static empty(type: SupportType): SearchPage { - return new SearchPage(0, 0, 0, type, []); + return new SearchPage(0, 1, 0, type, []); } static emptyWithNoType() { - return new SearchPage(0, 0, 0, null, []); + return new SearchPage(0, 1, 0, null, []); } } diff --git a/src/org/wanxp/douban/data/model/SearchPageInfo.ts b/src/org/wanxp/douban/data/model/SearchPageInfo.ts index 9a1dd8a..2a1e154 100644 --- a/src/org/wanxp/douban/data/model/SearchPageInfo.ts +++ b/src/org/wanxp/douban/data/model/SearchPageInfo.ts @@ -77,7 +77,7 @@ export class SearchPageInfo { return this; } return new SearchPageInfo(this.total, this._pageNum - 1, - this._pageSize, SupportType.ALL); + this._pageSize, SupportType.all); } diff --git a/src/org/wanxp/douban/data/model/SearchPageTypeOf.ts b/src/org/wanxp/douban/data/model/SearchPageTypeOf.ts index 3d3391b..2026aa4 100644 --- a/src/org/wanxp/douban/data/model/SearchPageTypeOf.ts +++ b/src/org/wanxp/douban/data/model/SearchPageTypeOf.ts @@ -20,10 +20,10 @@ export class SearchPageTypeOf extends SearchPageInfo { } public static empty(type: SupportType): SearchPageTypeOf { - return new SearchPageTypeOf(0, 0, 0, type, []); + return new SearchPageTypeOf(0, 1, 0, type, []); } static emptyWithNoType() { - return new SearchPageTypeOf(0, 0, 0, null, []); + return new SearchPageTypeOf(0, 1, 0, null, []); } } diff --git a/src/org/wanxp/douban/data/search/DoubanSearchFuzzySuggestModal.ts b/src/org/wanxp/douban/data/search/DoubanSearchFuzzySuggestModal.ts index ca43f15..0b8626e 100644 --- a/src/org/wanxp/douban/data/search/DoubanSearchFuzzySuggestModal.ts +++ b/src/org/wanxp/douban/data/search/DoubanSearchFuzzySuggestModal.ts @@ -1,9 +1,13 @@ import { - DoubanSearchGroupPublishResultSubjectNextPage, DoubanSearchGroupPublishResultSubjectPreviousPage, + DoubanSearchGroupPublishResultSubjectNextPage, + DoubanSearchGroupPublishResultSubjectPreviousPage, + DoubanSearchResultSubject_EMPTY, DoubanSearchResultSubject_TIP_EMPTY, DoubanSearchResultSubjectNextPage, DoubanSearchResultSubjectNextPageNeedLogin, DoubanSearchResultSubjectPreviousPage, - NavigateType, SEARCH_ITEM_PAGE_SIZE, SupportType + NavigateType, + SEARCH_ITEM_PAGE_SIZE, + SupportType } from "../../../constant/Constsant"; import {FuzzySuggestModal, RequestUrlParam, request} from "obsidian"; @@ -106,9 +110,18 @@ class DoubanFuzzySuggester extends FuzzySuggestModal private initItems(searchPage: SearchPage) { const doubanList: DoubanSearchResultSubject[] = searchPage.list; + + if (searchPage.type == SupportType.all && searchPage.pageNum == 1) { + if (doubanList.length == 0) { + // if (searchPage.list.length > 0) { + doubanList.push(DoubanSearchResultSubject_EMPTY); + }else if (searchPage.list.length < SEARCH_ITEM_PAGE_SIZE) { + doubanList.push(DoubanSearchResultSubject_TIP_EMPTY); + } + } if (searchPage.hasNext) { if (this.plugin.userComponent.isLogin()) { - if (searchPage.type == SupportType.ALL && searchPage.pageNum == 1) { + if (searchPage.type == SupportType.all && searchPage.pageNum == 1) { doubanList.push(DoubanSearchGroupPublishResultSubjectNextPage) }else { doubanList.push(DoubanSearchResultSubjectNextPage) @@ -118,7 +131,7 @@ class DoubanFuzzySuggester extends FuzzySuggestModal } } if (searchPage.hasPrevious) { - if (searchPage.type == SupportType.ALL && searchPage.pageNum == 2) { + if (searchPage.type == SupportType.all && searchPage.pageNum == 2) { doubanList.unshift(DoubanSearchGroupPublishResultSubjectPreviousPage) }else { doubanList.unshift(DoubanSearchResultSubjectPreviousPage); diff --git a/src/org/wanxp/douban/data/search/DoubanSearchModal.ts b/src/org/wanxp/douban/data/search/DoubanSearchModal.ts index 4990606..58edc6d 100644 --- a/src/org/wanxp/douban/data/search/DoubanSearchModal.ts +++ b/src/org/wanxp/douban/data/search/DoubanSearchModal.ts @@ -8,16 +8,19 @@ import {sleep} from "../../../utils/TimeUtil"; export class DoubanSearchModal extends Modal { searchTerm: string; - searchType: SupportType = SupportType.ALL; + searchType: SupportType = SupportType.all; plugin: DoubanPlugin; context: HandleContext - constructor(app: App, plugin: DoubanPlugin, context: HandleContext) { + constructor(app: App, plugin: DoubanPlugin, context: HandleContext, type: SupportType) { super(app); this.plugin = plugin; this.context = context; + this.searchType = type??SupportType.all; } + + onOpen() { let {contentEl} = this; @@ -42,7 +45,7 @@ export class DoubanSearchModal extends Modal { const typeSelect = content.createDiv("type-select"); const typeSelectInput = new DropdownComponent(typeSelect) .addOptions(SearchTypeRecords) - .setValue(SupportType.ALL) + .setValue(this.searchType) .onChange((value:SupportType) => { this.searchType = value; }); diff --git a/src/org/wanxp/douban/data/search/parser/AllFirstPageSearchResultPageParser.ts b/src/org/wanxp/douban/data/search/parser/AllFirstPageSearchResultPageParser.ts index a925f74..2d9fd6e 100644 --- a/src/org/wanxp/douban/data/search/parser/AllFirstPageSearchResultPageParser.ts +++ b/src/org/wanxp/douban/data/search/parser/AllFirstPageSearchResultPageParser.ts @@ -1,4 +1,6 @@ -import {SupportType} from "../../../../constant/Constsant"; +import { + SupportType +} from "../../../../constant/Constsant"; import {SearchResultPageParserInterface} from "./SearchResultPageParserInterface"; import {SearchPage} from "../../model/SearchPage"; import SearchParserHandlerV2 from "../SearchParserV2"; @@ -7,7 +9,7 @@ import {log} from "../../../../utils/Logutil"; export class AllFirstPageSearchResultPageParser implements SearchResultPageParserInterface { support(type:SupportType, pageNum:number):boolean { - return pageNum == 1 && type == SupportType.ALL; + return pageNum == 1 && type == SupportType.all; } parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage { if (!source || StringUtil.notJsonString(source)) { diff --git a/src/org/wanxp/douban/data/search/parser/NotAllPageSearchResultPageParser.ts b/src/org/wanxp/douban/data/search/parser/NotAllPageSearchResultPageParser.ts index 8b13a33..3cae666 100644 --- a/src/org/wanxp/douban/data/search/parser/NotAllPageSearchResultPageParser.ts +++ b/src/org/wanxp/douban/data/search/parser/NotAllPageSearchResultPageParser.ts @@ -6,7 +6,7 @@ import SearchParserHandler from "../SearchParser"; export class NotAllPageSearchResultPageParser implements SearchResultPageParserInterface { support(type:SupportType, pageNum:number):boolean { - return type != SupportType.ALL && !(pageNum ==1 && type == SupportType.NOTE); + return type != SupportType.all && !(pageNum ==1 && type == SupportType.note); } parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage { log.debug("解析给多页面结果"); diff --git a/src/org/wanxp/douban/data/search/parser/NoteFirstPageSearchResultPageParser.ts b/src/org/wanxp/douban/data/search/parser/NoteFirstPageSearchResultPageParser.ts index 61cd897..184c9a1 100644 --- a/src/org/wanxp/douban/data/search/parser/NoteFirstPageSearchResultPageParser.ts +++ b/src/org/wanxp/douban/data/search/parser/NoteFirstPageSearchResultPageParser.ts @@ -7,7 +7,7 @@ import DoubanSearchResultSubject from "../../model/DoubanSearchResultSubject"; export class NoteFirstPageSearchResultPageParser implements SearchResultPageParserInterface { support(type:SupportType, pageNum:number):boolean { - return pageNum == 1 && type == SupportType.NOTE; + return pageNum == 1 && type == SupportType.note; } parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage { const pageData = load(source); diff --git a/src/org/wanxp/douban/data/search/parser/OtherAllPageSearchResultPageParser.ts b/src/org/wanxp/douban/data/search/parser/OtherAllPageSearchResultPageParser.ts index a40a883..4a6970a 100644 --- a/src/org/wanxp/douban/data/search/parser/OtherAllPageSearchResultPageParser.ts +++ b/src/org/wanxp/douban/data/search/parser/OtherAllPageSearchResultPageParser.ts @@ -6,7 +6,7 @@ import SearchParserHandlerV2 from "../SearchParserV2"; export class OtherAllPageSearchResultPageParser implements SearchResultPageParserInterface { support(type:SupportType, pageNum:number):boolean { - return pageNum > 1 && type == SupportType.ALL; + return pageNum > 1 && type == SupportType.all; } parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage { log.debug("解析给多页面结果"); diff --git a/src/org/wanxp/douban/data/search/searcher/AbstractSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/AbstractSearchPageFetcher.ts index cceebdb..b7c0577 100644 --- a/src/org/wanxp/douban/data/search/searcher/AbstractSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/AbstractSearchPageFetcher.ts @@ -17,8 +17,9 @@ export abstract class AbstractSearchPageFetcher implements SearchPageFetcherInte support(type: SupportType, pageNum?:number): boolean { throw new Error("Method not implemented."); - } - fetch(keyword: string, pageNum: number, pageSize: number): Promise { + } + + fetch(keyword: string, pageNum: number, pageSize: number): Promise { const start:number = Math.floor((pageNum - 1) * pageSize); const url:string = this.getSearchUrl(keyword, start, pageSize); if (!url) { @@ -27,7 +28,8 @@ export abstract class AbstractSearchPageFetcher implements SearchPageFetcherInte return DoubanHttpUtil.httpRequestGet(url, this.settingsManager.getHeaders(), this.settingsManager) .catch(e => { throw log.error(i18nHelper.getMessage('130101').replace('{0}', e.toString()), e); - }); } + }); + } getSearchUrl(keyword: string, start: number, pageSize: number):string { keyword = keyword.trim(); diff --git a/src/org/wanxp/douban/data/search/searcher/AllPageSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/AllPageSearchPageFetcher.ts index 81df3ac..66dfe89 100644 --- a/src/org/wanxp/douban/data/search/searcher/AllPageSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/AllPageSearchPageFetcher.ts @@ -6,7 +6,7 @@ export class AllPageSearchPageFetcher extends AbstractSearchPageFetcher { return `https://m.douban.com/rexxar/api/v2/search?q=${keyword}&start=${pageNum}&count=${pageSize}`; } support(type: SupportType): boolean { - return type == SupportType.ALL; + return type == SupportType.all; } diff --git a/src/org/wanxp/douban/data/search/searcher/BookPageSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/BookPageSearchPageFetcher.ts index 8da1fbe..991a0c6 100644 --- a/src/org/wanxp/douban/data/search/searcher/BookPageSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/BookPageSearchPageFetcher.ts @@ -6,7 +6,7 @@ export class BookPageSearchPageFetcher extends AbstractSearchPageFetcher { return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=1001`; } support(type: SupportType): boolean { - return type == SupportType.BOOK; + return type == SupportType.book; } diff --git a/src/org/wanxp/douban/data/search/searcher/GamePageSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/GamePageSearchPageFetcher.ts index 882f097..748e11b 100644 --- a/src/org/wanxp/douban/data/search/searcher/GamePageSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/GamePageSearchPageFetcher.ts @@ -6,7 +6,7 @@ export class GamePageSearchPageFetcher extends AbstractSearchPageFetcher { return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=3114`; } support(type: SupportType): boolean { - return type == SupportType.GAME; + return type == SupportType.game; } diff --git a/src/org/wanxp/douban/data/search/searcher/MoviePageSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/MoviePageSearchPageFetcher.ts index ee6f93c..210fe4a 100644 --- a/src/org/wanxp/douban/data/search/searcher/MoviePageSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/MoviePageSearchPageFetcher.ts @@ -6,7 +6,7 @@ export class MoviePageSearchPageFetcher extends AbstractSearchPageFetcher { return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=1002`; } support(type: SupportType): boolean { - return type == SupportType.MOVIE; + return type == SupportType.movie; } diff --git a/src/org/wanxp/douban/data/search/searcher/MusicPageSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/MusicPageSearchPageFetcher.ts index 40a981b..5400e76 100644 --- a/src/org/wanxp/douban/data/search/searcher/MusicPageSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/MusicPageSearchPageFetcher.ts @@ -6,7 +6,7 @@ export class MusicPageSearchPageFetcher extends AbstractSearchPageFetcher { return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=1003`; } support(type: SupportType): boolean { - return type == SupportType.MUSIC; + return type == SupportType.music; } diff --git a/src/org/wanxp/douban/data/search/searcher/NoteFirstPageSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/NoteFirstPageSearchPageFetcher.ts index 210de87..d088550 100644 --- a/src/org/wanxp/douban/data/search/searcher/NoteFirstPageSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/NoteFirstPageSearchPageFetcher.ts @@ -6,7 +6,7 @@ export class NoteFirstPageSearchPageFetcher extends AbstractSearchPageFetcher { return `https://www.douban.com/search?cat=1015&q=${keyword}`; } support(type: SupportType, pageNum:number): boolean { - return type == SupportType.NOTE && pageNum == 1; + return type == SupportType.note && pageNum == 1; } diff --git a/src/org/wanxp/douban/data/search/searcher/NotePageSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/NotePageSearchPageFetcher.ts index a3abbaa..98d5788 100644 --- a/src/org/wanxp/douban/data/search/searcher/NotePageSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/NotePageSearchPageFetcher.ts @@ -6,7 +6,7 @@ export class NotePageSearchPageFetcher extends AbstractSearchPageFetcher { return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=1015`; } support(type: SupportType, pageNum:number): boolean { - return type == SupportType.NOTE && pageNum > 1; + return type == SupportType.note && pageNum > 1; } diff --git a/src/org/wanxp/douban/data/search/searcher/TheaterPageSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/TheaterPageSearchPageFetcher.ts index 3e863a8..5dfa559 100644 --- a/src/org/wanxp/douban/data/search/searcher/TheaterPageSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/TheaterPageSearchPageFetcher.ts @@ -6,7 +6,7 @@ export class TheaterPageSearchPageFetcher extends AbstractSearchPageFetcher { return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=3069`; } support(type: SupportType): boolean { - return type == SupportType.THEATER; + return type == SupportType.theater; } diff --git a/src/org/wanxp/douban/setting/BasicSettingsHelper.ts b/src/org/wanxp/douban/setting/BasicSettingsHelper.ts index 14946b2..d4cf1bd 100644 --- a/src/org/wanxp/douban/setting/BasicSettingsHelper.ts +++ b/src/org/wanxp/douban/setting/BasicSettingsHelper.ts @@ -9,6 +9,7 @@ import {createFolderSelectionSetting} from "./TemplateSettingHelper"; import StringUtil from "../../utils/StringUtil"; import {log} from "../../utils/Logutil"; import DoubanPlugin from "../../main"; +import {SearchTypeRecords, SupportType, SupportTypeMap} from "../../constant/Constsant"; export function constructBasicUI(containerEl: HTMLElement, manager: SettingsManager) { // containerEl.createEl('h3', { text: i18nHelper.getMessage('1210') }); @@ -97,6 +98,19 @@ export function constructBasicUI(containerEl: HTMLElement, manager: SettingsMana }); }); + new Setting(containerEl) + .setName(i18nHelper.getMessage('121410')) + .setDesc(i18nHelper.getMessage('121411')) + .addDropdown((dropdown) => { + dropdown + .addOptions(SearchTypeRecords) + .setValue(manager.plugin.settings.searchDefaultType) + .onChange(async (value) => { + // @ts-ignore + manager.plugin.settings.searchDefaultType = SupportTypeMap[value]; + await manager.plugin.saveSettings(); + }); + }); } diff --git a/src/org/wanxp/douban/setting/CustomPropertySettingsHelper.ts b/src/org/wanxp/douban/setting/CustomPropertySettingsHelper.ts index 7acaaab..e91a315 100644 --- a/src/org/wanxp/douban/setting/CustomPropertySettingsHelper.ts +++ b/src/org/wanxp/douban/setting/CustomPropertySettingsHelper.ts @@ -2,7 +2,7 @@ import {i18nHelper} from "../../lang/helper"; import SettingsManager from "./SettingsManager"; import {CustomProperty} from "./model/CustomProperty"; import {ButtonComponent, DropdownComponent, ExtraButtonComponent, Setting, TextComponent} from "obsidian"; -import {SupportType} from "../../constant/Constsant"; +import {SupportType, SupportTypeMap} from "../../constant/Constsant"; import DoubanPlugin from "../../main"; export function constructCustomPropertySettingsUI(containerEl: HTMLElement, manager: SettingsManager) { @@ -16,7 +16,7 @@ export function constructCustomPropertySettingsUI(containerEl: HTMLElement, mana button.setTooltip(i18nHelper.getMessage('124101')); button.setIcon('plus'); button.onClick(async () => { - customProperties.push({name: '', value: '', field: SupportType.ALL}); + customProperties.push({name: '', value: '', field: SupportType.all}); constructCustomPropertyUI(list, customProperties, manager); }); }); @@ -68,11 +68,15 @@ function addFilterInput(data: CustomProperty, el: HTMLElement, customProperties: const fieldsDropdown = new DropdownComponent(el); for (const fieldSelect in SupportType) { - // @ts-ignore fieldsDropdown.addOption(fieldSelect, i18nHelper.getMessage(fieldSelect)); } item.createEl('span', { text: i18nHelper.getMessage('124106') }); - fieldsDropdown.setValue(data.field) + let dataFieldValue = data.field; + if(typeof dataFieldValue === 'string') { + // @ts-ignore + dataFieldValue = SupportTypeMap[dataFieldValue]; + } + fieldsDropdown.setValue(dataFieldValue) .onChange(async (value: SupportType) => { customProperties[idx].field = value; await manager.plugin.saveSettings(); diff --git a/src/org/wanxp/douban/setting/OutputSettingsHelper.ts b/src/org/wanxp/douban/setting/OutputSettingsHelper.ts index 7d5e4c5..720e3d7 100644 --- a/src/org/wanxp/douban/setting/OutputSettingsHelper.ts +++ b/src/org/wanxp/douban/setting/OutputSettingsHelper.ts @@ -33,7 +33,7 @@ export function showFileExample(containerEl: HTMLElement, manager: SettingsManag const document = new DocumentFragment(); document.createDiv('file-path-example') .innerHTML = `${i18nHelper.getMessage('121604')}《简爱》: ${VariableUtil.replaceSubject(EXAMPLE_SUBJECT_MAP, - FileUtil.join(manager.plugin.settings.dataFilePath, manager.plugin.settings.dataFileNamePath + ".md"), SupportType.BOOK, + FileUtil.join(manager.plugin.settings.dataFilePath, manager.plugin.settings.dataFileNamePath + ".md"), SupportType.book, manager)}`; new Setting(containerEl) diff --git a/src/org/wanxp/douban/setting/model/DoubanPluginSetting.ts b/src/org/wanxp/douban/setting/model/DoubanPluginSetting.ts index 90cde78..142a96b 100644 --- a/src/org/wanxp/douban/setting/model/DoubanPluginSetting.ts +++ b/src/org/wanxp/douban/setting/model/DoubanPluginSetting.ts @@ -3,6 +3,7 @@ import {SyncHandledData} from "./SyncHandledData"; import {ArraySetting} from "./ArraySetting"; import {ScoreSetting} from "./ScoreSetting"; import PictureBedSetting from "./PictureBedSetting"; +import {SupportType} from "../../../constant/Constsant"; export interface DoubanPluginSetting { onlineSettingsFileName: string; @@ -39,4 +40,5 @@ export interface DoubanPluginSetting { // syncLastUpdateTime: Map, arraySettings: ArraySetting[], scoreSetting: ScoreSetting, + searchDefaultType: SupportType, } diff --git a/src/org/wanxp/douban/sync/handler/list/DoubanGameListHandler.ts b/src/org/wanxp/douban/sync/handler/list/DoubanGameListHandler.ts index 8200385..6e9e2f9 100644 --- a/src/org/wanxp/douban/sync/handler/list/DoubanGameListHandler.ts +++ b/src/org/wanxp/douban/sync/handler/list/DoubanGameListHandler.ts @@ -40,7 +40,7 @@ export abstract class DoubanGameListHandler extends DoubanAbstractListHandler { .find("div.title > a") .text() .trim(); - const updateDateStr: string = item.find("div.date").text().trim(); + const updateDateStr: string = item.find("span.date").text().trim(); let updateDate = null; try { updateDate = new Date(updateDateStr); @@ -73,11 +73,10 @@ export abstract class DoubanGameListHandler extends DoubanAbstractListHandler { }); const {syncConfig} = context; const {scope} = syncConfig; - const pattern = /(\d+)/g; - const wishCount = this.getCount(countDescs, '想玩', pattern); - const collectCount = this.getCount(countDescs, '玩过', pattern); - const doCount = this.getCount(countDescs, '在玩', pattern); + const wishCount = this.getCount(countDescs, '想玩'); + const collectCount = this.getCount(countDescs, '玩过'); + const doCount = this.getCount(countDescs, '在玩'); switch (scope) { @@ -94,8 +93,9 @@ export abstract class DoubanGameListHandler extends DoubanAbstractListHandler { } - private getCount(countDescs:string[], keyword:string, pattern:RegExp):number { + private getCount(countDescs:string[], keyword:string):number { return countDescs.filter(desc => desc.includes(keyword)).map(desc => { + const pattern = /(\d+)/g; const result = pattern.exec(desc); return result ? parseInt(result[0], 10) : 0; })[0]; diff --git a/src/org/wanxp/lang/locale/en.ts b/src/org/wanxp/lang/locale/en.ts index f7462a3..3540eb3 100644 --- a/src/org/wanxp/lang/locale/en.ts +++ b/src/org/wanxp/lang/locale/en.ts @@ -1,13 +1,18 @@ //简体中文 export default { //main.ts - '110001': 'search douban by current file name', - '110002': 'search douban and import to current file', + '110001': 'search by current file name', + '110002': 'search and import to current file', '110003': `Enter Search Term:`, '110004': `Search`, '110005': `Cancel`, - '110006': `sync douban personal book-movie-music to Obsidian`, - '110101': 'search douban and create file', + '110006': `sync personal book-movie-music to Obsidian`, + '110101': 'search and create file', + '110102': 'search movie or tv and create ', + '110104': 'search book and create', + '110105': 'search music and create ', + '110106': 'search game and create ', + '110201': `{0} already exists`, '110202': `{0} template can not read`, '110103': 'sync personal data from douban', @@ -240,6 +245,9 @@ PS: This file could be delete if you want to. '121401': `Status Bar`, '121402': `Display status bar when import data ?`, + '121410': `Search Default Type`, + '121411': `Search defuault type when open command palette 'search douban and create file'`, + '121430': `Save Attachment File`, '121431': `Save attachment file to local disk, such as image ? If you do not enable this feature, it will not show cover image in note`, '121432': `Attachment folder`, @@ -349,6 +357,8 @@ PS: This file could be delete if you want to. '150103': `[Next Page]...`, '150105': `[Next Page (Group Post)]...`, '150104': `[Next Page (Please Login First)]...`, + '150107': `Result is empty. Please choose type before search`, + '150108': `If you can't find what you want, try changing the keyword or search type`, @@ -648,6 +658,18 @@ PS: This file could be delete if you want to. 'MOVIE_AND_TELEPLAY': `movie&tv`, + 'all': `all`, + 'movie': `movie`, + 'book': `book`, + 'music': `music`, + 'note': `note`, + 'game': `game`, + 'teleplay': `teleplay`, + 'theater': `theater`, + + 'movie_and_teleplay': `movie&tv`, + + 'DAY': `D`, 'HOUR': `H`, diff --git a/src/org/wanxp/lang/locale/zh-cn.ts b/src/org/wanxp/lang/locale/zh-cn.ts index adeea99..fc8bfa0 100644 --- a/src/org/wanxp/lang/locale/zh-cn.ts +++ b/src/org/wanxp/lang/locale/zh-cn.ts @@ -4,14 +4,22 @@ import {SyncItemStatus} from "../../constant/Constsant"; export default { //main.ts - '110001': '搜索豆瓣当前文档名并写入', - '110002': '搜索豆瓣并写入当前文档', + '110001': '搜索当前文档名并写入', + '110002': '搜索并写入当前文档', '110003': `输入搜索内容:`, '110004': `搜索`, '110005': `取消`, - '110006': `同步豆瓣广播至Obsidian`, - '110101': '搜索豆瓣并创建文档', - '110103': '同步豆瓣个人书影音广播记录', + '110006': `同步广播至Obsidian`, + '110101': '搜索并创建文档', + '110103': '同步个人书影音广播记录', + //'110102': 'search douban and create movie or tv', + '110102': '搜索电影或电视剧并创建', +// '110104': 'search douban and create book', + '110104': '搜索书籍并创建', + //'110105': 'search douban and create music', + '110105': '搜索音乐并创建', + //'110106': 'search douban and create game', + '110106': '搜索游戏并创建', '110007': `开始同步`, '110009': `停止同步`, '110010': `后台运行`, @@ -61,7 +69,7 @@ export default { {1} ### 同步结果明细 -{1} +{2} --- 注:此文档可删除 @@ -284,6 +292,14 @@ export default { '121401': `状态栏`, '121402': `当在导入数据时, 是否需要在状态栏显示处理状态? `, + // '121410': `Search Default Type`, + // '121411': `Search defuault type for open command palette 'search douban and create file'`, + '121410': `默认搜索类型`, + '121411': `在打开"搜索豆瓣并创建文件"时默认搜索的类型`, + + + + '121430': `保存图片附件`, '121431': `导入数据会同步保存图片附件到本地文件夹, 如电影封面,书籍封面。如果需要显示封面,请保持开启该功能。`, '121432': `附件存放位置`, @@ -355,6 +371,9 @@ export default { '150103': `[下一页]...`, '150105': `[下一页]...(小组帖子结果)`, '150104': `[下一页]...(请先在插件中登录才能使用此功能)`, +// '150107': `Result is empty. Please choose type before search`, + '150107': `结果为空,请先选择类型再搜索`, + '150108': `如果没有找到你想要的内容, 请尝试更换关键字或者更换搜索类型`, //content '200101': `。`, @@ -655,6 +674,16 @@ export default { 'MOVIE_AND_TELEPLAY': `影视剧`, + 'all': `全部类型`, + 'movie': `电影`, + 'book': `书籍`, + 'music': `音乐`, + 'note': `笔记`, + 'game': `游戏`, + 'teleplay': `电视剧`, + 'theater': `戏剧`, + 'movie_and_teleplay': `影视剧`, + 'DAY': `天`, 'HOUR': `时`, 'MINUTE': `分`, diff --git a/src/org/wanxp/main.ts b/src/org/wanxp/main.ts index 4dc6ffb..19f3158 100644 --- a/src/org/wanxp/main.ts +++ b/src/org/wanxp/main.ts @@ -151,17 +151,21 @@ export default class DoubanPlugin extends Plugin { if (activeFile) { const searchTerm = activeFile.basename; if (searchTerm) { - await this.search(searchTerm, SupportType.ALL, context); + await this.search(searchTerm, SupportType.all, context); } } } async getDoubanTextForCreateNewNote(context: HandleContext) { - new DoubanSearchModal(this.app, this, context).open(); + new DoubanSearchModal(this.app, this, context, null).open(); + } + + async getDoubanTextForCreateNewNoteForType(context: HandleContext, type: SupportType) { + new DoubanSearchModal(this.app, this, context, type).open(); } async getDoubanTextForSearchTerm(context: HandleContext) { - new DoubanSearchModal(this.app, this, context).open(); + new DoubanSearchModal(this.app, this, context, null).open(); } async showSyncModal(context: HandleContext) { @@ -180,13 +184,13 @@ export default class DoubanPlugin extends Plugin { id: "searcher-douban-import-and-create-file", name: i18nHelper.getMessage("110101"), callback: () => - this.getDoubanTextForCreateNewNote({plugin: this, + this.getDoubanTextForCreateNewNoteForType({plugin: this, mode: SearchHandleMode.FOR_CREATE, settings: this.settings, userComponent: this.userComponent, netFileHandler: this.netFileHandler, showAfterCreate:true, - action: Action.SearchAndCrate}), + action: Action.SearchAndCrate}, this.settings.searchDefaultType), }); this.addCommand({ @@ -228,6 +232,61 @@ export default class DoubanPlugin extends Plugin { syncStatusHolder: this.statusHolder}), }); + this.addCommand({ + id: "searcher-douban-import-and-create-file-movie-tv", + name: i18nHelper.getMessage("110102"), + callback: () => + this.getDoubanTextForCreateNewNoteForType({plugin: this, + mode: SearchHandleMode.FOR_CREATE, + settings: this.settings, + userComponent: this.userComponent, + netFileHandler: this.netFileHandler, + showAfterCreate:true, + action: Action.SearchAndCrate}, SupportType.movie), + }); + + this.addCommand({ + id: "searcher-douban-import-and-create-file-book", + name: i18nHelper.getMessage("110104"), + callback: () => + this.getDoubanTextForCreateNewNoteForType({plugin: this, + mode: SearchHandleMode.FOR_CREATE, + settings: this.settings, + userComponent: this.userComponent, + netFileHandler: this.netFileHandler, + showAfterCreate:true, + action: Action.SearchAndCrate}, SupportType.book), + }); + + this.addCommand({ + id: "searcher-douban-import-and-create-file-music", + name: i18nHelper.getMessage("110105"), + callback: () => + this.getDoubanTextForCreateNewNoteForType({plugin: this, + mode: SearchHandleMode.FOR_CREATE, + settings: this.settings, + userComponent: this.userComponent, + netFileHandler: this.netFileHandler, + showAfterCreate:true, + action: Action.SearchAndCrate}, SupportType.music), + }); + + this.addCommand({ + id: "searcher-douban-import-and-create-file-game", + name: i18nHelper.getMessage("110106"), + callback: () => + this.getDoubanTextForCreateNewNoteForType({plugin: this, + mode: SearchHandleMode.FOR_CREATE, + settings: this.settings, + userComponent: this.userComponent, + netFileHandler: this.netFileHandler, + showAfterCreate:true, + action: Action.SearchAndCrate}, SupportType.game), + }); + + + + this.settingsManager = new SettingsManager(app, this); // this.fetchOnlineData(this.settingsManager); this.userComponent = new UserComponent(this.settingsManager); diff --git a/src/org/wanxp/utils/VariableUtil.ts b/src/org/wanxp/utils/VariableUtil.ts index ded1667..e66c32c 100644 --- a/src/org/wanxp/utils/VariableUtil.ts +++ b/src/org/wanxp/utils/VariableUtil.ts @@ -244,7 +244,7 @@ export class VariableUtil { const customPropertiesMap= new Map(); customProperties.filter(customProperty => customProperty.name && customProperty.field - && (customProperty.field.toLowerCase() == SupportType.ALL || + && (customProperty.field.toLowerCase() == SupportType.all || customProperty.field.toLowerCase() == subjectType)).forEach(customProperty => { customPropertiesMap.set(customProperty.name, customProperty.value); });