Skip to content

Commit

Permalink
Merge pull request #1 from Chef5/dev
Browse files Browse the repository at this point in the history
fix: 修复首次运行报错
  • Loading branch information
Chef5 authored Jan 5, 2023
2 parents 9eb7adc + 3a3371a commit cbad614
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Continue To Visit",
"version": "1.0.3",
"version": "1.0.5",
"manifest_version": 3,
"description": "常用网址访问外链时,跳过提示页继续访问!",
"content_scripts": [
Expand Down
68 changes: 43 additions & 25 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,80 @@
* @Author: Patrick-Jun
* @Date: 2021-01-31 19:21:01
* @Last Modified by: Patrick-Jun
* @Last Modified time: 2021-12-01 12:04:31
* @Last Modified time: 2021-12-07 21:10:46
*/

"use strict";
// 校验网址更新频率
const updateHours = 24;
// 需要校验的网址配置
const websites = getWebsites() || [
// 默认网址配置
const websitesDefault = [
{
name: '知乎', // 站点名称
domain: 'link.zhihu.com', // 站点域名
exactMatch: '', // 精确校验
targetKey: 'target', // 目标url字段
name: '知乎',
domain: 'link.zhihu.com',
exactMatch: '',
targetKey: 'target'
},
{
name: 'CSDN',
domain: 'link.csdn.net',
exactMatch: '',
targetKey: 'target',
targetKey: 'target'
},
{
name: '简书',
domain: 'www.jianshu.com',
exactMatch: 'www.jianshu.com/go-wild?',
targetKey: 'url',
targetKey: 'url'
},
{
name: 'QQ邮箱',
domain: 'mail.qq.com',
exactMatch: 'mail.qq.com/cgi-bin/readtemplate?t=safety&check=false',
targetKey: 'gourl',
targetKey: 'gourl'
},
{
name: 'segmentfault',
domain: 'link.segmentfault.com',
exactMatch: '',
targetKey: 'url',
targetKey: 'url'
},
{
name: '掘金',
domain: 'link.juejin.cn',
exactMatch: '',
targetKey: 'target',
targetKey: 'target'
},
{
name: '微信开放社区',
domain: 'developers.weixin.qq.com',
exactMatch: 'developers.weixin.qq.com/community/middlepage/href',
targetKey: 'href'
},
{
name: '腾讯文档',
domain: 'docs.qq.com',
exactMatch: 'https://docs.qq.com/scenario/link.html',
targetKey: 'url'
}
];

run();
// 需要校验的网址配置
let websites = websitesDefault;

// 运行
try {
chrome.storage.local.get(['__chrome_ctv_websites'], (result) => {
websites = JSON.parse(result['__chrome_ctv_websites'] || '[]');
run();
});
} catch (error) {
websites = websitesDefault;
run();
}

// 更新匹配站点
updateWebsites();

/**
* @description 执行
Expand Down Expand Up @@ -106,26 +133,18 @@ function getTargetUrl(fullUrl, matchParams) {
}

/**
* @description 获取网站列表
* @description 更新网站列表
* @returns {*} 网站列表
*/
function getWebsites() {
let websites = [];
try {
chrome.storage.local.get(['__chrome_ctv_websites'], (result) => {
websites = JSON.parse(result['__chrome_ctv_websites']);
});
} catch (error) {
websites = [];
}
function updateWebsites() {
// 从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) {
const protocol = location.protocol;
get(`${protocol}//v1.hot.isdz.cn/github/Chrome-ContinueToVisit/main/src/websites.json`, (res) => {
get(`${protocol}//v1.hot.1zdz.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 });
});
Expand All @@ -134,7 +153,6 @@ function getWebsites() {
} catch (error) {
console.error(error);
}
return websites && websites.length > 0 ? websites : null;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/websites.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@
"domain": "developers.weixin.qq.com",
"exactMatch": "developers.weixin.qq.com/community/middlepage/href",
"targetKey": "href"
},
{
"name": "腾讯文档",
"domain": "docs.qq.com",
"exactMatch": "https://docs.qq.com/scenario/link.html",
"targetKey": "url"
}
]

0 comments on commit cbad614

Please sign in to comment.