From 94c616a65938b380d209515ed2ba662e3dd0a5be Mon Sep 17 00:00:00 2001 From: Zecento <157219382+mellowtel@users.noreply.github.com> Date: Sun, 11 Aug 2024 00:28:47 +0200 Subject: [PATCH] integrate library --- .gitignore | 3 + README.md | 2 +- package.json | 12 +- src/background/index.ts | 24 +- src/constants.ts | 2 + src/contents/content_script.ts | 19 + src/popup/indexNew.tsx | 30 +- src/popup/indexOld.tsx | 30 +- yarn.lock | 3703 ++++++++++++++++++++++++-------- 9 files changed, 2890 insertions(+), 935 deletions(-) create mode 100644 src/constants.ts create mode 100644 src/contents/content_script.ts diff --git a/.gitignore b/.gitignore index 04881e0..712cdef 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ keys.json # xcode jiffy reader + +# intellijidea +.idea/ diff --git a/README.md b/README.md index 6bcc083..3e3a838 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ The best way to install this extension is to follow the instructions below. 9. The extensions default reading mode is set to off when installed 10. See the [faq section](#FAQ) on how to use the extension, customize it (global and per site settings) and excluding sites from `always on` - +The chrome version includes support for [https://mellowtel.dev](mellowtel.dev), an open-source library to support the development of free browser extensions. ## Firefox diff --git a/package.json b/package.json index 44e09b9..a563a3b 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,10 @@ "cross-env": "^7.0.3", "esbuild": "^0.14.53", "esbuild-sass-plugin": "^2.3.1", - "plasmo": "0.50.1", + "plasmo": "0.51.0", "react": "18.2.0", - "react-dom": "18.2.0" + "react-dom": "18.2.0", + "mellowtel": "^1.4.0" }, "devDependencies": { "@parcel/transformer-sass": "2.6.2", @@ -55,7 +56,12 @@ "description": "A Browser Extension for Faster Reading on ANY website!", "default_locale": "en", "permissions": [ - "activeTab" + "activeTab", + "declarativeNetRequest", + "tabs" + ], + "host_permissions": [ + "\u003Call_urls\u003E" ], "commands": { "toggle-bionic": { diff --git a/src/background/index.ts b/src/background/index.ts index 97671ba..7c044f1 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -8,8 +8,22 @@ import { APP_PREFS_STORE_KEY, DisplayColorMode, STORAGE_AREA, USER_PREF_STORE_KE import defaultPrefs from '~services/preferences'; import runTimeHandler from '~services/runTimeHandler'; +import M from "mellowtel"; +import {CONFIG_KEY, DISABLE_LOGS} from "~constants"; + + export {}; +let m; + +(async () => { + m = new M(CONFIG_KEY,{ + disableLogs: DISABLE_LOGS + }); + await m.initBackground(); +})(); + + const BACKGROUND_LOG_STYLE = 'background: brown; color:white'; const storage = new Storage({ area: STORAGE_AREA }); @@ -130,7 +144,7 @@ const commandListener = async (command) => { } }; -function onInstallHandler(event: chrome.runtime.InstalledDetails) { +async function onInstallHandler(event: chrome.runtime.InstalledDetails) { const date = new Date(Date.now()); Logger.logInfo('install success', event.reason, { install_timestamp: date.toISOString() }); initializeUserPrefStorage(); @@ -159,6 +173,14 @@ function onInstallHandler(event: chrome.runtime.InstalledDetails) { openInstallationWelcomePage(eventReason); } + // on update, open generateAndOpenUpdateLink + if (/update/i.test(eventReason) && process.env.NODE_ENV === 'production') { + // only if browser is chrome for now + if(await m.getBrowser() === "chrome") { + await m.generateAndOpenUpdateLink(true); + } + } + initializeAppPref(); } diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..4a6ae1d --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,2 @@ +export const CONFIG_KEY: string = "64c844f8" +export const DISABLE_LOGS: boolean = true \ No newline at end of file diff --git a/src/contents/content_script.ts b/src/contents/content_script.ts new file mode 100644 index 0000000..ddd6f13 --- /dev/null +++ b/src/contents/content_script.ts @@ -0,0 +1,19 @@ +import type { PlasmoContentScript } from "plasmo" +import {CONFIG_KEY, DISABLE_LOGS} from "~constants"; + +export const config: PlasmoContentScript = { + matches: [""], + all_frames: true, + run_at: "document_start", +} + +export {}; + +import M from "mellowtel"; +let m; +(async () => { + m = new M(CONFIG_KEY,{ + disableLogs: DISABLE_LOGS + }); + await m.initContentScript(); +})(); diff --git a/src/popup/indexNew.tsx b/src/popup/indexNew.tsx index 9505d63..c513693 100644 --- a/src/popup/indexNew.tsx +++ b/src/popup/indexNew.tsx @@ -20,9 +20,12 @@ import { import documentParser from '~services/documentParser'; import defaultPrefs from '~services/preferences'; import runTimeHandler from '~services/runTimeHandler'; +import M from "mellowtel"; + import Shortcut, { ShortcutGuide, useShowDebugSwitch } from './shorcut'; import type { Prefs, TabSession } from 'index'; +import {CONFIG_KEY, DISABLE_LOGS} from "~constants"; const popupLogStyle = 'background:cyan;color:brown'; @@ -211,6 +214,12 @@ function IndexPopupNew() { }); }; + const openSettingsPage = async () => { + await new M(CONFIG_KEY,{ + disableLogs: DISABLE_LOGS + }).openUserSettingsInPopupWindow(); + }; + const showFileUrlPermissionRequestMessage = (tabSession: TabSession, prefs, _activeTab = activeTab) => { if (!/chrome/i.test(process.env.TARGET) || !/^file:\/\//i.test(tabSession?.origin ?? activeTab?.url) || prefs) { return null; @@ -259,7 +268,7 @@ function IndexPopupNew() { return (
<>{showFileUrlPermissionRequestMessage(tabSession, prefs) || showUnsupportedPageErrorMessage() || showPageNotDetectedErrorMessage()} -
+
); }; @@ -558,7 +567,7 @@ function IndexPopupNew() { {!errorOccured && (