diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e6a0321..57a44cc 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -32,6 +32,7 @@ jobs: cp README.md LICENSE firefox echo "Copying docs into folder" cp -r docs firefox/docs + cd firefox echo "Zipping folder into stardown-${{ github.ref_name }}-firefox.zip" zip -r "stardown-${{ github.ref_name }}-firefox.zip" firefox - name: Build for Chrome @@ -41,13 +42,14 @@ jobs: cp README.md LICENSE chrome echo "Copying docs into folder" cp -r docs chrome/docs + cd chrome echo "Zipping folder into stardown-${{ github.ref_name }}-chrome.zip" - zip -r "stardown-${{ github.ref_name }}-chrome.zip" chrome + zip -r "stardown-${{ github.ref_name }}-chrome.zip" . - name: Release uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') with: generate_release_notes: true files: | - stardown-${{ github.ref_name }}-firefox.zip - stardown-${{ github.ref_name }}-chrome.zip + firefox/stardown-${{ github.ref_name }}-firefox.zip + chrome/stardown-${{ github.ref_name }}-chrome.zip diff --git a/chrome/browserSpecific.js b/chrome/browserSpecific.js index 9170884..05a333a 100644 --- a/chrome/browserSpecific.js +++ b/chrome/browserSpecific.js @@ -155,7 +155,7 @@ export async function handleCopyRequest(text) { try { await navigator.clipboard.writeText(text); } catch (err) { - console.error('navigator.clipboard.writeText:', err); + console.error('navigator.clipboard.writeText:', err.message); console.log('Using fallback method to write text to the clipboard.'); const textarea = document.createElement('textarea'); diff --git a/docs/install and update instructions/index.html b/docs/install and update instructions/index.html index 08b8704..063bdc8 100644 --- a/docs/install and update instructions/index.html +++ b/docs/install and update instructions/index.html @@ -35,6 +35,59 @@

+ +
@@ -48,6 +101,25 @@

+
+ Browser + +
+ + +
+ +
+ + +
+ +
+ + +
+
+
How did you install Stardown? diff --git a/docs/install and update instructions/script.js b/docs/install and update instructions/script.js index 8eb4d68..25c8813 100644 --- a/docs/install and update instructions/script.js +++ b/docs/install and update instructions/script.js @@ -12,14 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -const isWindows = navigator.userAgent.includes('Windows'); - -const isChromium = navigator.userAgent.includes('Chrome'); // https://developer.mozilla.org/en-US/docs/Web/API/Window/navigator#example_1_browser_detect_and_return_a_string -const isFirefox = navigator.userAgent.includes('Firefox'); -const isSafari = navigator.userAgent.includes('Safari'); - const instructionsEl = document.querySelector('#instructions'); -const formEl = document.querySelector('form'); // fieldsets that start hidden const installedWithEl = document.querySelector('#installedWith'); @@ -27,6 +20,9 @@ const willInstallWithEl = document.querySelector('#willInstallWith'); const hasNodeV14PlusEl = document.querySelector('#hasNodeV14Plus'); // radio inputs +const chromiumEl = document.querySelector('#chromium'); +const firefoxEl = document.querySelector('#firefox'); +const safariEl = document.querySelector('#safari'); const installingEl = document.querySelector('#installing'); const updatingEl = document.querySelector('#updating'); const installedWithStoreEl = document.querySelector('#installedWithStore'); @@ -43,6 +39,22 @@ installedWithEl.setAttribute('hidden', 'hidden'); willInstallWithEl.setAttribute('hidden', 'hidden'); hasNodeV14PlusEl.setAttribute('hidden', 'hidden'); +const isWindows = navigator.userAgent.includes('Windows'); + +// [How to determine the current browser](https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browsers#answer-9851769) +// There is no completely reliable way, so users should be able to select their browser. +chromiumEl.checked = Boolean(window.chrome); +firefoxEl.checked = typeof InstallTrigger !== 'undefined' && !chromiumEl.checked; +safariEl.checked = ( + navigator.vendor && + /Apple Computer, Inc\./i.test(navigator.vendor) && + !chromiumEl.checked && + !firefoxEl.checked +); + +chromiumEl.addEventListener('change', main); +firefoxEl.addEventListener('change', main); +safariEl.addEventListener('change', main); installingEl.addEventListener('change', main); updatingEl.addEventListener('change', main); installedWithStoreEl.addEventListener('change', main); @@ -64,18 +76,19 @@ class Instructions { function main() { const instructions = new Instructions(); - if (!isChromium && !isFirefox && !isSafari) { - instructions.text = `Unknown browser: ${navigator.userAgent}`; - formEl.setAttribute('hidden', 'hidden'); - } else if (isSafari) { - instructions.text = 'Safari support coming soon!'; - formEl.setAttribute('hidden', 'hidden'); - } else if (installingEl.checked) { - install(instructions); - } else if (updatingEl.checked) { - update(instructions); - } else { - throw new Error('Neither installing nor updating'); + if (chromiumEl.checked || firefoxEl.checked || safariEl.checked) { + if (safariEl.checked) { + instructions.text = 'Safari support coming soon!'; + willInstallWithEl.setAttribute('hidden', 'hidden'); + installedWithEl.setAttribute('hidden', 'hidden'); + hasNodeV14PlusEl.setAttribute('hidden', 'hidden'); + } else if (installingEl.checked) { + install(instructions); + } else if (updatingEl.checked) { + update(instructions); + } else { + throw new Error('Neither installing nor updating'); + } } if (instructions.text || instructions.steps.length > 0) { @@ -83,6 +96,8 @@ function main() { } else { instructionsEl.setAttribute('hidden', 'hidden'); } + + window.scrollTo(0, document.body.scrollHeight); } function install(instructions) { @@ -126,12 +141,12 @@ function update(instructions) { } function installWithStore(instructions) { - if (isChromium) { + if (chromiumEl.checked) { instructions.text = ` Install Stardown from the Chrome Web Store `; - } else if (isFirefox) { + } else if (firefoxEl.checked) { instructions.text = ` Install Stardown from Add-ons for Firefox @@ -142,20 +157,20 @@ function installWithStore(instructions) { } function installWithZip(instructions) { - if (isChromium) { + if (chromiumEl.checked) { instructions.steps.push( - // TODO: link to the zip file of the built code - `Click here to download the .zip file`, + ` + Download the chrome.zip file`, 'Unzip the .zip file', 'In your browser, open chrome://extensions/', 'Turn on developer mode', 'Click "Load unpacked"', 'Select the unzipped copy of Stardown', ); - } else if (isFirefox) { + } else if (firefoxEl.checked) { instructions.steps.push( - // TODO: link to the zip file of the built code - `Click here to download the .zip file`, + ` + Download the firefox.zip file`, 'Unzip the .zip file', 'In your browser, open about:debugging#/runtime/this-firefox', 'Click "Load Temporary Add-on..."', @@ -190,7 +205,7 @@ function installWithTerminal(instructions) { && cd Stardown` ); - if (isChromium) { + if (chromiumEl.checked) { instructions.steps.push( 'Then run npm install && npm run build-chrome', 'In your browser, open chrome://extensions/', @@ -198,7 +213,7 @@ function installWithTerminal(instructions) { 'Click "Load unpacked"', 'Select Stardown\'s chrome folder', ); - } else if (isFirefox) { + } else if (firefoxEl.checked) { instructions.steps.push( 'Then run npm install && npm run build-firefox', 'In your browser, open about:debugging#/runtime/this-firefox', @@ -211,12 +226,12 @@ function installWithTerminal(instructions) { } function updateWithStore(instructions) { - if (isChromium) { + if (chromiumEl.checked) { instructions.text = ` You're up to date! Extensions installed from the store update automatically. `; - } else if (isFirefox) { + } else if (firefoxEl.checked) { instructions.text = ` Extensions installed from the store normally update automatically. If you might have automatic updates turned off, see @@ -229,20 +244,20 @@ function updateWithStore(instructions) { } function updateWithZip(instructions) { - if (isChromium) { + if (chromiumEl.checked) { instructions.steps.push( - // TODO: link to the zip file of the built code - `Click here to download a new .zip file`, + ` + Download a new chrome.zip file`, 'Unzip the .zip file', 'In your browser, open chrome://extensions/', 'Remove Stardown', 'Click "Load unpacked"', 'Select the newly unzipped copy of Stardown', ); - } else if (isFirefox) { + } else if (firefoxEl.checked) { instructions.steps.push( - // TODO: link to the zip file of the built code - `Click here to download a new .zip file`, + ` + Download a new firefox.zip file`, 'Unzip the .zip file', 'In your browser, open about:debugging#/runtime/this-firefox', 'Remove Stardown', @@ -255,14 +270,14 @@ function updateWithZip(instructions) { } function updateWithTerminal(instructions) { - if (isChromium) { + if (chromiumEl.checked) { instructions.steps.push( 'In a terminal, navigate into Stardown\'s folder', 'Run git pull && npm install && npm run build-chrome', 'In your browser, open chrome://extensions/', 'Click Stardown\'s reload button', ); - } else if (isFirefox) { + } else if (firefoxEl.checked) { instructions.steps.push( 'In a terminal, navigate into Stardown\'s folder', 'Run git pull && npm install && npm run build-firefox',