From 7518882ceebb9d4cd2b40160bdd3d03ed59bbda0 Mon Sep 17 00:00:00 2001 From: Patrick-Jun Date: Tue, 23 Nov 2021 12:02:25 +0800 Subject: [PATCH] v1.0.2 --- README.md | 8 ++++++-- manifest.json | 4 ++-- src/app.js | 31 +++++++++++++++++++++---------- src/websites.json | 6 ++++++ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index daae565..9d8bbfe 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ "domain": "link.zhihu.com", "exactMatch": "", "targetKey": "target", -}, +} ``` - name: 站点名称 @@ -30,7 +30,11 @@ - exactMatch: 精确校验url(少数网站中转域名和主站点域名是一样的,例如”简书“,这时候就需要更精确的url匹配了) - targetKey: 目标url字段 -## 安装 +## 安装包 + +https://cloud.189.cn/web/share?code=MnQzamjQ732a(访问码:q6sa) + +## 从商店安装 - Chrome: https://chrome.google.com/webstore/detail/continue-to-visit/nabahgobhkeppllhmnkplegdfkehliab - Firefox: https://addons.mozilla.org/zh-CN/firefox/addon/continue-to-visit/ diff --git a/manifest.json b/manifest.json index f60bbdc..6e88ea9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Continue To Visit", - "version": "1.0.1", - "manifest_version": 2, + "version": "1.0.2", + "manifest_version": 3, "description": "常用网址访问外链时,跳过提示页继续访问!", "content_scripts": [ { diff --git a/src/app.js b/src/app.js index 23b57a0..c7fa34c 100644 --- a/src/app.js +++ b/src/app.js @@ -2,10 +2,12 @@ * @Author: Patrick-Jun * @Date: 2021-01-31 19:21:01 * @Last Modified by: Patrick-Jun - * @Last Modified time: 2021-08-12 10:52:09 + * @Last Modified time: 2021-11-22 23:10:09 */ "use strict"; +// 校验网址更新频率 +const updateHours = 24; // 需要校验的网址配置 const websites = getWebsites() || [ { @@ -108,20 +110,29 @@ function getTargetUrl(fullUrl, matchParams) { * @returns {*} 网站列表 */ function getWebsites() { - const websitesText = localStorage.getItem('__chrome_ctv_websites'); let websites = []; try { - websites = JSON.parse(websitesText); + chrome.storage.local.get(['__chrome_ctv_websites'], (result) => { + websites = JSON.parse(result['__chrome_ctv_websites']); + }); } catch (error) { websites = []; } - get('https://raw.githubusercontent.com/Patrick-Jun/Chrome-ContinueToVisit/main/src/websites.json', function(res) { - if (res) { - localStorage.setItem('__chrome_ctv_websites', JSON.stringify(res)); - } else { - localStorage.setItem('__chrome_ctv_websites', JSON.stringify([])); - } - }); + // 从github更新website + try { + chrome.storage.local.get(['__chrome_ctv_update'], (result) => { + const now = (new Date()).getTime(); + const update = result['__chrome_ctv_update']; + if (!update || now - update > updateHours * 3600000) { + get('http://v1.hot.isdz.cn/github/Chrome-ContinueToVisit/main/src/websites.json', (res) => { + chrome.storage.local.set({ '__chrome_ctv_websites': JSON.stringify(res || []) }); + chrome.storage.local.set({ '__chrome_ctv_update': now }); + }); + } + }); + } catch (error) { + console.error(error); + } return websites && websites.length > 0 ? websites : null; } diff --git a/src/websites.json b/src/websites.json index 5c32223..e95aca0 100644 --- a/src/websites.json +++ b/src/websites.json @@ -34,5 +34,11 @@ "domain": "link.juejin.cn", "exactMatch": "", "targetKey": "target" + }, + { + "name": "微信开放社区", + "domain": "developers.weixin.qq.com", + "exactMatch": "developers.weixin.qq.com/community/middlepage/href", + "targetKey": "href" } ] \ No newline at end of file