diff options
-rw-r--r-- | .github/workflows/build.yml | 20 | ||||
-rw-r--r-- | .github/workflows/publish.yml | 60 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | browser/background.js | 48 | ||||
-rw-r--r-- | browser/icon.png | bin | 0 -> 21831 bytes | |||
-rw-r--r-- | browser/manifest.json (renamed from browser/manifestv3.json) | 15 | ||||
-rw-r--r-- | browser/manifestv2.json | 25 | ||||
-rw-r--r-- | scripts/build/buildWeb.mjs | 33 |
8 files changed, 103 insertions, 104 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5c9eafe..1590c79 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,28 +34,19 @@ jobs: - name: Build web run: pnpm buildWeb --standalone - - name: Sign firefox extension - run: | - pnpx web-ext sign --api-key $WEBEXT_USER --api-secret $WEBEXT_SECRET --channel=unlisted - env: - WEBEXT_USER: ${{ secrets.WEBEXT_USER }} - WEBEXT_SECRET: ${{ secrets.WEBEXT_SECRET }} - - name: Build run: pnpm build --standalone - - name: Rename extensions for more user friendliness + - name: Clean up obsolete files run: | - mv dist/*.xpi dist/Vencord-for-Firefox.xpi - mv dist/extension-v3.zip dist/Vencord-for-Chrome-and-Edge.zip - rm -rf dist/extension-v2-unpacked dist/extension-v2.zip + rm -rf dist/extension* Vencord.user.css - name: Get some values needed for the release id: release_values run: | echo "release_tag=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - name: Upload Devbuild as release + - name: Upload DevBuild as release run: | gh release upload devbuild --clobber dist/* gh release edit devbuild --title "DevBuild $RELEASE_TAG" @@ -63,13 +54,15 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_TAG: ${{ env.release_tag }} - - name: Upload Devbuild to builds repo + - name: Upload DevBuild to builds repo run: | git config --global user.name "$USERNAME" git config --global user.email actions@github.com git clone https://$USERNAME:$API_TOKEN@github.com/$GH_REPO.git upload cd upload + + GLOBIGNORE: .git:.gitignore:README.md:LICENSE rm -rf * cp -r ../dist/* . @@ -78,6 +71,5 @@ jobs: git push --force https://$USERNAME:$API_TOKEN@github.com/$GH_REPO.git env: API_TOKEN: ${{ secrets.BUILDS_TOKEN }} - GLOBIGNORE: .git:.gitignore:README.md:LICENSE GH_REPO: Vencord/builds USERNAME: GitHub-Actions diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..34738b9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,60 @@ +name: Release Browser Extension +on: + push: + tags: + - v* + +jobs: + Publish: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: check that tag matches package.json version + run: | + pkg_version="$(jq -r .version < package.json)" + if [[ "${{ github.ref_name }}" != "$pkg_version" ]]; then + echo "Tag ${{ github.ref_name }} does not match package.json version $pkg_version" >&2 + exit 1 + fi + + - uses: pnpm/action-setup@v2 # Install pnpm using packageManager key in package.json + + - name: Use Node.js 19 + uses: actions/setup-node@v3 + with: + node-version: 19 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build web + run: pnpm buildWeb --standalone + + - name: Publish extension + run: | + cd dist/extension-unpacked + + # Do not fail so that even if chrome fails, firefox gets a shot. But also store exit code to fail workflow later + EXIT_CODE=0 + + # Chrome + pnpx chrome-webstore-upload-cli@2.1.0 upload --auto-publish || EXIT_CODE=$? + + # Firefox + pnpx web-ext-submit@7.4.0 + + exit $EXIT_CODE + env: + # Chrome + EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }} + CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }} + CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }} + REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }} + + # Firefox + WEB_EXT_API_KEY: ${{ secrets.WEBEXT_USER }} + WEB_EXT_API_SECRET: ${{ secrets.WEBEXT_SECRET }} + @@ -18,11 +18,9 @@ The cutest Discord client mod ## Installing on Browser -[![Get the Firefox extension](https://blog.mozilla.org/addons/files/2015/11/get-the-addon-small.png)](https://addons.mozilla.org/en-GB/firefox/addon/vencord-web/) +[![Get it on the Firefox Webstore](https://blog.mozilla.org/addons/files/2015/11/get-the-addon.png)](https://addons.mozilla.org/en-GB/firefox/addon/vencord-web/) [![Get it on the Chrome Webstore](https://storage.googleapis.com/web-dev-uploads/image/WlD8wC6g8khYWPJUsQceQkhXSlv1/UV4C4ybeBTsZt43U4xis.png)](https://chrome.google.com/webstore/detail/vencord-web/cbghhgpcnddeihccjmnadmkaejncjndb) -Or install the browser extension for -- [![Chrome](https://img.shields.io/badge/chrome-ext-brightgreen)](https://github.com/Vendicated/Vencord/releases/latest/download/Vencord-for-Chrome-and-Edge.zip) -- [UserScript](https://raw.githubusercontent.com/Vencord/builds/main/Vencord.user.js) - Please note that QuickCSS, shiki and other plugins making use of external resources will not work with the UserScript. +Or use the [UserScript](https://raw.githubusercontent.com/Vencord/builds/main/Vencord.user.js) - Please note that QuickCSS and plugins making use of external resources will not work with the UserScript. ## Building from Source diff --git a/browser/background.js b/browser/background.js deleted file mode 100644 index 5c99dd8..0000000 --- a/browser/background.js +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Linnea Gräf - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ - -function setContentTypeOnStylesheets(details) { - if (details.type === "stylesheet") { - details.responseHeaders = details.responseHeaders.filter(it => it.name.toLowerCase() !== 'content-type'); - details.responseHeaders.push({ name: "Content-Type", value: "text/css" }); - } - return { responseHeaders: details.responseHeaders }; -} - -var cspHeaders = [ - "content-security-policy", - "content-security-policy-report-only", -]; - -function removeCSPHeaders(details) { - return { - responseHeaders: details.responseHeaders.filter(header => - !cspHeaders.includes(header.name.toLowerCase())) - }; -} - - - - -browser.webRequest.onHeadersReceived.addListener( - setContentTypeOnStylesheets, { urls: ["https://raw.githubusercontent.com/*"] }, ["blocking", "responseHeaders"] -); - -browser.webRequest.onHeadersReceived.addListener( - removeCSPHeaders, { urls: ["https://raw.githubusercontent.com/*", "*://*.discord.com/*"] }, ["blocking", "responseHeaders"] -); diff --git a/browser/icon.png b/browser/icon.png Binary files differnew file mode 100644 index 0000000..57349fa --- /dev/null +++ b/browser/icon.png diff --git a/browser/manifestv3.json b/browser/manifest.json index d15b80a..c20770e 100644 --- a/browser/manifestv3.json +++ b/browser/manifest.json @@ -1,10 +1,14 @@ { "manifest_version": 3, + "minimum_chrome_version": "91", + "name": "Vencord Web", - "description": "Yeee", - "version": "1.0.0", + "description": "The cutest Discord mod now in your browser", "author": "Vendicated", "homepage_url": "https://github.com/Vendicated/Vencord", + "icons": { + "128": "icon.png" + }, "host_permissions": [ "*://*.discord.com/*", @@ -36,5 +40,12 @@ "path": "modifyResponseHeaders.json" } ] + }, + + "applications": { + "gecko": { + "id": "vencord-firefox@vendicated.dev", + "strict_min_version": "109.0" + } } } diff --git a/browser/manifestv2.json b/browser/manifestv2.json deleted file mode 100644 index b28b73f..0000000 --- a/browser/manifestv2.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "manifest_version": 2, - "name": "Vencord Web", - "description": "The Vencord Client Mod for Discord Web.", - "version": "1.0.0", - "author": "Vendicated", - "homepage_url": "https://github.com/Vendicated/Vencord", - "permissions": [ - "webRequest", - "webRequestBlocking", - "*://*.discord.com/*", - "https://raw.githubusercontent.com/*" - ], - "content_scripts": [ - { - "run_at": "document_start", - "matches": ["*://*.discord.com/*"], - "js": ["content.js"] - } - ], - "web_accessible_resources": ["dist/Vencord.js", "dist/Vencord.css"], - "background": { - "scripts": ["background.js"] - } -} diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs index ceddbcb..dd7d32e 100644 --- a/scripts/build/buildWeb.mjs +++ b/scripts/build/buildWeb.mjs @@ -82,10 +82,19 @@ async function buildPluginZip(target, files, shouldZip) { const entries = { "dist/Vencord.js": await readFile("dist/browser.js"), "dist/Vencord.css": await readFile("dist/browser.css"), - ...Object.fromEntries(await Promise.all(files.map(async f => [ - (f.startsWith("manifest") ? "manifest.json" : f), - await readFile(join("browser", f)) - ]))), + ...Object.fromEntries(await Promise.all(files.map(async f => { + let content = await readFile(join("browser", f)); + if (f.startsWith("manifest")) { + const json = JSON.parse(content.toString("utf-8")); + json.version = PackageJSON.version; + content = new TextEncoder().encode(JSON.stringify(json)); + } + + return [ + f.startsWith("manifest") ? "manifest.json" : f, + content + ]; + }))), }; if (shouldZip) { @@ -115,20 +124,22 @@ async function buildPluginZip(target, files, shouldZip) { } } -const cssText = "`" + readFileSync("dist/Vencord.user.css", "utf-8").replaceAll("`", "\\`") + "`"; -const cssRuntime = ` +const appendCssRuntime = readFile("dist/Vencord.user.css", "utf-8").then(content => { + const cssRuntime = ` ;document.addEventListener("DOMContentLoaded", () => document.documentElement.appendChild( Object.assign(document.createElement("style"), { - textContent: ${cssText}, + textContent: \`${content.replaceAll("`", "\\`")}\`, id: "vencord-css-core" }) ), { once: true }); `; + return appendFile("dist/Vencord.user.js", cssRuntime); +}); + await Promise.all([ - appendFile("dist/Vencord.user.js", cssRuntime), - buildPluginZip("extension-v3.zip", ["modifyResponseHeaders.json", "content.js", "manifestv3.json"], true), - buildPluginZip("extension-v2.zip", ["background.js", "content.js", "manifestv2.json"], true), - buildPluginZip("extension-v2-unpacked", ["background.js", "content.js", "manifestv2.json"], false), + appendCssRuntime, + buildPluginZip("extension.zip", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"], true), + buildPluginZip("extension-unpacked", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"], false), ]); |