From 4efb1cc2803c002a747c1b496b9bf26745da69eb Mon Sep 17 00:00:00 2001 From: Ng Guoyou Date: Sat, 4 May 2024 16:53:37 +0800 Subject: [PATCH] fix: Firefox settings no longer disabled on the options page when in Firefox (#214) --- CHANGELOG.md | 262 +++++++++++++++++++++-------------------- manifest.json | 2 +- package.json | 2 +- src/chrome-detector.js | 5 +- src/options/options.js | 47 +++++--- 5 files changed, 169 insertions(+), 149 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4267001..20295ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,95 +1,99 @@ +# 3.7.3 + +- Firefox settings no longer disabled on the options page when in Firefox (#214) + # 3.7.2 -* Fix light mode icon again +- Fix light mode icon again # 3.7.1 -* Fix invalid default menu configuration -* Now notifies by default for successful downloads -* Fix light mode icon for last used menu item being white -* Refactor context menu creation, might help with #200 +- Fix invalid default menu configuration +- Now notifies by default for successful downloads +- Fix light mode icon for last used menu item being white +- Refactor context menu creation, might help with #200 # 3.7.0 -This update might require a change in your muscle memories. Previously all submenus of the same depth would have their shortcut keys increment even if they had different parents. That's now been fixed. Thanks, +This update might require a change in your muscle memories. Previously all submenus of the same depth would have their shortcut keys increment even if they had different parents. That's now been fixed. Thanks, @mfaizsyahmi! If you want to use your old buggy shortcut again, use the new `(key: )` comment (eg, `menu // (key: 1)`), which will override the automatically-assigned shortcut with `1`. -* Reset accessKey count on every submenu. (#198, #199). Thanks @mfaizsyahmi! -* Add new meta comment to override accessKey -* Use white icon for previous entry in dark mode (#184) -* Add basic history to options page (#159) +- Reset accessKey count on every submenu. (#198, #199). Thanks @mfaizsyahmi! +- Add new meta comment to override accessKey +- Use white icon for previous entry in dark mode (#184) +- Add basic history to options page (#159) It's been difficult getting motivation to work on save-in, especially with the poor code quality, stalled TypeScript changes, and impending v3 manifest changes. Sorry if I've disappointed anyone! I still have grand dreams of rewriting this extension to make it maintainable, but my energy is being and has been sucked up by $DAY_JOB! # 3.6.0 -* Add support for multiple `capture` clauses (#160, @MaddyKakkoHeart) +- Add support for multiple `capture` clauses (#160, @MaddyKakkoHeart) # 3.5.3 -* Add "fetch via Fetch API" option for some incompatible sites (eg, Instagram) (#166) -* Upgrade webextension-polyfill to 0.8.0 +- Add "fetch via Fetch API" option for some incompatible sites (eg, Instagram) (#166) +- Upgrade webextension-polyfill to 0.8.0 # 3.5.2 -* Refactor `legacyDownloadInfo` out from code -* Fix some potential bugs with filename and source URL routing -* Fix dashes in aliases breaking download paths (#124) -* Fix separators in submenus not being treated as special directories (#117) -* Fix Click-to-save not working for middle and right mouse buttons (#116) -* Fix text not visible in dark mode (#112) -* Update sv localisation (#119, @Sopor) -* Update vendored mozilla/webextension-polyfill to 0.5 +- Refactor `legacyDownloadInfo` out from code +- Fix some potential bugs with filename and source URL routing +- Fix dashes in aliases breaking download paths (#124) +- Fix separators in submenus not being treated as special directories (#117) +- Fix Click-to-save not working for middle and right mouse buttons (#116) +- Fix text not visible in dark mode (#112) +- Update sv localisation (#119, @Sopor) +- Update vendored mozilla/webextension-polyfill to 0.5 # 3.5.0 -* Make options page support dark mode for Firefox (#112) -* Add unofficially (unsupported) onMessageExternal listener for use with other extensions such as Foxy Gestures (#110) +- Make options page support dark mode for Firefox (#112) +- Add unofficially (unsupported) onMessageExternal listener for use with other extensions such as Foxy Gestures (#110) See wiki at https://github.com/gyng/save-in/wiki/Use-with-Foxy-Gestures # 3.4.1 -* Fix `Referer` header not set in Chrome >= 72 (#66) -* Check if download originates from save-in before renaming download (Chrome, #109) -* Add favicon to options page (#108) +- Fix `Referer` header not set in Chrome >= 72 (#66) +- Check if download originates from save-in before renaming download (Chrome, #109) +- Add favicon to options page (#108) # 3.4.0 -* Add option to always prefer links when downloading from pages that match a regex list of URLs (#100) -* Add notification option for when a link is downloaded instead of the source -* Add option to close tabs marked for saving (FF, #68) +- Add option to always prefer links when downloading from pages that match a regex list of URLs (#100) +- Add notification option for when a link is downloaded instead of the source +- Add option to close tabs marked for saving (FF, #68) # 3.3.0 -* Add downloading of multiple highlighted tabs (FF63, #91) -* Enable access keys for Firefox >= 63 (#91) -* Add sv localisation by @Sopor- (#98, #99) +- Add downloading of multiple highlighted tabs (FF63, #91) +- Enable access keys for Firefox >= 63 (#91) +- Add sv localisation by @Sopor- (#98, #99) # 3.2.0 -* Add option to set `Referer` header on downloads, disabled by default. Should fix errors while downloading for sites that check this, especially pixiv.net in Chrome. Requires new permissions. (#66) +- Add option to set `Referer` header on downloads, disabled by default. Should fix errors while downloading for sites that check this, especially pixiv.net in Chrome. Requires new permissions. (#66) # 3.1.3 -* Fix submenus not tracking parent menu item -* Fix submenu items having duplicate IDs +- Fix submenus not tracking parent menu item +- Fix submenu items having duplicate IDs # 3.1.2 -* Fix export settings not exporting updated settings after changing them (#83) -* Improve checkmark styling in options page (#84) +- Fix export settings not exporting updated settings after changing them (#83) +- Improve checkmark styling in options page (#84) # 3.1.1 -* Fix neighbouring submenus nesting when they should not +- Fix neighbouring submenus nesting when they should not # 3.1.0 -* Add nl localisation (Thanks @80486dx, #72) +- Add nl localisation (Thanks @80486dx, #72) -* Add menu item aliasing (#64) +- Add menu item aliasing (#64) To use this, put an `(alias: )` in the comments for that line. For example: @@ -97,7 +101,7 @@ It's been difficult getting motivation to work on save-in, especially with the p cats // (alias: actually dogs) ``` -* Add submenu support (#26) +- Add submenu support (#26) To use this, add `>`s at the start of the line. For example: @@ -110,88 +114,88 @@ It's been difficult getting motivation to work on save-in, especially with the p # 3.0.0 -* Fix Chrome rules matching against `_`, now matches against special characters instead -* Add variables view to last download in options -* Fix routing failing in some cases (regression) (#80) -* Fix last used access key not working at all (Chrome) +- Fix Chrome rules matching against `_`, now matches against special characters instead +- Add variables view to last download in options +- Fix routing failing in some cases (regression) (#80) +- Fix last used access key not working at all (Chrome) # 2.7.3 -* Fix accesskeys not appearing in Chrome (regression) (#79) -* Fix notifications not showing up for alt-clicked images (#78) +- Fix accesskeys not appearing in Chrome (regression) (#79) +- Fix notifications not showing up for alt-clicked images (#78) # 2.7.2 -* Replace custom polyfill with mozilla/webextension-polyfill +- Replace custom polyfill with mozilla/webextension-polyfill # 2.7.1 -* Include credentials when firing `HEAD` to grab Content-Disposition (Firefox) +- Include credentials when firing `HEAD` to grab Content-Disposition (Firefox) # 2.7.0 -* Add option to prefer links over media (#75) -* Use @Rob--W's Content-Disposition parser (#73) +- Add option to prefer links over media (#75) +- Use @Rob--W's Content-Disposition parser (#73) (source: Rob--W/open-in-browser)[https://github.com/Rob--W/open-in-browser/blob/master/extension/content-disposition.js] -* Add localisation hooks to most things +- Add localisation hooks to most things # 2.6.2 -* Fix import settings on options page being totally broken -* Remove debug information and last download information from options +- Fix import settings on options page being totally broken +- Remove debug information and last download information from options # 2.6.0 -* Add option to choose which mouse button to use for click-to-save (#60) -* Add autocomplete dropdown in options page (#63) +- Add option to choose which mouse button to use for click-to-save (#60) +- Add autocomplete dropdown in options page (#63) # 2.5.4 -* Fix overzealous leading dot sanitisation when rewriting filenames (#61) -* Fix notifications not being polyfilled for Chrome (#62) -* Fix potential uninitialised object error in Chrome +- Fix overzealous leading dot sanitisation when rewriting filenames (#61) +- Fix notifications not being polyfilled for Chrome (#62) +- Fix potential uninitialised object error in Chrome # 2.5.3 -* Throttle saving tabs from tabstrip, might fix random bugginess when saving (#57) +- Throttle saving tabs from tabstrip, might fix random bugginess when saving (#57) # 2.5.0 -* Save tabs from tabstrip, with options to save to right, and tabs opened from another tab. Firefox only. (#57) +- Save tabs from tabstrip, with options to save to right, and tabs opened from another tab. Firefox only. (#57) # 2.4.1 -* Fix Freedesktop shortcuts not using the page title for Name and Title (#54) +- Fix Freedesktop shortcuts not using the page title for Name and Title (#54) # 2.4.0 -* Major refactor to options management, downloading, and renaming. I've tried to keep behaviour identical to older versions so if there are any unexpected changes please file an issue. The extension has had insane feature creep and code spaghettification, so this taming was necessary to keep it maintainable. -* Fix save-to-click toggle key not deactivating after switching tabs (#15) -* Add option to download things via content script. Disabled by default, Firefox only. (#46) -* Treat `~` as a normal character in paths (#51) -* Add option to show or hide last used location. Enabled by default. (#52) -* Add more fields to Freedesktop shortcuts (#54) -* Add option to prompt on menu item click when shift is held. Enabled by default. (#55) -* Options page now validates routes without needing to refresh to get last download +- Major refactor to options management, downloading, and renaming. I've tried to keep behaviour identical to older versions so if there are any unexpected changes please file an issue. The extension has had insane feature creep and code spaghettification, so this taming was necessary to keep it maintainable. +- Fix save-to-click toggle key not deactivating after switching tabs (#15) +- Add option to download things via content script. Disabled by default, Firefox only. (#46) +- Treat `~` as a normal character in paths (#51) +- Add option to show or hide last used location. Enabled by default. (#52) +- Add more fields to Freedesktop shortcuts (#54) +- Add option to prompt on menu item click when shift is held. Enabled by default. (#55) +- Options page now validates routes without needing to refresh to get last download # 2.3.0 -* Add `comment:`, `menuindex:` matchers -* Allow comments on menu items +- Add `comment:`, `menuindex:` matchers +- Allow comments on menu items # 2.2.1 -* Also stop propagation immediately on click-to-save +- Also stop propagation immediately on click-to-save # 2.2.0 -* Add filesize and mimetype to successful download notification (#48) -* Add experimental click-to-save feature (#15, #20) +- Add filesize and mimetype to successful download notification (#48) +- Add experimental click-to-save feature (#15, #20) # 2.1.0 -* Add `context:` clause -* Do not automatically add `.html` to all page downloads. (#45) This avoids wrong extensions on non-HTML pages. For the old behaviour, use a rule: +- Add `context:` clause +- Do not automatically add `.html` to all page downloads. (#45) This avoids wrong extensions on non-HTML pages. For the old behaviour, use a rule: ``` context: page into: :pagetitle:.html @@ -199,12 +203,12 @@ It's been difficult getting motivation to work on save-in, especially with the p # 2.0.2 -* Don't warn if path has a `\` in it -* Hack to allow multiple separators (#44) +- Don't warn if path has a `\` in it +- Hack to allow multiple separators (#44) # 2.0.0 -* Filename rewrites upgrade: now 100% more flexible +- Filename rewrites upgrade: now 100% more flexible - New rule-based syntax - Now able to use regex capture groups on supported clauses @@ -215,85 +219,85 @@ It's been difficult getting motivation to work on save-in, especially with the p - Option to notify on rule match - Migrating old rules: https://github.com/gyng/save-in/wiki/Filename-rewrite#migrating-to-the-new-syntax -* Add `:sourceurl:`, `:selectiontext:` variables (#39) -* Add `:naivefilename:`, `:naivefileext:` variables -* Add replacement character option (#39) -* Settings now autosave on update -* More iteration on options page -* Fix improper bad character replacements creating extra directories (#37) -* Add error messages for bad paths and rewrite patterns (#29) -* Add settings import and export -* Add menu keyboard shortcuts for Chrome (#15)* -* Add option to prompt on download failure -* Fix `:pagetitle` not updating (#41) -* Bug fixes and other improvements +- Add `:sourceurl:`, `:selectiontext:` variables (#39) +- Add `:naivefilename:`, `:naivefileext:` variables +- Add replacement character option (#39) +- Settings now autosave on update +- More iteration on options page +- Fix improper bad character replacements creating extra directories (#37) +- Add error messages for bad paths and rewrite patterns (#29) +- Add settings import and export +- Add menu keyboard shortcuts for Chrome (#15)\* +- Add option to prompt on download failure +- Fix `:pagetitle` not updating (#41) +- Bug fixes and other improvements # 1.6.0 -* Add `:second:` variable (#31) -* Add `:pagetitle:` variable (requires new `tabs` permission) -* Add saving of current page (#17, #30) -* Add saving of things as shortcuts (#17) -* Save selection with page titles for filenames -* Add filename conflict action option for Chrome (#18)* -* Add reset to default button in options -* Add :linktext: to directories -* Add truncate path component option -* Better error handling for bad regex patterns (#34) -* Photonized options page +- Add `:second:` variable (#31) +- Add `:pagetitle:` variable (requires new `tabs` permission) +- Add saving of current page (#17, #30) +- Add saving of things as shortcuts (#17) +- Save selection with page titles for filenames +- Add filename conflict action option for Chrome (#18)\* +- Add reset to default button in options +- Add :linktext: to directories +- Add truncate path component option +- Better error handling for bad regex patterns (#34) +- Photonized options page # 1.5.2 -* Only notify for downloads downloaded through save in +- Only notify for downloads downloaded through save in # 1.5.1 -* Fix false-positive failure notifications (#28) -* Fix for browsers (FF < 57) which do not support `icons` in context menu items (#27) -* Set notify on failure to be on by default +- Fix false-positive failure notifications (#28) +- Fix for browsers (FF < 57) which do not support `icons` in context menu items (#27) +- Set notify on failure to be on by default # 1.5.0 -* Add `:year:`, `:month:`, `:day:`, `:hour:`, `:minute:` variables (#24) -* Add last used menu entry (#20)* -* Add save selection feature/option (#19) -* Add debug logging checkbox in options page +- Add `:year:`, `:month:`, `:day:`, `:hour:`, `:minute:` variables (#24) +- Add last used menu entry (#20)\* +- Add save selection feature/option (#19) +- Add debug logging checkbox in options page # 1.4.4 -* Fix Firefox Nightly 58.0a not saving into default directory (#7) +- Fix Firefox Nightly 58.0a not saving into default directory (#7) # 1.4.1 -* Fix nested directories being treated as a single directory -* Pad single-digit components in dates with `0` +- Fix nested directories being treated as a single directory +- Pad single-digit components in dates with `0` # 1.4.0 -* Added global filename rewrites, along with `:filename:`, `:fileext:`, and `:$n:` variables -* Added `:unixdate:`, `:isodate:` variables -* Added option to prompt if filename has no extension -* Fixed Chrome detection on Firefox -* Fixed bunch of undefined variables in Chrome (notifications) +- Added global filename rewrites, along with `:filename:`, `:fileext:`, and `:$n:` variables +- Added `:unixdate:`, `:isodate:` variables +- Added option to prompt if filename has no extension +- Fixed Chrome detection on Firefox +- Fixed bunch of undefined variables in Chrome (notifications) # 1.3.1 -* Added timeout duration option for notifications +- Added timeout duration option for notifications # 1.3.0 -* Added notifications for download success/failures (disabled by default) -* Added `notifications` permission +- Added notifications for download success/failures (disabled by default) +- Added `notifications` permission # 1.2.0 -* Added option to show file dialog on save -* Fix link option always being checked in options page +- Added option to show file dialog on save +- Fix link option always being checked in options page # 1.1.0 -* Added `` permission (to get around CORS when issuing HEAD requests) -* Handle `Content-Disposition` headers -* Directory variables (:sourcedomain:, :pagedomain:, :pageurl:, :date:) -* Now always defaults to `.` as a directory to be saved into (improves first-run experience) -* Options page styling tweaks +- Added `` permission (to get around CORS when issuing HEAD requests) +- Handle `Content-Disposition` headers +- Directory variables (:sourcedomain:, :pagedomain:, :pageurl:, :date:) +- Now always defaults to `.` as a directory to be saved into (improves first-run experience) +- Options page styling tweaks diff --git a/manifest.json b/manifest.json index f52675f..2795a10 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "__MSG_extensionName__", "description": "__MSG_extensionDescription__", - "version": "3.7.2", + "version": "3.7.3", "default_locale": "en", "applications": { diff --git a/package.json b/package.json index c15208a..64542b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "save-in", - "version": "3.7.2", + "version": "3.7.3", "license": "MIT", "scripts": { "build": "env -u WEB_EXT_API_KEY -u WEB_EXT_API_SECRET web-ext build --overwrite-dest -i test docs yarn.lock yarn-error.log", diff --git a/src/chrome-detector.js b/src/chrome-detector.js index 1e9dc1c..45dffad 100644 --- a/src/chrome-detector.js +++ b/src/chrome-detector.js @@ -1,10 +1,11 @@ const BROWSERS = { CHROME: "CHROME", FIREFOX: "FIREFOX", + UNKNOWN: "UNKNOWN", }; let BROWSER_FEATURES; // eslint-disable-line -let CURRENT_BROWSER = BROWSERS.CHROME; +let CURRENT_BROWSER = BROWSERS.UNKNOWN; let CURRENT_BROWSER_VERSION; const setFeatures = (browser, version) => { @@ -51,5 +52,5 @@ if (typeof browser === "undefined") { // If we don't have browser.runtime.getBrowserInfo, assume it's Chrome // Big assumption, but browser.runtime.getBrowserInfo is not well supported CURRENT_BROWSER = BROWSERS.CHROME; // eslint-disable-line - BROWSER_FEATURES = setFeatures(CURRENT_BROWSER, CURRENT_BROWSER_VERSION); // eslint-disable-line + BROWSER_FEATURES = setFeatures(CURRENT_BROWSER, CURRENT_BROWSER_VERSION); // eslint-disable-line } diff --git a/src/options/options.js b/src/options/options.js index 1a872ae..dde2723 100644 --- a/src/options/options.js +++ b/src/options/options.js @@ -1,6 +1,19 @@ const getOptionsSchema = browser.runtime .sendMessage({ type: "OPTIONS_SCHEMA" }) - .then((res) => res.body); + .then((res) => { + console.log("options", res, CURRENT_BROWSER); + return res.body; + }) + .catch(console.error); + +const waitForBrowserDetection = () => { + if (CURRENT_BROWSER === "UNKNOWN") { + setTimeout(waitForBrowserDetection, 10); + } else { + setupChromeDisables(); + } +}; +waitForBrowserDetection(); const updateErrors = () => { const pathsErrors = document.querySelector("#error-paths"); @@ -136,7 +149,7 @@ const updateErrors = () => { const updateHistory = async () => { // Copied from history.js const HISTORY_KEY = "save-in-history"; - const history = (await browser.storage.local.get(HISTORY_KEY)) || {}; + const history = (await browser.storage.local.get(HISTORY_KEY)) ?? {}; const el = document.querySelector("#history"); el.value = JSON.stringify(history, null, 2); }; @@ -152,7 +165,7 @@ const deleteHistory = () => { }; document .querySelector("#history-delete") - .addEventListener("click", deleteHistory); + ?.addEventListener("click", deleteHistory); browser.runtime.onMessage.addListener((message) => { switch (message.type) { @@ -278,22 +291,24 @@ document.querySelector("#reset").addEventListener("click", (e) => { } }); -if (CURRENT_BROWSER === BROWSERS.CHROME) { - document.querySelectorAll(".chrome-only").forEach((el) => { - el.classList.toggle("show"); - }); +const setupChromeDisables = () => { + if (CURRENT_BROWSER === BROWSERS.CHROME) { + document.querySelectorAll(".chrome-only").forEach((el) => { + el.classList.toggle("show"); + }); - document.querySelectorAll(".chrome-enabled").forEach((el) => { - el.removeAttribute("disabled"); - }); + document.querySelectorAll(".chrome-enabled").forEach((el) => { + el.removeAttribute("disabled"); + }); - document.querySelector("html").style = "min-width: 600px;"; - // document.querySelector("body").style = "overflow-y: hidden;"; + document.querySelector("html").style = "min-width: 600px;"; + // document.querySelector("body").style = "overflow-y: hidden;"; - document.querySelectorAll(".chrome-disabled").forEach((el) => { - el.disabled = true; - }); -} + document.querySelectorAll(".chrome-disabled").forEach((el) => { + el.disabled = true; + }); + } +}; const setupAutosave = (el) => { const autosaveCb = (e) => {