diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml
index de9aec4..127a135 100644
--- a/.github/workflows/publish-release.yml
+++ b/.github/workflows/publish-release.yml
@@ -92,19 +92,19 @@ jobs:
fi
- - name: chrome ext publish
- run: |
- if [ -z "${{ secrets.CLIENT_ID }}" ] || [ -z "${{ secrets.CLIENT_SECRET }}" ] || [ -z "${{ secrets.REFRESH_TOKEN }}" ] || [ -z "${{ secrets.EXTENSION_ID }}" ]; then
- echo "Required secrets are not provided. Exiting."
- exit 0
- fi
+ # - name: chrome ext publish
+ # run: |
+ # if [ -z "${{ secrets.CLIENT_ID }}" ] || [ -z "${{ secrets.CLIENT_SECRET }}" ] || [ -z "${{ secrets.REFRESH_TOKEN }}" ] || [ -z "${{ secrets.EXTENSION_ID }}" ]; then
+ # echo "Required secrets are not provided. Exiting."
+ # exit 0
+ # fi
- npx cws-publish ${{ secrets.CLIENT_ID }} ${{ secrets.CLIENT_SECRET }} ${{ secrets.REFRESH_TOKEN }} ./build/jiffyReader-chrome-prod.zip ${{ secrets.EXTENSION_ID }}
+ # npx cws-publish ${{ secrets.CLIENT_ID }} ${{ secrets.CLIENT_SECRET }} ${{ secrets.REFRESH_TOKEN }} ./build/jiffyReader-chrome-prod.zip ${{ secrets.EXTENSION_ID }}
- # if secrete.DEV_EXTENSION_ID is not empty then publish
- if [ -n "${{ secrets.EXTENSION_DEV_ID }}" ]; then
- npx cws-publish ${{ secrets.CLIENT_ID }} ${{ secrets.CLIENT_SECRET }} ${{ secrets.REFRESH_TOKEN }} ./build/jiffyReader-chrome-dev.zip ${{ secrets.EXTENSION_DEV_ID }}
- fi
+ # # if secrete.DEV_EXTENSION_ID is not empty then publish
+ # if [ -n "${{ secrets.EXTENSION_DEV_ID }}" ]; then
+ # npx cws-publish ${{ secrets.CLIENT_ID }} ${{ secrets.CLIENT_SECRET }} ${{ secrets.REFRESH_TOKEN }} ./build/jiffyReader-chrome-dev.zip ${{ secrets.EXTENSION_DEV_ID }}
+ # fi
diff --git a/Makefile b/Makefile
index b261f6e..a4fa916 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
SHELL := /bin/bash
.SILENT:
-.PHONY: build
+.PHONY: print-manifests build
help:
@@ -9,7 +9,7 @@ help:
| sed -e 's/\[32m #-- /[33m/'
print-manifests: ## print out build target manifests
- @ls ./build/jiffyReader-* -t |grep -E '.(xpi|zip|crx)' | xargs -I {} sh -c 'unzip -p "{}" manifest.json | jq -r ". | \"Version: \(.version), Name: \(.name), Version Name: \(.version_name), Target: \(.target), Scope: \(.scope) {}\""'
+ @ls ./build/jiffyReader-* -t |grep -E '.(xpi|zip|crx)' | xargs -I {} sh -c 'unzip -p "{}" manifest.json | jq -r ". | \"Version: \(.version), Name: \(.name), Version Name: \(.version_name), Target: \(.target), Tag: \(.tag) {}\""'
test-build-manifests: ## test build manifests
@if make -s print-manifests | grep -E '(\W-\W|null)'; then exit 1; fi
diff --git a/bump.txt b/bump.txt
deleted file mode 100644
index 18efdb9..0000000
--- a/bump.txt
+++ /dev/null
@@ -1 +0,0 @@
-1.1.8
diff --git a/package.json b/package.json
index 0d95ef9..c585125 100644
--- a/package.json
+++ b/package.json
@@ -5,35 +5,36 @@
"description": "jiffy reader",
"packageManager": "yarn@1.22.19",
"scripts": {
- "dev": "VERSION=\"$(npm pkg get version | tr -d '\"')\" TARGET=${TARGET:-chrome} NAME=${NAME:-\"jiffy-reader-chrome\"} TAG=${TAG:=local} VERSION_NAME=$VERSION-$TARGET-$TAG DEBUG=${DEBUG:-TRUE} SHORTCUT=${SHORTCUT:-\"Alt+B\"} plasmo dev --target=${MANIFEST_VERSION:-chrome-mv3}",
- "buildx": "VERSION=\"$(npm pkg get version | tr -d '\"')\" TARGET=${TARGET:-chrome} NAME=${NAME:-\"Jiffy Reader\"} TAG=${TAG:=prod} VERSION_NAME=$VERSION-$TARGET-$TAG DEBUG=${DEBUG:-FALSE} SHORTCUT=${SHORTCUT:-\"Alt+B\"} plasmo build --target=${MANIFEST_VERSION:-chrome-mv3}",
+ "dev": "PLASMO_VERSION=\"$(npm pkg get version | tr -d '\"')\" PLASMO_TARGET=${PLASMO_TARGET:-chrome} PLASMO_NAME=${PLASMO_NAME:-\"jiffy-reader-chrome\"} PLASMO_TAG=${PLASMO_TAG:-dev} PLASMO_VERSION_NAME=$PLASMO_VERSION-$PLASMO_TARGET-$PLASMO_TAG PLASMO_DEBUG=${PLASMO_DEBUG:-TRUE} PLASMO_SHORTCUT=${PLASMO_SHORTCUT:-\"Alt+B\"} plasmo dev --target=${PLASMO_MANIFEST_VERSION:-chrome-mv3}",
+ "buildx": "PLASMO_VERSION=\"$(npm pkg get version | tr -d '\"')\" PLASMO_TARGET=${PLASMO_TARGET:-chrome} PLASMO_NAME=${PLASMO_NAME:-\"Jiffy Reader\"} PLASMO_TAG=${PLASMO_TAG:-prod} PLASMO_VERSION_NAME=$PLASMO_VERSION-$PLASMO_TARGET-$PLASMO_TAG PLASMO_DEBUG=${PLASMO_DEBUG:-FALSE} PLASMO_SHORTCUT=${PLASMO_SHORTCUT:-\"Alt+B\"} plasmo build --target=${PLASMO_MANIFEST_VERSION:-chrome-mv3}",
"build": "npm run build:opera && npm run build:chrome & npm run build:firefox & npm run build:safari",
"dev:chrome": "npm run dev",
- "dev:firefox": "NAME=jiffy-reader-firefox TARGET=firefox SHORTCUT=\"Alt+W\" MANIFEST_VERSION=firefox-mv2 npm run dev",
- "dev:safari": "NAME=jiffy-reader-safari TARGET=safari SHORTCUT=\"Alt+W\" MANIFEST_VERSION=safari-mv2 npm run dev",
+ "dev:firefox": "PLASMO_NAME=jiffy-reader-firefox PLASMO_TARGET=firefox PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=firefox-mv2 npm run dev",
+ "dev:safari": "PLASMO_NAME=jiffy-reader-safari PLASMO_TARGET=safari PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=safari-mv2 npm run dev",
"build:chrome": "npm run buildx && npm run bundle:chrome",
- "build:opera": "TARGET=opera npm run build:chrome && npm run bundle:opera",
- "build:firefox": "NAME=jiffy-reader-firefox TARGET=firefox SHORTCUT=\"Alt+W\" MANIFEST_VERSION=firefox-mv2 npm run buildx && npm run bundle:firefox",
- "build:safari": "NAME=jiffy-reader-safari TARGET=safari SHORTCUT=\"Alt+W\" MANIFEST_VERSION=safari-mv2 npm run buildx && npm run bundle:safari",
- "gh:build:chrome": "TARGET=chrome SHORTCUT=\"Alt+B\" MANIFEST_VERSION=chrome-mv3 npm run buildx && npm run bundle:chrome",
- "gh:build:opera": "TARGET=opera SHORTCUT=\"Alt+B\" MANIFEST_VERSION=chrome-mv3 npm run buildx && npm run bundle:opera",
- "gh:build:firefox": "TARGET=firefox SHORTCUT=\"Alt+W\" MANIFEST_VERSION=firefox-mv2 npm run buildx && npm run bundle:firefox",
- "gh:build:safari": "TARGET=safari SHORTCUT=\"Alt+W\" MANIFEST_VERSION=safari-mv2 npm run buildx && npm run bundle:safari",
- "gh:build": "echo 'TAG=prod NODE_ENV=production npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari & wait'",
- "gh:build:development": "echo 'TAG=dev NODE_ENV=development NAME=Jiffy-Reader-Dev npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari & wait'",
- "gh:build:bookmarklet": "VERSION=\"$(npm pkg get version | tr -d '\"')\" node src/Bookmarklet/esbuild.mjs",
+ "build:opera": "PLASMO_TARGET=opera PLASMO_MANIFEST_VERSION=opera-mv3 npm run build:chrome && npm run bundle:opera",
+ "build:firefox": "PLASMO_NAME=jiffy-reader-firefox PLASMO_TARGET=firefox PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=firefox-mv2 npm run buildx && npm run bundle:firefox",
+ "build:safari": "PLASMO_NAME=jiffy-reader-safari PLASMO_TARGET=safari PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=safari-mv2 npm run buildx && npm run bundle:safari",
+ "gh:build:chrome": "PLASMO_TARGET=chrome PLASMO_SHORTCUT=\"Alt+B\" npm run buildx && npm run bundle:chrome",
+ "gh:build:opera": "PLASMO_TARGET=opera PLASMO_SHORTCUT=\"Alt+B\" PLASMO_MANIFEST_VERSION=opera-mv3 npm run buildx && npm run bundle:opera",
+ "gh:build:firefox": "PLASMO_TARGET=firefox PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=firefox-mv2 npm run buildx && npm run bundle:firefox",
+ "gh:build:safari": "PLASMO_TARGET=safari PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=safari-mv2 npm run buildx && npm run bundle:safari",
+ "gh:build": "echo 'PLASMO_TAG=prod NODE_ENV=production npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari & wait'",
+ "gh:build:development": "echo 'PLASMO_TAG=dev NODE_ENV=development PLASMO_NAME=Jiffy-Reader-Dev npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari & wait'",
+ "gh:build:bookmarklet": "PLASMO_VERSION=\"$(npm pkg get version | tr -d '\"')\" node src/Bookmarklet/esbuild.mjs",
"bundle": "npm run bundle:chrome & npm run bundle:firefix & npm run bundle:safari",
- "bundle:firefox": "cd build/firefox-mv2-prod/ && zip -r ../jiffyReader-firefox-$TAG.xpi ./*",
- "bundle:safari": "cd build/safari-mv2-prod/ && zip -r ../jiffyReader-safari-$TAG.xpi ./*",
- "bundle:chrome": "cd build/chrome-mv3-prod && zip -r ../jiffyReader-chrome-$TAG.zip ./*",
- "bundle:opera": "rm -rf build/opera-mv3-prod; cp -r build/chrome-mv3-prod build/opera-mv3-prod && cd build/opera-mv3-prod && zip -r ../jiffyReader-opera-$TAG.crx ./*",
+ "bundle:firefox": "cd build/firefox-mv2-$PLASMO_TAG/ && zip -r ../jiffyReader-firefox-$PLASMO_TAG.xpi ./*",
+ "bundle:safari": "cd build/safari-mv2-$PLASMO_TAG/ && zip -r ../jiffyReader-safari-$PLASMO_TAG.xpi ./*",
+ "bundle:chrome": "cd build/chrome-mv3-$PLASMO_TAG && zip -r ../jiffyReader-chrome-$PLASMO_TAG.zip ./*",
+ "bundle:opera": "cd build/opera-mv3-$PLASMO_TAG && zip -r ../jiffyReader-opera-$PLASMO_TAG.crx ./*",
"build:ios": "xcrun safari-web-extension-converter --rebuild-project \"Jiffy reader/Jiffy reader.xcodeproj\"",
"build:xcode": "pnpm build:safari && xcrun safari-web-extension-converter --swift --no-open --force --bundle-identifier com.jiffyreader build/safari-mv2-prod",
"build:xcode:all": "pnpm build:xcode && pnpm build:ios",
"dev:xcode": "xcrun safari-web-extension-converter --swift --no-open --force --bundle-identifier com.jiffyreader build/safari-mv2-dev",
"release": "if [ 0 -eq $(git log --oneline | head -n1 | grep 'chore(release)' | wc -l) ]; then commit-and-tag-version; fi",
- "lint": "prettier -w src/ ; eslint --fix src/",
- "test": "make -s build;# test is unstable';"
+ "lint": "eslint src/",
+ "lint:fix": "eslint --fix src/",
+ "test": "make -s build print-manifests; # test is unstable';"
},
"dependencies": {
"@plasmohq/prettier-plugin-sort-imports": "^1.1.1",
@@ -48,7 +49,8 @@
"postcss": "^8.4.49",
"react": "18.2.0",
"react-dom": "18.2.0",
- "webpack": "^4.47.0"
+ "webpack": "^4.47.0",
+ "zod": "^3.24.1"
},
"devDependencies": {
"@parcel/transformer-sass": "2.6.2",
@@ -72,13 +74,12 @@
"typescript": "4.7.4"
},
"manifest": {
- "name": "$NAME",
- "target": "$TARGET",
- "version": "$VERSION",
- "tag": "$TAG",
- "version_name": "$VERSION_NAME",
+ "name": "$PLASMO_NAME",
+ "target": "$PLASMO_TARGET",
+ "version": "$PLASMO_VERSION",
+ "tag": "$PLASMO_TAG",
+ "version_name": "$PLASMO_VERSION_NAME",
"environment": "$NODE_ENV",
- "scope": "$TAG",
"description": "A Browser Extension for Faster Reading on ANY website!",
"default_locale": "en",
"permissions": [
@@ -92,7 +93,7 @@
"commands": {
"toggle-bionic": {
"suggested_key": {
- "default": "$SHORTCUT"
+ "default": "$PLASMO_SHORTCUT"
},
"description": "Toggle bionic reading mode"
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 074e0bc..ace5e05 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -44,6 +44,9 @@ dependencies:
webpack:
specifier: ^4.47.0
version: 4.47.0
+ zod:
+ specifier: ^3.24.1
+ version: 3.24.1
devDependencies:
'@parcel/transformer-sass':
@@ -12198,3 +12201,7 @@ packages:
compress-commons: 4.1.2
readable-stream: 3.6.2
dev: false
+
+ /zod@3.24.1:
+ resolution: {integrity: sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==}
+ dev: false
diff --git a/src/Bookmarklet/esbuild.mjs b/src/Bookmarklet/esbuild.mjs
index 874e740..84f8168 100644
--- a/src/Bookmarklet/esbuild.mjs
+++ b/src/Bookmarklet/esbuild.mjs
@@ -7,7 +7,7 @@ const /** @type {import('esbuild').BuildOptions} */ defaultConfigs = {
minify: true,
write: false,
plugins: [sassPlugin({ type: 'css-text' })],
- define: { 'process.env.DEBUG': '"false"' },
+ define: { 'envService.DEBUG': '"false"' },
tsconfig: './tsconfig.json',
};
diff --git a/src/background/index.ts b/src/background/index.ts
index 88d53c6..b3d89d7 100644
--- a/src/background/index.ts
+++ b/src/background/index.ts
@@ -4,6 +4,7 @@ import M from 'mellowtel';
import { CONFIG_KEY, DISABLE_LOGS } from '~constants';
import { APP_PREFS_STORE_KEY, DisplayColorMode, STORAGE_AREA, USER_PREF_STORE_KEY } from '~services/config';
+import { envService } from '~services/envService';
import Logger from '~services/Logger';
import defaultPrefs from '~services/preferences';
import runTimeHandler from '~services/runTimeHandler';
@@ -33,14 +34,14 @@ const setBadgeText = (badgeTextDetails: chrome.action.BadgeTextDetails, runner =
return chrome?.action?.setBadgeText(badgeTextDetails) || browser.browserAction.setBadgeText(badgeTextDetails);
};
-const openInstallationWelcomePage = async (eventReason: chrome.runtime.OnInstalledReason, browserTargetName: string = process.env.PLASMO_TARGET) => {
+const openInstallationWelcomePage = async (eventReason: chrome.runtime.OnInstalledReason, browserTargetName: string = envService.PLASMO_TARGET) => {
// if (await storage.get(USER_PREF_STORE_KEY)) {
// return;
// }
chrome.tabs.create({
active: true,
- url: `https://jiffyreader.com/welcome?browser=${browserTargetName}&event=${eventReason}&version=${process.env.VERSION}`,
+ url: `https://jiffyreader.com/welcome?browser=${browserTargetName}&event=${eventReason}&version=${envService.VERSION}`,
});
};
@@ -148,7 +149,7 @@ async function onInstallHandler(event: chrome.runtime.InstalledDetails) {
const eventReason = event.reason;
- const newVersion = process.env.VERSION;
+ const newVersion = envService.VERSION;
const { previousVersion } = event;
const isNewVersion = previousVersion !== newVersion;
Logger.logInfo({ newVersion, previousVersion, isNewVersion });
@@ -161,7 +162,7 @@ async function onInstallHandler(event: chrome.runtime.InstalledDetails) {
previousVersion,
});
- if (isNewVersion && /install/i.test(eventReason) && process.env.NODE_ENV === 'production') {
+ if (isNewVersion && /install/i.test(eventReason) && envService.NODE_ENV === 'production') {
openInstallationWelcomePage(eventReason);
}
diff --git a/src/contents/content.tsx b/src/contents/content.tsx
index b6c0a15..631399b 100644
--- a/src/contents/content.tsx
+++ b/src/contents/content.tsx
@@ -5,6 +5,7 @@ import type { PlasmoContentScript } from 'plasmo';
import { useEffect, useState } from 'react';
import documentParser from '~services/documentParser';
+import { envService } from '~services/envService';
import Logger from '~services/Logger';
import overrides from '~services/siteOverrides';
import usePrefs from '~services/usePrefs';
@@ -160,35 +161,25 @@ const IndexContent = () => {
const getCollapseExpandBtn = () => ;
- const showDebugOverLay = (show) => {
- if (!show) return;
+ const showDebugOverLay = (show = !envService.isProduction) => {
+ if (show) return;
return (
- Target {process.env.PLASMO_TARGET}
+ Target {envService.PLASMO_TARGET}
{getCollapseExpandBtn()}
{!prefs || !tabSession ? 'Loading... or broken but probably loading' : 'JiffyReady to the moon'}
-
{JSON.stringify(tabSession)}
-
- {isExpanded &&
- prefs &&
- Object.entries(prefs).map(([key, val], index) => (
-
- {key}::
- {typeof val === 'boolean' ? (val === true ? 'true' : 'false') : val}
-
- ))}
-
+
{isExpanded && {JSON.stringify({ tabSession, prefs }, null, 2)}
}
{getCollapseExpandBtn()}
);
};
- return showDebugOverLay(process.env.NODE_ENV !== 'production');
+ return showDebugOverLay();
};
export default IndexContent;
diff --git a/src/popup/ShowInlineDebug.tsx b/src/popup/ShowInlineDebug.tsx
new file mode 100644
index 0000000..d2facea
--- /dev/null
+++ b/src/popup/ShowInlineDebug.tsx
@@ -0,0 +1,39 @@
+import type { TabSession } from 'index';
+import { envService } from '~services/envService';
+import TabHelper from '~services/TabHelper';
+import usePrefs, { usePrefStorage } from '~services/usePrefs';
+import { useShowDebugSwitch } from './shorcut';
+
+export function ShowDebugInline({ tabSession }: { tabSession: TabSession }) {
+ const [isDebugDataVisible, setIsDebugDataVisible] = useShowDebugSwitch();
+
+ const [prefs] = usePrefs(async () => await TabHelper.getTabOrigin(await TabHelper.getActiveTab(true)), true, envService.PLASMO_TARGET);
+
+ const [appConfigPrefs] = usePrefStorage();
+
+ if (envService.isProduction) return <>>;
+
+ const debugData = (
+ <>
+
+ tabSession {JSON.stringify({ tabSession, prefs, appConfigPrefs, envService }, null, 2)}
+
+ >
+ );
+
+ return (
+
+
+ {isDebugDataVisible && debugData}
+
+ );
+}
diff --git a/src/popup/context.tsx b/src/popup/context.tsx
index 631a6c4..ccaf997 100644
--- a/src/popup/context.tsx
+++ b/src/popup/context.tsx
@@ -1,5 +1,6 @@
import { Storage } from '@plasmohq/storage';
import { createContext, useContext, useEffect, useReducer } from 'react';
+import { envService } from '~services/envService';
let storage = {
key: 'context.store',
@@ -13,7 +14,7 @@ let storage = {
};
const rawValues = {
- isDebugDataVisible: !/production/i.test(process.env.NODE_ENV),
+ isDebugDataVisible: envService.showDebugInfo,
};
const initialPopupContextValue = {
diff --git a/src/popup/index.tsx b/src/popup/index.tsx
index c289a67..20f4e19 100644
--- a/src/popup/index.tsx
+++ b/src/popup/index.tsx
@@ -1,8 +1,7 @@
-import { useCallback, useEffect, useState } from 'react';
+import { useEffect, useState, type CSSProperties } from 'react';
import Logger from '~services/Logger';
import TabHelper from '~services/TabHelper';
-import usePrefs from '~services/usePrefs';
import './../styles/style.scss';
import './style.scss';
@@ -15,48 +14,45 @@ import documentParser from '~services/documentParser';
import runTimeHandler from '~services/runTimeHandler';
import TrackEventService, { EventCategory } from '~services/TrackEventService';
+import { envService } from '~services/envService';
import PopupContextProvider from './context';
import IndexPopupNew from './indexNew';
import IndexPopupOld from './indexOld';
-import { useShowDebugSwitch } from './shorcut';
-const badCapScroll = /safari/i.test(process.env.PLASMO_TARGET) ? { overflowY: 'scroll', height: '600px' } : {};
+const badCapScroll: CSSProperties = /safari/i.test(envService.PLASMO_TARGET) ? { overflowY: 'scroll', height: '600px' } : {};
-const DisplayVersion = ({ displayVersion }) => {
- if (displayVersion === 'old') return ;
- else if (displayVersion === 'new') return ;
+const PopupVersions = {
+ new: IndexPopupNew,
+ old: IndexPopupOld,
+};
+const DisplayVersion = ({ displayVersionKey }: { displayVersionKey: keyof typeof PopupVersions }) => {
+ const PopupVersion = PopupVersions[displayVersionKey];
+ return ;
};
const popupLogStyle = 'background:cyan;color:brown';
const jiffyLogo = chrome.runtime.getURL('./assets/icon512.png');
-const { setAttribute, setProperty, getProperty, getAttribute, setSaccadesStyle } = documentParser.makeHandlers(document);
-
const SHOW_FOOTER_MESSAGE_DURATION = 12_000;
const FOOT_MESSAGAES_ANIMATION_DELAY = 300;
const FIRST_FOOTER_MESSAGE_INDEX = 1;
function IndexPopup() {
- const [activeTab, setActiveTab] = useState(null as chrome.tabs.Tab);
- const [footerMessageIndex, setFooterMeessageIndex] = useState(null);
- const [isDebugDataVisible, setIsDebugDataVisible] = useShowDebugSwitch();
-
- const getTabOriginfn = useCallback(async () => await TabHelper.getTabOrigin(await TabHelper.getActiveTab(true)), [TabHelper]);
-
- const [prefs, setPrefs] = usePrefs(getTabOriginfn, true, process.env.PLASMO_TARGET);
+ const [, setActiveTab] = useState(null);
+ const [footerMessageIndex, setFooterMeessageIndex] = useState(null);
const [tabSession, setTabSession] = useState(null);
- const [tipsVisibility, setTipsVisibility] = useState(false);
-
const [appConfigPrefs, setAppConfigPrefs] = useStorage({
key: APP_PREFS_STORE_KEY,
area: STORAGE_AREA,
});
const footerMessagesLength = 3;
- const nextMessageIndex = (oldFooterMessageIndex) => (typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength);
+
+ const nextMessageIndex = (oldFooterMessageIndex: typeof footerMessageIndex) =>
+ typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength;
useEffect(() => {
if (!tabSession) return;
@@ -74,9 +70,10 @@ function IndexPopup() {
const origin = await TabHelper.getTabOrigin(_activeTab);
- const brMode = chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => {
- setTabSession({ brMode: data, origin });
- });
+ _activeTab.id &&
+ chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => {
+ setTabSession({ brMode: data, origin });
+ });
})();
runTimeHandler.runtime.onMessage.addListener((request, sender, sendResponse) => {
@@ -96,7 +93,7 @@ function IndexPopup() {
}
});
- let footerInterval;
+ let footerInterval: NodeJS.Timer;
setTimeout(() => {
setFooterMeessageIndex(nextMessageIndex);
@@ -134,7 +131,7 @@ function IndexPopup() {
{/* display goes here */}
-
+
diff --git a/src/popup/indexNew.tsx b/src/popup/indexNew.tsx
index ed6b450..6cf48a5 100644
--- a/src/popup/indexNew.tsx
+++ b/src/popup/indexNew.tsx
@@ -16,7 +16,9 @@ import documentParser from '~services/documentParser';
import defaultPrefs from '~services/preferences';
import runTimeHandler from '~services/runTimeHandler';
-import Shortcut, { ShortcutGuide, useShowDebugSwitch } from './shorcut';
+import { envService } from '~services/envService';
+import Shortcut, { ShortcutGuide } from './shorcut';
+import { ShowDebugInline } from './ShowInlineDebug';
const popupLogStyle = 'background:cyan;color:brown';
@@ -24,7 +26,7 @@ const darkToggle = chrome.runtime.getURL('./assets/moon-solid.svg');
const lightToggle = chrome.runtime.getURL('./assets/sun-light-solid.svg');
const jiffyLogo = chrome.runtime.getURL('./assets/icon512.png');
-const { setAttribute, setProperty, getProperty, getAttribute, setSaccadesStyle } = documentParser.makeHandlers(document);
+const { setAttribute, setProperty, setSaccadesStyle } = documentParser.makeHandlers(document);
const FIXATION_OPACITY_STOPS = 5;
const FIXATION_OPACITY_STOP_UNIT_SCALE = Math.floor(100 / FIXATION_OPACITY_STOPS);
@@ -34,15 +36,14 @@ const FOOT_MESSAGAES_ANIMATION_DELAY = 300;
const FIRST_FOOTER_MESSAGE_INDEX = 1;
function IndexPopupNew() {
- const [activeTab, setActiveTab] = useState(null as chrome.tabs.Tab);
- const [footerMessageIndex, setFooterMeessageIndex] = useState(null);
- const [isDebugDataVisible, setIsDebugDataVisible] = useShowDebugSwitch();
+ const [activeTab, setActiveTab] = useState(null);
+ const [footerMessageIndex, setFooterMeessageIndex] = useState(null);
const getTabOriginfn = useCallback(async () => await TabHelper.getTabOrigin(await TabHelper.getActiveTab(true)), [TabHelper]);
- const [prefs, setPrefs] = usePrefs(getTabOriginfn, true, process.env.PLASMO_TARGET);
+ const [prefs, setPrefs] = usePrefs(getTabOriginfn, true, envService.PLASMO_TARGET);
- const [tabSession, setTabSession] = useState(null);
+ const [tabSession, setTabSession] = useState(null);
const [tipsVisibility, setTipsVisibility] = useState(false);
@@ -52,7 +53,8 @@ function IndexPopupNew() {
});
const footerMessagesLength = 3;
- const nextMessageIndex = (oldFooterMessageIndex) => (typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength);
+ const nextMessageIndex = (oldFooterMessageIndex: typeof footerMessageIndex) =>
+ typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength;
useEffect(() => {
if (!tabSession) return;
@@ -80,9 +82,10 @@ function IndexPopupNew() {
const origin = await TabHelper.getTabOrigin(_activeTab);
- const brMode = chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => {
- setTabSession({ brMode: data, origin });
- });
+ _activeTab.id &&
+ chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => {
+ setTabSession({ brMode: data, origin });
+ });
})();
runTimeHandler.runtime.onMessage.addListener((request, sender, sendResponse) => {
@@ -102,7 +105,7 @@ function IndexPopupNew() {
}
});
- let footerInterval;
+ let footerInterval: NodeJS.Timer;
setTimeout(() => {
setFooterMeessageIndex(nextMessageIndex);
@@ -141,7 +144,7 @@ function IndexPopupNew() {
TabHelper.getActiveTab(true).then((tab) => chrome.tabs.sendMessage(tab.id, payload, () => Logger.LogLastError()));
};
- const handleDisplayColorModeChange = async (currentDisplayColorMode) => {
+ const handleDisplayColorModeChange = async (currentDisplayColorMode: DisplayColorMode) => {
console.log('handleDisplayColorModeChange', currentDisplayColorMode);
if (![...Object.values(DisplayColorMode)].includes(currentDisplayColorMode)) {
@@ -165,35 +168,6 @@ function IndexPopupNew() {
return 'animated-footer-link ' + (index === footerMessageIndex && ' animated-footer-link-show');
};
- function showDebugInline(environment = 'production') {
- if (/production/i.test(environment)) return;
-
- const debugData = (
- <>
- tabSession {JSON.stringify(tabSession)}
- prefs: {JSON.stringify(prefs)}
- appConfigPrefs: {JSON.stringify(appConfigPrefs)}
- footerMessageIndex: {footerMessageIndex}
- >
- );
-
- return (
-
-
- {isDebugDataVisible && debugData}
-
- );
- }
-
const reloadActiveTab = async (_activeTab = activeTab) => {
await chrome.tabs.reload(_activeTab.id).then(() => window.close());
};
@@ -211,7 +185,7 @@ function IndexPopupNew() {
};
const showFileUrlPermissionRequestMessage = (tabSession: TabSession, prefs, _activeTab = activeTab) => {
- if (!/chrome/i.test(process.env.PLASMO_TARGET) || !/^file:\/\//i.test(tabSession?.origin ?? activeTab?.url) || prefs) {
+ if (!/chrome/i.test(envService.PLASMO_TARGET) || !/^file:\/\//i.test(tabSession?.origin ?? activeTab?.url) || prefs) {
return null;
}
@@ -265,9 +239,11 @@ function IndexPopupNew() {
const errorOccured = !prefs || !tabSession;
+ console.log({ tabSession, prefs });
+
return (
<>
- {showDebugInline(process.env.NODE_ENV)}
+
{errorOccured ? (
showErrorMessage()
) : (
@@ -375,7 +351,7 @@ function IndexPopupNew() {
{chrome.i18n.getMessage('shortcutLabelText')}:
{chrome.i18n.getMessage(
- /firefox/i.test(process.env.PLASMO_TARGET) ? 'defaultShortcutValueTextFirefox' : 'defaultShortcutValueTextChrome',
+ /firefox/i.test(envService.PLASMO_TARGET) ? 'defaultShortcutValueTextFirefox' : 'defaultShortcutValueTextChrome',
)}
*/}
@@ -563,7 +539,7 @@ function Footer({ textColor = 'text-secondary', chrome, onClickPasser }) {
-
{process.env.VERSION_NAME}
+
{envService.VERSION_NAME}
{/*
-
{process.env.VERSION_NAME}
+
{envService.VERSION_NAME}
);
- const showDebugInline = (environment = 'production') => {
- if (/production/i.test(environment)) return;
-
- const debugData = (
- <>
-
tabSession {JSON.stringify(tabSession)}
-
prefs: {JSON.stringify(prefs)}
-
appConfigPrefs: {JSON.stringify(appConfigPrefs)}
-
footerMessageIndex: {footerMessageIndex}
- >
- );
-
- return (
-
-
- {isDebugDataVisible && debugData}
-
- );
- };
-
const reloadActiveTab = async (_activeTab = activeTab) => {
await chrome.tabs.reload(_activeTab.id);
};
@@ -254,7 +224,7 @@ function IndexPopupOld() {
};
const showFileUrlPermissionRequestMessage = (tabSession: TabSession, prefs, _activeTab = activeTab) => {
- if (!/chrome/i.test(process.env.PLASMO_TARGET) || !/^file:\/\//i.test(tabSession?.origin ?? activeTab?.url) || prefs) {
+ if (!/chrome/i.test(envService.PLASMO_TARGET) || !/^file:\/\//i.test(tabSession?.origin ?? activeTab?.url) || prefs) {
return null;
}
@@ -316,7 +286,8 @@ function IndexPopupOld() {
return (
<>
- {showDebugInline(process.env.NODE_ENV)}
+
+
{errorOccured ? (
showErrorMessage(openSettingsPage)
) : (
diff --git a/src/services/Logger.ts b/src/services/Logger.ts
index 582f4fd..624106c 100644
--- a/src/services/Logger.ts
+++ b/src/services/Logger.ts
@@ -3,6 +3,8 @@
* provide development utility functions for reporting errors, logging data and logging time
*/
+import { envService } from './envService';
+
/**
* @description stateMachine of debug to cantDebug states
*/
@@ -11,15 +13,11 @@ const debugStates = new Map([
['false', true],
]);
-/* eslint-disable no-console */
-const cantDebug = (debugState: string = 'false') => {
- const key = debugState.toLowerCase();
- return debugStates.has(key) && debugStates.get(key);
-};
+const cantDebug = (shouldDebug: boolean = false) => !shouldDebug;
const nullCallback = () => null;
-const maker =
(fn: T): T => (cantDebug(process.env.DEBUG) ? nullCallback : fn) as T;
+const maker = (fn: T): T => (envService.DEBUG ? nullCallback : fn) as T;
/**
*
@@ -27,7 +25,7 @@ const maker = (fn: T): T => (cantDebug(process.env.DEBUG) ? nullCallback : fn
* @returns {Function} end and display time when called in non production environment
*/
const logTime = (label) => {
- if (cantDebug(process.env.DEBUG)) return () => nullCallback;
+ if (cantDebug(envService.DEBUG)) return () => nullCallback;
console.time(label);
return () => console.timeEnd(label);
diff --git a/src/services/TrackEventService.ts b/src/services/TrackEventService.ts
index b035056..8cdb5e7 100644
--- a/src/services/TrackEventService.ts
+++ b/src/services/TrackEventService.ts
@@ -1,3 +1,4 @@
+import { envService } from './envService';
import Logger from './Logger';
export enum EventCategory {
@@ -8,9 +9,9 @@ export enum EventCategory {
function trackEvent(
eventData: { eventCategory: EventCategory; eventName: string; eventType: string; [key: string]: any },
- appData: { browser; version } = { browser: process.env.PLASMO_TARGET, version: process.env.VERSION },
+ appData = { browser: envService.PLASMO_TARGET, version: envService.VERSION },
date = new Date(),
- enableTracking = /true/.test(process.env.ENABLE_TRACKING),
+ enableTracking = envService.ENABLE_TRACKING,
) {
Logger.logInfo({ enableTracking });
if (!enableTracking) {
@@ -19,7 +20,7 @@ function trackEvent(
const params = new URLSearchParams({ ...{ time: date.toString(), time_iso: date.toISOString(), ...eventData }, ...appData });
Logger.logInfo('track-event', params.toString());
- return fetch(process.env.HOME_URL ?? 'https://jiffyreader.com' + `/track-event?${params.toString()}`);
+ return fetch(envService.HOME_URL ?? 'https://jiffyreader.com' + `/track-event?${params.toString()}`);
}
const TrackEventService = {
diff --git a/src/services/config.ts b/src/services/config.ts
index 00cef46..74a893d 100644
--- a/src/services/config.ts
+++ b/src/services/config.ts
@@ -1,6 +1,7 @@
+import { envService } from '~services/envService';
export const USER_PREF_STORE_KEY = 'prefStore';
export const APP_PREFS_STORE_KEY = 'appStore';
-export const STORAGE_AREA = ((process.env.PLASMO_TARGET as string).includes('firefox') && 'local') || 'sync';
+export const STORAGE_AREA = ((envService.PLASMO_TARGET as string).includes('firefox') && 'local') || 'sync';
export const COLOR_MODE_STATE_TRANSITIONS = [
[null, 'light'],
diff --git a/src/services/envService.ts b/src/services/envService.ts
new file mode 100644
index 0000000..f15c46f
--- /dev/null
+++ b/src/services/envService.ts
@@ -0,0 +1,81 @@
+import { z } from 'zod';
+
+const booleanMap = new Map<'true' | 'false' | undefined, boolean>([
+ ['true', true],
+ ['false', false],
+ [undefined, false],
+]);
+
+const env = {
+ PLASMO_VERSION: { value: process.env.PLASMO_VERSION, validator: z.string().optional() },
+ PLASMO_VERSION_NAME: { value: process.env.PLASMO_VERSION_NAME, validator: z.string().optional() },
+ PLASMO_TARGET: {
+ value: process.env.PLASMO_TARGET,
+ validator: z
+ .string()
+ .default('')
+ .transform((x) => x as typeof process.env.PLASMO_TARGET),
+ },
+ NODE_ENV: {
+ value: process.env.NODE_ENV,
+ validator: z
+ .string()
+ .optional()
+ .transform((x) => x as typeof process.env.NODE_ENV),
+ },
+ PLASMO_DEBUG: {
+ value: process.env.PLASMO_DEBUG,
+ validator: z
+ .boolean()
+ .or(
+ z
+ .enum(['true', 'false'])
+ // .optional()
+ // .default('true')
+ .transform((x) => booleanMap.get(x as keyof typeof booleanMap.keys)),
+ )
+ .default(false),
+ },
+ PLASMO_ENABLE_TRACKING: {
+ value: process.env.PLASMO_ENABLE_TRACKING,
+ validator: z
+ .boolean()
+ .or(
+ z
+ .enum(['true', 'false'])
+ .optional()
+ .default('false')
+ .transform((x) => booleanMap.get(x as keyof typeof booleanMap.keys)),
+ )
+ .default(false),
+ },
+ PLASMO_HOME_URL: { value: process.env.PLASMO_HOME_URL, validator: z.string().optional() },
+};
+
+type Env = typeof env;
+
+console.log({ env });
+
+let envSchema = z.object(Object.fromEntries(Object.entries(env).map(([key, { validator }]) => [key, validator])) as { [K in keyof Env]: Env[K]['validator'] });
+let envSelection = Object.fromEntries(Object.entries(env).map(([key, { value }]) => [key, value])) as (typeof process)['env'];
+let sourceEnv: z.infer;
+
+try {
+ sourceEnv = envSchema.parse(envSelection);
+} catch (error) {
+ const zerr = JSON.stringify((error as z.ZodError).flatten(), null, 2);
+ console.error(zerr);
+ throw new Error(zerr);
+}
+
+const envService = {
+ ...sourceEnv,
+ get isProduction(): boolean {
+ return /production/i.test(this.NODE_ENV);
+ },
+ get showDebugInfo(): boolean {
+ return !this.isProduction;
+ },
+};
+
+export { envService };
diff --git a/src/services/siteOverrides.ts b/src/services/siteOverrides.ts
index 20aa612..5e0efd5 100644
--- a/src/services/siteOverrides.ts
+++ b/src/services/siteOverrides.ts
@@ -6,6 +6,7 @@ import Logger from '~services/Logger';
const siteOverrides = {
'play.google.com': `[br-mode=on] reader-rendered-page { overflow: auto !important; }`,
+ 'reddit.com': 'br-span, br-bold, br-fixation, br-edge { visibility : visible !important; }',
};
/**
diff --git a/src/services/usePrefs.tsx b/src/services/usePrefs.tsx
index 676811e..beef80f 100644
--- a/src/services/usePrefs.tsx
+++ b/src/services/usePrefs.tsx
@@ -2,13 +2,15 @@ import { Storage, useStorage } from '@plasmohq/storage';
import type { Prefs, PrefStore, SetPrefsExternal } from 'index';
import { useEffect, useState } from 'react';
+import { APP_PREFS_STORE_KEY, STORAGE_AREA } from './config';
+import { envService } from './envService';
import Logger from './Logger';
import defaultPrefs from './preferences';
const PREF_STORE_SCOPES = ['global', 'local', 'reset'];
const PREF_LOG_STYLE = 'color: green; background: black;';
-const usePrefs = (getOrigin: () => Promise, initialize = false, target = process.env.PLASMO_TARGET ?? 'chrome'): [Prefs, SetPrefsExternal] => {
+const usePrefs = (getOrigin: () => Promise, initialize = false, target = envService.PLASMO_TARGET ?? 'chrome'): [Prefs, SetPrefsExternal] => {
const [privateOrigin, setPrivateOrigin] = useState(null);
const area = ((target as string).includes('firefox') && 'local') || 'sync';
@@ -89,3 +91,9 @@ const usePrefs = (getOrigin: () => Promise, initialize = false, target =
};
export default usePrefs;
+
+export const usePrefStorage = () =>
+ useStorage({
+ key: APP_PREFS_STORE_KEY,
+ area: STORAGE_AREA,
+ });