From 57c2efff4da3faed1f9ec1ef82fbcf6962c7de08 Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Wed, 26 Apr 2023 10:14:56 +0800 Subject: [PATCH 001/333] fix: compatibility for Safari < 15.4 (#472) * fix: add polyfill `Object.hasOwn` --- src/shared/settings.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/shared/settings.js b/src/shared/settings.js index 127f1bdb..2a68635c 100644 --- a/src/shared/settings.js +++ b/src/shared/settings.js @@ -354,6 +354,12 @@ function deepFreeze(object) { return Object.freeze(object); } +// @todo remove this polyfill when browser limitation is set above 15.4 +// compatibility polyfill for Safari < 15.4 +if (Object.hasOwn === undefined) { + Object.hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); +} + // export and define the operation method of settings storage // they are similar to browser.storage but slightly different From cc4232220b414600786cc6af7eea4e25355ffd04 Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Wed, 26 Apr 2023 10:20:28 +0800 Subject: [PATCH 002/333] build: v4.4.1(71), v1.4.1(44) --- xcode/xcconfig/Userscripts-Release.xcconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/xcconfig/Userscripts-Release.xcconfig b/xcode/xcconfig/Userscripts-Release.xcconfig index 9a90bb36..4a1de205 100644 --- a/xcode/xcconfig/Userscripts-Release.xcconfig +++ b/xcode/xcconfig/Userscripts-Release.xcconfig @@ -1,9 +1,9 @@ #include "Userscripts-Base.xcconfig" INFOPLIST_KEY_NSHumanReadableCopyright = Copyright © 2018–2023 Justin Wasack. All rights reserved. -IOS_APP_BUILD = 43 +IOS_APP_BUILD = 44 IOS_APP_VERSION = 1.4.1 -MAC_APP_BUILD = 70 +MAC_APP_BUILD = 71 MAC_APP_VERSION = 4.4.1 // Developer Team ID From 991363485c412a97fe7a36c6e4d13e9713642834 Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Thu, 27 Apr 2023 06:41:50 +0800 Subject: [PATCH 003/333] fix: gm xhr api broken This reverts commit fe363e36d0bf6c16c5068a16370711fd0ec12aee. --- xcode/Safari-Extension/Resources/content.js | 1 - 1 file changed, 1 deletion(-) diff --git a/xcode/Safari-Extension/Resources/content.js b/xcode/Safari-Extension/Resources/content.js index b29798d1..85c62f9a 100644 --- a/xcode/Safari-Extension/Resources/content.js +++ b/xcode/Safari-Extension/Resources/content.js @@ -214,7 +214,6 @@ const apis = { }; // remote window's browser object delete window.browser; -delete window.chrome; // label used to distinguish frames in console const label = randomLabel(); From ded7fce87051b9dcfc084e029004ccc2f4217090 Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Thu, 27 Apr 2023 06:52:06 +0800 Subject: [PATCH 004/333] build: v4.4.1(72), v1.4.1(45) --- xcode/xcconfig/Userscripts-Release.xcconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/xcconfig/Userscripts-Release.xcconfig b/xcode/xcconfig/Userscripts-Release.xcconfig index 4a1de205..6ece3097 100644 --- a/xcode/xcconfig/Userscripts-Release.xcconfig +++ b/xcode/xcconfig/Userscripts-Release.xcconfig @@ -1,9 +1,9 @@ #include "Userscripts-Base.xcconfig" INFOPLIST_KEY_NSHumanReadableCopyright = Copyright © 2018–2023 Justin Wasack. All rights reserved. -IOS_APP_BUILD = 44 +IOS_APP_BUILD = 45 IOS_APP_VERSION = 1.4.1 -MAC_APP_BUILD = 71 +MAC_APP_BUILD = 72 MAC_APP_VERSION = 4.4.1 // Developer Team ID From e41de420c3d9a98f6527404f3d1aaa8b70d8a0a6 Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Mon, 1 May 2023 01:46:49 +0800 Subject: [PATCH 005/333] fix: properly discharge xhr resources (#476) --- xcode/Safari-Extension/Resources/background.js | 2 +- xcode/Safari-Extension/Resources/content.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/xcode/Safari-Extension/Resources/background.js b/xcode/Safari-Extension/Resources/background.js index 7eae15e0..9b860642 100644 --- a/xcode/Safari-Extension/Resources/background.js +++ b/xcode/Safari-Extension/Resources/background.js @@ -424,7 +424,7 @@ function handleMessage(request, sender, sendResponse) { }); // handle port disconnect and clean tasks port.onDisconnect.addListener(p => { - if (p.error) { + if (p?.error) { console.error(`port disconnected due to an error: ${p.error.message}`); } }); diff --git a/xcode/Safari-Extension/Resources/content.js b/xcode/Safari-Extension/Resources/content.js index 85c62f9a..2060a321 100644 --- a/xcode/Safari-Extension/Resources/content.js +++ b/xcode/Safari-Extension/Resources/content.js @@ -178,17 +178,17 @@ const apis = { } // call userscript method details[msg.name](msg.response); - // all messages received - // tell background it's safe to close port - if (msg.name === "onloadend") { - port.postMessage({name: "DISCONNECT"}); - } + } + // all messages received + // tell background it's safe to close port + if (msg.name === "onloadend") { + port.postMessage({name: "DISCONNECT"}); } }); // handle port disconnect and clean tasks port.onDisconnect.addListener(p => { - if (p.error) { + if (p?.error) { console.error(`port disconnected due to an error: ${p.error.message}`); } browser.runtime.onConnect.removeListener(listener); From eb797f277b549fa0ec681369ff50638d79f20fdf Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Mon, 1 May 2023 02:44:11 +0800 Subject: [PATCH 006/333] refactor: disable badge for ios --- xcode/Safari-Extension/Resources/background.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xcode/Safari-Extension/Resources/background.js b/xcode/Safari-Extension/Resources/background.js index 9b860642..053d808d 100644 --- a/xcode/Safari-Extension/Resources/background.js +++ b/xcode/Safari-Extension/Resources/background.js @@ -82,7 +82,10 @@ function setClipboard(data, type = "text/plain") { async function setBadgeCount() { const clearBadge = () => browser.browserAction.setBadgeText({text: ""}); - // TODO: after the background script is modularized, import and use: + // @todo until better introduce in ios, only set badge on macOS + const platform = await getPlatform(); + if (platform !== "macos") return clearBadge(); + // @todo after the background script is modularized, import and use: // settingsStorage.get(["global_active","toolbar_badge_count","global_exclude_match"]) const results = await browser.storage.local.get(["US_GLOBAL_ACTIVE", "US_TOOLBAR_BADGE_COUNT"]); if (results?.US_GLOBAL_ACTIVE === false) return clearBadge(); @@ -96,7 +99,7 @@ async function setBadgeCount() { if (!url) return clearBadge(); // only check for http/s pages if (!url.startsWith("http://") && !url.startsWith("https://")) return clearBadge(); - // TODO: if url match in global exclude list, clear badge + // @todo if url match in global exclude list, clear badge const frameUrls = new Set(); const frames = await browser.webNavigation.getAllFrames({tabId: currentTab.id}); for (let i = 0; i < frames.length; i++) { From 6a578360c996c4c042c29290ca61f7650ca2863a Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Mon, 1 May 2023 10:50:18 +0800 Subject: [PATCH 007/333] fix: disable dnr below safari 15.4 (#477) --- xcode/Safari-Extension/Resources/background.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xcode/Safari-Extension/Resources/background.js b/xcode/Safari-Extension/Resources/background.js index 053d808d..12505364 100644 --- a/xcode/Safari-Extension/Resources/background.js +++ b/xcode/Safari-Extension/Resources/background.js @@ -130,6 +130,8 @@ async function setBadgeCount() { } async function setSessionRules() { + // not supported below safari 15.4 + if (!browser.declarativeNetRequest.updateSessionRules) return; await clearAllSessionRules(); const message = {name: "REQ_REQUESTS"}; const response = await browser.runtime.sendNativeMessage(message); From 4a04198db8c7bd249d49ae37f604297627dbfb25 Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Fri, 5 May 2023 09:03:37 +0800 Subject: [PATCH 008/333] fix: revive javascript linter in editor page (#481) --- .eslintrc.json | 3 ++- .gitattributes | 1 + docs/dev.md | 2 ++ docs/structure.md | 28 ++++++++++++++++++++++++++++ entry-page.html | 1 + public/page/jshint.min.js | 28 ++++++++++++++++++++++++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 docs/structure.md create mode 100644 public/page/jshint.min.js diff --git a/.eslintrc.json b/.eslintrc.json index d51e455f..c84c97d1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -15,7 +15,8 @@ "/etc", "build", "dist", - "node_modules" + "node_modules", + "public" ], "overrides": [ { diff --git a/.gitattributes b/.gitattributes index 5c4dc3ba..d85906ec 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ pnpm-lock.yaml linguist-generated +public linguist-generated xcode/iOS-App/Base.lproj/Main.html linguist-generated \ No newline at end of file diff --git a/docs/dev.md b/docs/dev.md index 861fd35d..8a8a331b 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -2,6 +2,8 @@ The `root` directory is a typical multi-page app of Vite with Svelte JavaScript The `xcode` directory is the root of the Xcode project where the Safari extension app is built. +For other directory structure instructions, please refer to [structure.md](structure.md). + # Environment - [`Node.js`](https://nodejs.dev/en/learn/how-to-install-nodejs/) - [`pnpm`](https://pnpm.io/installation) (optional) diff --git a/docs/structure.md b/docs/structure.md new file mode 100644 index 00000000..5cefc590 --- /dev/null +++ b/docs/structure.md @@ -0,0 +1,28 @@ +# Project directory structure +For development and build environments please refer to [development guide](dev.md). + +## `docs` +Store documents and project description files, etc. + +## `etc` +Readme references and project history assets + +## `public` +Project Static Asset +https://vitejs.dev/guide/assets.html#the-public-directory + +### `./public/page/jshint.min.js` +CodeMirror 5 `codemirror/addon/lint/javascript-lint.js` depends on `jshint.js` +https://codemirror.net/5/doc/manual.html#addon_lint +https://github.com/jshint/jshint/blob/main/dist/jshint.js + +## `src` +Project Web App Source Code +Build the project from here to extension resources + +## `xcode` +Project Native App Source Code +Build the project from here to extension bundle app + +# About +[Userscripts](https://github.com/quoid/userscripts) @ 2018-2023 \ No newline at end of file diff --git a/entry-page.html b/entry-page.html index 2e585fc0..82a9df6b 100644 --- a/entry-page.html +++ b/entry-page.html @@ -10,5 +10,6 @@
+