From 2237148a8d04fd4b0d772f1de467d89703cdc317 Mon Sep 17 00:00:00 2001 From: lifesign Date: Tue, 8 Feb 2022 20:26:40 +0800 Subject: [PATCH 01/16] feat: add isBlank mixin --- tool.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tool.js b/tool.js index 2603cef..de08f73 100644 --- a/tool.js +++ b/tool.js @@ -1,3 +1,8 @@ +function isBlank(value) { + return _.isEmpty(value) && !_.isNumber(value) || _.isNaN(value) +} +_.mixin({ isBlank }) + module.exports = { getUpdateFrequency: () => { const DEFAULT_MIN_FREQUENCY = 2 From e43a0f9dcacacc07a84183cc412fcd8d5963088e Mon Sep 17 00:00:00 2001 From: lifesign Date: Tue, 8 Feb 2022 20:26:55 +0800 Subject: [PATCH 02/16] feat: add author avatar --- sspai.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sspai.js b/sspai.js index 1279049..73e3662 100644 --- a/sspai.js +++ b/sspai.js @@ -8,6 +8,13 @@ const sspai = { formatLinkByPostId: (postId) => { return "https://sspai.com/post/" + postId }, + formatLinkByAvatar: (url) => { + if (_.isBlank(url) || _.includes(url, "gif")) { + debug(`invalid avatar url: ${url}. fallback to placeholder.`) + url = "ui/avatar-placeholder.png" + } + return "https://cdn.sspai.com/" + url + }, getUnreadFeeds: (feeds, readIds) => { return _.filter(feeds, (item, index) => !_.includes(readIds, getPostId(item.link))) }, @@ -33,7 +40,8 @@ const sspai = { // console.log(sspai.formatLinkByPostId(item["id"])) return { link: sspai.formatLinkByPostId(item["id"]), - title: item["title"] + title: item["title"], + avatar: sspai.formatLinkByAvatar(item["author"]["avatar"]) } }) } @@ -56,7 +64,8 @@ const sspai = { // console.log(sspai.formatLinkByPostId(item["id"])) return { link: sspai.formatLinkByPostId(item["id"]), - title: item["title"] + title: item["title"], + avatar: sspai.formatLinkByAvatar(item["author"]["avatar"]) } }) } From 7316d2ed446bf0662770b229deb492e2fd8c077e Mon Sep 17 00:00:00 2001 From: lifesign Date: Tue, 8 Feb 2022 20:27:08 +0800 Subject: [PATCH 03/16] feat: add avatar for popover --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 25c958d..c65a38f 100644 --- a/index.js +++ b/index.js @@ -147,7 +147,7 @@ function updateData() { // const stylePath = "./menubar/" + getMenuBarStyleName(); // debug("menubar style path: " + stylePath); here.menuBar.set({ - title: `(${unreadFeeds.length})`, + title: ` ${unreadFeeds.length}`, icon: stylePath, }) // here.menuBar.setIcon(stylePath); @@ -189,10 +189,16 @@ function formatTabData(rawUnreadFeeds, readIds) { } return _.map(rawUnreadFeeds, (item, index) => { // console.log("item detail" + JSON.stringify(item)) + // console.log("item avatar: " + item.avatar) return { title: isDebugMode() ? `${index + 1}. ${item.title} PID:${getPostId(item.link)}` : `${index + 1}. ${item.title}`, + accessory: { + title: "", + imageURL: `${item.avatar}`, + imageCornerRadius: 4, + }, onClick: () => { if (item.link != undefined) { let postId = getPostId(item.link); From 5e99737d185b89444d8dcafc33c120316848115d Mon Sep 17 00:00:00 2001 From: lifesign Date: Thu, 10 Feb 2022 22:20:23 +0800 Subject: [PATCH 04/16] feat: add expert mode config --- config.json | 6 ++++++ tool.js | 3 +++ 2 files changed, 9 insertions(+) diff --git a/config.json b/config.json index 34e8109..987b90b 100644 --- a/config.json +++ b/config.json @@ -61,6 +61,12 @@ "type": "text", "key": "debug-hotkey", "default": "cmd+F1", + }, + { + "title": "高级模式", + "type": "checkbox", + "key": "expert-mode", + "default": false, } ] } diff --git a/tool.js b/tool.js index de08f73..496b6e0 100644 --- a/tool.js +++ b/tool.js @@ -48,6 +48,9 @@ module.exports = { getDebugHotkey: () => { return pref.get("debug-hotkey") }, + getExpertMode: () => { + return pref.get("expert-mode") + }, debug: (log, isMainFlow = false, override = false) => { let span = "" if (!isMainFlow) { From c51011f1ddb9327c3351d5df8661037eca6c8feb Mon Sep 17 00:00:00 2001 From: lifesign Date: Thu, 10 Feb 2022 22:20:35 +0800 Subject: [PATCH 05/16] feat: add copy debug info --- index.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c65a38f..dbbae33 100644 --- a/index.js +++ b/index.js @@ -5,9 +5,10 @@ const net = require("net") const pref = require("pref") const i18n = require("i18n") const http = require('http') +const pb = require('pasteboard') const {getPostId, getUnreadFeeds, getMatrixData, getHomepageData} = require('./sspai.js') -const {getUpdateFrequency, getFetchArticleNum, getMenuBarStyleName, isDebugMode, isUnreadNotifyOpen, getDebugHotkey, debug} = require('./tool.js') +const {getUpdateFrequency, getFetchArticleNum, getMenuBarStyleName, isDebugMode, isUnreadNotifyOpen, getDebugHotkey, getExpertMode, debug} = require('./tool.js') function updateData() { debug(__("update data starting"), true) @@ -138,6 +139,68 @@ function updateData() { "data": formatTabData(val, readIds) } }) + + //expert mode tab + if (getExpertMode()) { + let expertModeTab = { + "title": "⚙️高级设置🤫", + "data": [ + { + title: "=================展示配置=================" + }, + { + title: "是否展示作者头像", + accessory: new here.SwitchAccessory({ + id: "accessory-avatar", + isOn: true, + onValueChange: (isOn) => { + console.log(`isOn: ${isOn}`); + here.popover.update(`#accessory-avatar.isOn`, isOn) + here.hudNotification(`avatar is ${isOn ? "On" : "Off"}.`); + } + }), + }, + { + title: "是否展示已读文章", + accessory: new here.SwitchAccessory({ + id: "accessory-read", + isOn: true, + onValueChange: (isOn) => { + console.log(`isOn: ${isOn}`); + here.popover.update(`#accessory-read.isOn`, isOn) + here.hudNotification(`read is ${isOn ? "On" : "Off"}.`); + } + }), + }, + ] + } + if (isDebugMode()) { + let debugLineData = [ + { + title: "=================DEBUG=================" + }, + { + title: "一键清除缓存", + accessory: new here.MainTextAccessory({ + title: "谨慎使用", + // detail: "Some detail" + }) + }, + { + title: "一键复制缓存信息", + onClick: () => { + pb.setText(JSON.stringify(cache.all())); + here.hudNotification("Debug info copied."); + } + }, + ] + + let mergeData = expertModeTab.data + mergeData.push(...debugLineData) + } + tabData.push(expertModeTab) + } + // console.log("tabData:" + JSON.stringify(tabData)) here.popover = new here.TabPopover(tabData); here.popover.reload() From 14c39e4b0fed2c1e3169a4595b828a8d499fd9c7 Mon Sep 17 00:00:00 2001 From: lifesign Date: Thu, 10 Feb 2022 22:50:24 +0800 Subject: [PATCH 06/16] feat: add cache remove --- index.js | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index dbbae33..5f73d45 100644 --- a/index.js +++ b/index.js @@ -66,32 +66,25 @@ function updateData() { } debug(`toRenderSize. matrix:${matrixData.items.length} homepage:${homepageData.items.length}`) - //init read list cache - let cachedPostIds = cache.get('readIds'); - if (cachedPostIds == undefined) { - debug("🚀 已读列表初始化缓存") - cache.set('readIds', []); - } else { - cachedPostIds = JSON.parse(cachedPostIds); - const checkUnreadFeedsNum = getUnreadFeeds(_.concat(matrixData.items, homepageData.items), cachedPostIds).length - debug("unread total: " + checkUnreadFeedsNum) - //unread notify - if (checkUnreadFeedsNum > 0 && IS_UNREAD_NOTIFY_OPEN) { - //when in debug mode, system notifications will be conflicted - //delay the unread notification for seconds later - _.delay((unreadNum) => { - here.systemNotification("【少数派有新的文章更新啦】", `未读数 ${checkUnreadFeedsNum}`) - }, isDebugMode() ? 5000 : 1000); - } + const cachedPostIds = JSON.parse(cache.get('readIds') || '[]'); + const checkUnreadFeedsNum = getUnreadFeeds(_.concat(matrixData.items, homepageData.items), cachedPostIds).length + debug("unread total: " + checkUnreadFeedsNum) + //unread notify + if (checkUnreadFeedsNum > 0 && IS_UNREAD_NOTIFY_OPEN) { + //when in debug mode, system notifications will be conflicted + //delay the unread notification for seconds later + _.delay((unreadNum) => { + here.systemNotification("【少数派有新的文章更新啦】", `未读数 ${checkUnreadFeedsNum}`) + }, isDebugMode() ? 5000 : 1000); } // render component let renderComponent = () => { - let readIds = JSON.parse(cache.get('readIds')); + let readIds = JSON.parse(cache.get('readIds') || '[]'); debug(`cachedIDs:${JSON.stringify(readIds)}`) //TOP Feed set...... - let unreadFeeds = getUnreadFeeds(_.concat(matrixData.items, homepageData.items), readIds) + const unreadFeeds = getUnreadFeeds(_.concat(matrixData.items, homepageData.items), readIds) let topFeed = _.head(unreadFeeds) debug(`topFeed: ${topFeed != undefined ? topFeed.title : ""}`) here.miniWindow.set({ @@ -183,14 +176,17 @@ function updateData() { title: "一键清除缓存", accessory: new here.MainTextAccessory({ title: "谨慎使用", - // detail: "Some detail" - }) + }), + onClick: () => { + cache.removeAll() + here.hudNotification("Cache info cleared."); + } }, { title: "一键复制缓存信息", onClick: () => { pb.setText(JSON.stringify(cache.all())); - here.hudNotification("Debug info copied."); + here.hudNotification("Cache info copied."); } }, ] From dca0ce45093fd957593367732d5fd25195121302 Mon Sep 17 00:00:00 2001 From: lifesign Date: Thu, 10 Feb 2022 23:13:02 +0800 Subject: [PATCH 07/16] feat: expert switches storage works fine --- index.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 5f73d45..b38bc75 100644 --- a/index.js +++ b/index.js @@ -135,6 +135,9 @@ function updateData() { //expert mode tab if (getExpertMode()) { + let expertModeConfig = JSON.parse(cache.get('expert') || '{}') + console.log("avatar switch: " + getShowExpertSpecificSwitch('avatar', true)) + console.log("read switch: " + getShowExpertSpecificSwitch('read', false)) let expertModeTab = { "title": "⚙️高级设置🤫", "data": [ @@ -145,11 +148,15 @@ function updateData() { title: "是否展示作者头像", accessory: new here.SwitchAccessory({ id: "accessory-avatar", - isOn: true, + isOn: getShowExpertSpecificSwitch('avatar', true), onValueChange: (isOn) => { - console.log(`isOn: ${isOn}`); + console.log(`accessory-avatar isOn: ${isOn}`); + expertModeConfig['avatar'] = isOn ? true : false + // console.log(expertModeConfig) + cache.set('expert', expertModeConfig) + console.log(cache.get('expert')) here.popover.update(`#accessory-avatar.isOn`, isOn) - here.hudNotification(`avatar is ${isOn ? "On" : "Off"}.`); + here.hudNotification(`avatar switch is ${isOn ? "On" : "Off"}.`); } }), }, @@ -157,11 +164,14 @@ function updateData() { title: "是否展示已读文章", accessory: new here.SwitchAccessory({ id: "accessory-read", - isOn: true, + isOn: getShowExpertSpecificSwitch('read', false), onValueChange: (isOn) => { - console.log(`isOn: ${isOn}`); + console.log(`read isOn: ${isOn}`); + expertModeConfig['read'] = isOn ? true : false + cache.set('expert', expertModeConfig) + console.log(cache.get('expert')) here.popover.update(`#accessory-read.isOn`, isOn) - here.hudNotification(`read is ${isOn ? "On" : "Off"}.`); + here.hudNotification(`read post switch is ${isOn ? "On" : "Off"}.`); } }), }, @@ -241,6 +251,12 @@ function updateData() { }) } +function getShowExpertSpecificSwitch(switchName, notExistsDefaultValue) { + const expertModeConfig = JSON.parse(cache.get('expert') || '{}') + if (_.isEmpty(expertModeConfig) || expertModeConfig[switchName] == undefined) return notExistsDefaultValue + return expertModeConfig[switchName] +} + function formatTabData(rawUnreadFeeds, readIds) { // console.log(rawUnreadFeeds) if (_.isEmpty(rawUnreadFeeds)) { From 2a556fc105a395e9ca9e1b9276edc9dc2a94a377 Mon Sep 17 00:00:00 2001 From: lifesign Date: Thu, 10 Feb 2022 23:33:48 +0800 Subject: [PATCH 08/16] feat: impl avatar switch with clean approach --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b38bc75..64a1926 100644 --- a/index.js +++ b/index.js @@ -271,8 +271,8 @@ function formatTabData(rawUnreadFeeds, readIds) { : `${index + 1}. ${item.title}`, accessory: { title: "", - imageURL: `${item.avatar}`, - imageCornerRadius: 4, + ...(getShowExpertSpecificSwitch('avatar', true)) && {imageURL: `${item.avatar}`}, + ...(getShowExpertSpecificSwitch('avatar', true)) && {imageCornerRadius: 4} }, onClick: () => { if (item.link != undefined) { From 9f74bf58b0115cd9fa5ff77fab71e680669285fd Mon Sep 17 00:00:00 2001 From: lifesign Date: Thu, 10 Feb 2022 23:54:05 +0800 Subject: [PATCH 09/16] feat: add index channel switch --- index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 64a1926..48de122 100644 --- a/index.js +++ b/index.js @@ -122,7 +122,8 @@ function updateData() { let homepageKey = __("Homepage") const tabRawData = { [matrixKey]: getUnreadFeeds(matrixData.items, readIds), - [homepageKey]: getUnreadFeeds(homepageData.items, readIds), + ...(getShowExpertSpecificSwitch('index-channel', true)) + && {[homepageKey]: getUnreadFeeds(homepageData.items, readIds)}, } // console.log(tabRawData) const tabData = _.map(tabRawData, (val, key) => { @@ -138,6 +139,7 @@ function updateData() { let expertModeConfig = JSON.parse(cache.get('expert') || '{}') console.log("avatar switch: " + getShowExpertSpecificSwitch('avatar', true)) console.log("read switch: " + getShowExpertSpecificSwitch('read', false)) + console.log("index-channel switch: " + getShowExpertSpecificSwitch('index-channel', true)) let expertModeTab = { "title": "⚙️高级设置🤫", "data": [ @@ -175,6 +177,21 @@ function updateData() { } }), }, + { + title: "是否展示[首页]频道", + accessory: new here.SwitchAccessory({ + id: "accessory-index-channel", + isOn: getShowExpertSpecificSwitch('index-channel', false), + onValueChange: (isOn) => { + console.log(`index channel isOn: ${isOn}`); + expertModeConfig['index-channel'] = isOn ? true : false + cache.set('expert', expertModeConfig) + console.log(cache.get('expert')) + here.popover.update(`#accessory-index-channel.isOn`, isOn) + here.hudNotification(`index channel switch is ${isOn ? "On" : "Off"}.`); + } + }), + }, ] } if (isDebugMode()) { From 1ac067cb5444c8e30a8e992822decc0d0a3a8acc Mon Sep 17 00:00:00 2001 From: lifesign Date: Fri, 11 Feb 2022 00:46:40 +0800 Subject: [PATCH 10/16] feat: impl read post filter --- index.js | 6 +++--- sspai.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 48de122..e55959f 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ const i18n = require("i18n") const http = require('http') const pb = require('pasteboard') -const {getPostId, getUnreadFeeds, getMatrixData, getHomepageData} = require('./sspai.js') +const {getPostId, getUnreadFeeds, getFeedsWithRead, getMatrixData, getHomepageData} = require('./sspai.js') const {getUpdateFrequency, getFetchArticleNum, getMenuBarStyleName, isDebugMode, isUnreadNotifyOpen, getDebugHotkey, getExpertMode, debug} = require('./tool.js') function updateData() { @@ -121,9 +121,9 @@ function updateData() { let matrixKey = __("Matrix") let homepageKey = __("Homepage") const tabRawData = { - [matrixKey]: getUnreadFeeds(matrixData.items, readIds), + [matrixKey]: getFeedsWithRead(matrixData.items, readIds), ...(getShowExpertSpecificSwitch('index-channel', true)) - && {[homepageKey]: getUnreadFeeds(homepageData.items, readIds)}, + && {[homepageKey]: getFeedsWithRead(homepageData.items, readIds)}, } // console.log(tabRawData) const tabData = _.map(tabRawData, (val, key) => { diff --git a/sspai.js b/sspai.js index 73e3662..221f3cc 100644 --- a/sspai.js +++ b/sspai.js @@ -18,6 +18,17 @@ const sspai = { getUnreadFeeds: (feeds, readIds) => { return _.filter(feeds, (item, index) => !_.includes(readIds, getPostId(item.link))) }, + getFeedsWithRead: (feeds, readIds) => { + return _.map(feeds, (feed, index) => { + if (_.includes(readIds, getPostId(feed.link))) { + //need to mark as read post and return + if (!feed.title.includes('[√]')) { + feed.title = `[√]${feed.title}` + } + } + return feed + }) + }, getMatrixData: () => { // replace rsshub feeds with directly api call, cause limit size not work in feeds. // return here.parseRSSFeed('https://rsshub.app/sspai/matrix?limit=30') From 43f3831cef33473ea0c62934be5cd5cb6dd25d6e Mon Sep 17 00:00:00 2001 From: lifesign Date: Fri, 11 Feb 2022 20:25:38 +0800 Subject: [PATCH 11/16] fix: toggle read switch with correct data --- index.js | 12 ++++++++++-- sspai.js | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e55959f..38a69f9 100644 --- a/index.js +++ b/index.js @@ -121,9 +121,9 @@ function updateData() { let matrixKey = __("Matrix") let homepageKey = __("Homepage") const tabRawData = { - [matrixKey]: getFeedsWithRead(matrixData.items, readIds), + [matrixKey]: getRenderedData(matrixData.items, readIds), ...(getShowExpertSpecificSwitch('index-channel', true)) - && {[homepageKey]: getFeedsWithRead(homepageData.items, readIds)}, + && {[homepageKey]: getRenderedData(homepageData.items, readIds)}, } // console.log(tabRawData) const tabData = _.map(tabRawData, (val, key) => { @@ -274,6 +274,14 @@ function getShowExpertSpecificSwitch(switchName, notExistsDefaultValue) { return expertModeConfig[switchName] } +function getRenderedData(feeds, readIds) { + const readSwitch = getShowExpertSpecificSwitch('read', false) + if (readSwitch) { + return getFeedsWithRead(feeds, readIds) + } + return getUnreadFeeds(feeds, readIds) +} + function formatTabData(rawUnreadFeeds, readIds) { // console.log(rawUnreadFeeds) if (_.isEmpty(rawUnreadFeeds)) { diff --git a/sspai.js b/sspai.js index 221f3cc..4e97d1d 100644 --- a/sspai.js +++ b/sspai.js @@ -22,8 +22,8 @@ const sspai = { return _.map(feeds, (feed, index) => { if (_.includes(readIds, getPostId(feed.link))) { //need to mark as read post and return - if (!feed.title.includes('[√]')) { - feed.title = `[√]${feed.title}` + if (!feed.title.includes('[已阅]')) { + feed.title = `[已阅]${feed.title}` } } return feed From ac1e49cd7c9a720e43f4ca91470b2b70bd294660 Mon Sep 17 00:00:00 2001 From: lifesign Date: Fri, 11 Feb 2022 20:48:10 +0800 Subject: [PATCH 12/16] fix: unread num not right when index channel is close --- index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 38a69f9..cf3d714 100644 --- a/index.js +++ b/index.js @@ -67,7 +67,11 @@ function updateData() { debug(`toRenderSize. matrix:${matrixData.items.length} homepage:${homepageData.items.length}`) const cachedPostIds = JSON.parse(cache.get('readIds') || '[]'); - const checkUnreadFeedsNum = getUnreadFeeds(_.concat(matrixData.items, homepageData.items), cachedPostIds).length + const checkUnreadFeedsNum = getUnreadFeeds( + (getShowExpertSpecificSwitch('index-channel', true) + ? _.concat(matrixData.items, homepageData.items) + : matrixData.items), + cachedPostIds).length debug("unread total: " + checkUnreadFeedsNum) //unread notify if (checkUnreadFeedsNum > 0 && IS_UNREAD_NOTIFY_OPEN) { @@ -84,7 +88,11 @@ function updateData() { debug(`cachedIDs:${JSON.stringify(readIds)}`) //TOP Feed set...... - const unreadFeeds = getUnreadFeeds(_.concat(matrixData.items, homepageData.items), readIds) + const unreadFeeds = getUnreadFeeds( + (getShowExpertSpecificSwitch('index-channel', true) + ? _.concat(matrixData.items, homepageData.items) + : matrixData.items), + readIds) let topFeed = _.head(unreadFeeds) debug(`topFeed: ${topFeed != undefined ? topFeed.title : ""}`) here.miniWindow.set({ @@ -181,7 +189,7 @@ function updateData() { title: "是否展示[首页]频道", accessory: new here.SwitchAccessory({ id: "accessory-index-channel", - isOn: getShowExpertSpecificSwitch('index-channel', false), + isOn: getShowExpertSpecificSwitch('index-channel', true), onValueChange: (isOn) => { console.log(`index channel isOn: ${isOn}`); expertModeConfig['index-channel'] = isOn ? true : false @@ -242,7 +250,7 @@ function updateData() { //dock component display here.dock.set({ - title: unreadFeeds.length.toString(), + title: `${unreadFeeds.length}`, detail: "少数派更新" }) here.dock.reload() From 25fd1da805f655dce0c3ee657d0e05381568ab72 Mon Sep 17 00:00:00 2001 From: lifesign Date: Sat, 12 Feb 2022 20:23:39 +0800 Subject: [PATCH 13/16] refactor: debug mode only work in expert mode --- index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index cf3d714..358dac3 100644 --- a/index.js +++ b/index.js @@ -331,7 +331,7 @@ function formatTabData(rawUnreadFeeds, readIds) { function initDebugHotKey() { //ensure debug switch was initialized closed on every onLoad - cache.set('debug-hotkey-switch', 0) + // cache.set('debug-hotkey-switch', 0) let hotkeySetting = getDebugHotkey(); if (hotkeySetting == "") return @@ -344,21 +344,27 @@ function initDebugHotKey() { } let bindResult = hotkey.bind(hotkeySetting.split("+"), () => { + //debug mode only available in expert mode + const identifier = here.pluginIdentifier() + if (!getExpertMode()) { + here.systemNotification("【🐞DEBUG模式开启失败】", `必须开启 ${identifier} 的高级模式后才可以使用`) + return false + } debug('|DEBUG_MODE CHANGED|', false, true) debug(`Before: ${cache.get('debug-hotkey-switch')}`) //Toggle Debug hotkey, implement use a simple cache switch const debugSwitch = cache.get('debug-hotkey-switch') - const identifier = here.pluginIdentifier() + if (debugSwitch != undefined && _.toSafeInteger(debugSwitch) == 1) { here.systemNotification("【🐞DEBUG模式】", `当前 ${identifier} 已关闭 DEBUG 模式`) cache.set('debug-hotkey-switch', 0) debug('After: 0') } else { here.systemNotification("【🐞DEBUG模式】", `当前 ${identifier} 处于 DEBUG 模式 -1. 每次重启或者 reload,缓存会清空 +1. 在高级设置下面会有 Debug 菜单 2. 帖子标题增加 POST_ID 方便追溯 `) - cache.removeAll() + // cache.removeAll() //ensure debug switch exists cache.set('debug-hotkey-switch', 1) debug('After: 1') From fa4c88e2138075ab9a41bae28f59ee0ceed73a3a Mon Sep 17 00:00:00 2001 From: lifesign Date: Sat, 12 Feb 2022 20:28:28 +0800 Subject: [PATCH 14/16] feat: reset debug setting when cache is clear --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 358dac3..14f119b 100644 --- a/index.js +++ b/index.js @@ -215,6 +215,8 @@ function updateData() { onClick: () => { cache.removeAll() here.hudNotification("Cache info cleared."); + //reset debug mode setting + cache.set('debug-hotkey-switch', 1) } }, { From 8f3702c5b9278db842891fa5dbd0c1e12241ba2f Mon Sep 17 00:00:00 2001 From: lifesign Date: Sat, 12 Feb 2022 20:39:55 +0800 Subject: [PATCH 15/16] feat: add clear read --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index 14f119b..1fb9041 100644 --- a/index.js +++ b/index.js @@ -226,6 +226,13 @@ function updateData() { here.hudNotification("Cache info copied."); } }, + { + title: "一键清除已读", + onClick: () => { + cache.remove("readIds") + here.hudNotification("Read cache cleared."); + } + }, ] let mergeData = expertModeTab.data From 597118ac4b3b107c2263dfdc902fa7bbaccb7f5a Mon Sep 17 00:00:00 2001 From: lifesign Date: Sat, 12 Feb 2022 20:40:06 +0800 Subject: [PATCH 16/16] chore: bump up version --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 987b90b..645883a 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "name": "少数派", - "version": "1.4.1", + "version": "1.5.0", "configURL": "https://raw.githubusercontent.com/FriendsOfHere/sspai/master/config.json", "downloadURL": "https://github.com/FriendsOfHere/sspai/releases/latest/download/SSPai.hereplugin", "description": "展示少数派最新文章",