Skip to content

Commit

Permalink
🔥 废弃proxy功能 #60
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Apr 26, 2022
1 parent d9bce47 commit 1ee42ad
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 114 deletions.
4 changes: 1 addition & 3 deletions build/scriptcat/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "ScriptCat",
"version": "0.9.0",
"version": "0.9.1",
"description": "脚本猫,一个用户脚本的框架,可编写脚本每天帮你自动处理事务.",
"background": {
"page": "background.html"
Expand Down Expand Up @@ -31,13 +31,11 @@
],
"permissions": [
"tabs",
"proxy",
"cookies",
"storage",
"debugger",
"downloads",
"webRequest",
"management",
"background",
"<all_urls>",
"contextMenus",
Expand Down
114 changes: 57 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scriptcat",
"version": "0.9.0",
"version": "0.9.1",
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
"scripts": {
"lint": "eslint --ext .js,.ts,.tsx tests/ src/",
Expand All @@ -25,7 +25,7 @@
"dexie": "^3.2.0",
"file-saver": "^2.0.5",
"jszip": "^3.7.1",
"log4js": "^6.4.1",
"log4js": "^6.4.5",
"monaco-editor": "^0.22.0",
"reflect-metadata": "^0.1.13",
"sortablejs": "^1.14.0",
Expand Down
1 change: 0 additions & 1 deletion src/apps/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SystemConfig } from '@App/pkg/config';
import { ICache } from '@App/pkg/storage/cache/cache';
import { Logger } from './logger/logger';

Expand Down
2 changes: 1 addition & 1 deletion src/apps/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const ExtVersion = '0.9.0';
export const ExtVersion = '0.9.1';

export const Server = process.env.NODE_ENV == 'production' ? 'https://sc.icodef.com/' : 'http://localhost:8080/';

Expand Down
56 changes: 13 additions & 43 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ user.listenEvent();
tools.listenEvent();

grant.listenScriptGrant();
window.addEventListener('message', (event) => {

// 监听日志
window.addEventListener('message', (event: MessageEvent<{ action: string; data: any }>) => {
if (event.data.action != Logger) {
return;
}
Expand All @@ -64,7 +66,7 @@ const timer = setInterval(() => {
sandbox.postMessage({ action: 'load' }, '*');
}, 1000);
window.addEventListener('message', sandboxLoad);
function sandboxLoad(event: MessageEvent) {
function sandboxLoad(event: MessageEvent<{ action: string }>) {
clearInterval(timer);
window.removeEventListener('message', sandboxLoad);
if (event.origin != 'null' && event.origin != App.ExtensionId) {
Expand Down Expand Up @@ -118,28 +120,29 @@ setInterval(() => {

get(Server + 'api/v1/system/version', (str) => {
chrome.storage.local.get(['oldNotice'], (items) => {
const resp = JSON.parse(str);
const resp = <{ data: { notice: string; version: string } }>JSON.parse(str);
if (resp.data.notice !== items['oldNotice']) {
chrome.storage.local.set({
void chrome.storage.local.set({
notice: resp.data.notice,
});
}
chrome.storage.local.set({
void chrome.storage.local.set({
version: resp.data.version,
});
});
});

// 半小时同步一次数据和检查更新
setInterval(() => {
get(Server + 'api/v1/system/version', (str) => {
chrome.storage.local.get(['oldNotice'], (items) => {
const resp = JSON.parse(str);
const resp = <{ data: { notice: string; version: string } }>JSON.parse(str);
if (resp.data.notice !== items['oldNotice']) {
chrome.storage.local.set({
void chrome.storage.local.set({
notice: resp.data.notice,
});
}
chrome.storage.local.set({
void chrome.storage.local.set({
version: resp.data.version,
});
});
Expand All @@ -152,42 +155,9 @@ setInterval(() => {
if (process.env.NODE_ENV == 'production') {
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason == 'install') {
chrome.tabs.create({ url: 'https://docs.scriptcat.org/' });
void chrome.tabs.create({ url: 'https://docs.scriptcat.org/' });
} else if (details.reason == 'update') {
chrome.tabs.create({ url: 'https://docs.scriptcat.org/change/' });
void chrome.tabs.create({ url: 'https://docs.scriptcat.org/change/' });
}
});
}

chrome.management.onEnabled.addListener((info) => {
for (const [, value] of info.permissions.entries()) {
if (value == 'proxy') {
InfoNotification(
'检测到扩展proxy权限冲突',
'检测到扩展"' + info.name + '"与ScriptCat冲突,可能会导致无法正常使用ScriptCat'
);
break;
}
}
});

chrome.management.getAll((items) => {
let text = '';
for (const item of items) {
if (item.id == chrome.runtime.id) {
continue;
}
for (const [, value] of item.permissions.entries()) {
if (value == 'proxy') {
text += item.name + ';';
break;
}
}
}
if (text !== '') {
InfoNotification(
'检测到扩展proxy权限冲突',
'检测到扩展"' + text + '"与ScriptCat冲突,可能会导致无法正常使用ScriptCat'
);
}
});
1 change: 1 addition & 0 deletions src/pkg/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Storage } from '@App/pkg/storage/storage'
import { ChromeStorage } from './storage/chrome';

export const SYSTEM_CONFIG_CHANGE = 'system_config_change';

//NOTE: 可以抽象set接口
export class SystemConfig {

Expand Down
4 changes: 3 additions & 1 deletion src/types/scriptcat.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ declare function GM_cookie(action: GM_Types.CookieAction, details: GM_Types.Cook
// 通过tabid(前后端通信可能用到,ValueChangeListener会返回tabid),获取storeid,后台脚本用.
declare function GM_getCookieStore(tabid: number, ondone: (storeId: number, error: any | undefined) => void): void;

// 正式版中以废弃
declare function CAT_setProxy(rule: CAT_Types.ProxyRule[] | string): void;
// 正式版中以废弃
declare function CAT_clearProxy(): void;
// 正式版中以废弃
declare function CAT_click(x: number, y: number): void;
declare function CAT_createFile(file: string | Blob, name: string, ondone?: (download: boolean, error?: any | undefined) => void): void;

declare namespace CAT_Types {
interface ProxyRule {
Expand Down
Loading

0 comments on commit 1ee42ad

Please sign in to comment.