From f681406f0a3510e145f0a90b09a0aff257120aa5 Mon Sep 17 00:00:00 2001 From: Guus van der Meer Date: Mon, 25 Dec 2023 02:29:17 +0100 Subject: [PATCH 1/4] Created a workflow that creates a PR for the block-rules for manifest V3 --- .github/workflows/block_rules.yml | 44 ++++++++++++++++++++ .github/workflows/generateBlockRules.js | 54 +++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 .github/workflows/block_rules.yml create mode 100644 .github/workflows/generateBlockRules.js diff --git a/.github/workflows/block_rules.yml b/.github/workflows/block_rules.yml new file mode 100644 index 00000000..8e59ef12 --- /dev/null +++ b/.github/workflows/block_rules.yml @@ -0,0 +1,44 @@ +name: Generate manifest V3 block rules + +on: + push: + branches: + - main + +jobs: + generate-block-rules: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 14 + + - name: Install dependencies + run: npm install + + - name: Generate block rules + run: node .github\workflows\generateBlockRules.js > src\rules.json + + - name: Run Prettier + run: npx prettier --write .\src\rules.json + + - name: Check for changes + id: git-diff + run: echo ::set-output name=files-changed::$(git diff --name-only) + + - name: Create pull request + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: Update block rules for Manifest V3 + branch: update-block-rules + title: Update manifest V3 block rules + body: | + This pull request updates the block rules based on the latest changes. + Files changed: + ${{ steps.git-diff.outputs.files-changed }} diff --git a/.github/workflows/generateBlockRules.js b/.github/workflows/generateBlockRules.js new file mode 100644 index 00000000..f7dec926 --- /dev/null +++ b/.github/workflows/generateBlockRules.js @@ -0,0 +1,54 @@ +// This is used to generate the block rules for Manifest V3 from the block rules in Manifest V2. + +import { blockUrls } from "../../src/data/rules.js"; + +function generateDeclarativeNetRules() { + const result = []; + let lastId = 1; + + const addRule = (blockRule) => { + const newRule = { + id: lastId++, + priority: 1, + action: { type: "block" }, + condition: { + urlFilter: blockRule.r, + resourceTypes: ["script", "stylesheet", "xmlhttprequest", "image"], + }, + }; + + if (blockRule.e) { + newRule.condition.excludedInitiatorDomains = blockRule.e.slice(); + } + + result.push(newRule); + }; + + for (const blockRule of blockUrls.common) { + addRule(blockRule); + } + + for (const blockRules of Object.values(blockUrls.common_groups)) { + for (const blockRule of blockRules) { + addRule(blockRule); + } + } + + for (const [domain, url] of Object.entries(blockUrls.specific)) { + const newRule = { + id: lastId++, + priority: 1, + action: { type: "block" }, + condition: { + urlFilter: url[0], + resourceTypes: ["script", "stylesheet", "xmlhttprequest", "image"], + initiatorDomains: [domain], + }, + }; + result.push(newRule); + } + + console.log(JSON.stringify(result, null, "\t")); +} + +generateDeclarativeNetRules(); From d9ab3cce06becc360c911f6e57503f3bef22bb2f Mon Sep 17 00:00:00 2001 From: Guus van der Meer Date: Mon, 25 Dec 2023 02:29:31 +0100 Subject: [PATCH 2/4] wrong branchname --- .github/workflows/block_rules.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/block_rules.yml b/.github/workflows/block_rules.yml index 8e59ef12..e0a8581f 100644 --- a/.github/workflows/block_rules.yml +++ b/.github/workflows/block_rules.yml @@ -3,7 +3,7 @@ name: Generate manifest V3 block rules on: push: branches: - - main + - master jobs: generate-block-rules: From 41700982b4edc5d78a2e8e1ab2a510ad6c75375f Mon Sep 17 00:00:00 2001 From: Guus van der Meer Date: Mon, 25 Dec 2023 02:32:29 +0100 Subject: [PATCH 3/4] Fixed path --- .github/workflows/block_rules.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/block_rules.yml b/.github/workflows/block_rules.yml index e0a8581f..4b22dba5 100644 --- a/.github/workflows/block_rules.yml +++ b/.github/workflows/block_rules.yml @@ -22,10 +22,10 @@ jobs: run: npm install - name: Generate block rules - run: node .github\workflows\generateBlockRules.js > src\rules.json + run: node ./.github/workflows/generateBlockRules.js > src/rules.json - name: Run Prettier - run: npx prettier --write .\src\rules.json + run: npx prettier --write ./src/rules.json - name: Check for changes id: git-diff From 128254d58f1c735ffb5b2ba71d1467546797dfd2 Mon Sep 17 00:00:00 2001 From: Guus van der Meer Date: Mon, 25 Dec 2023 02:40:21 +0100 Subject: [PATCH 4/4] Last fix in action --- .github/workflows/block_rules.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/block_rules.yml b/.github/workflows/block_rules.yml index 4b22dba5..1e5345e7 100644 --- a/.github/workflows/block_rules.yml +++ b/.github/workflows/block_rules.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v2 with: - node-version: 14 + node-version: 20 - name: Install dependencies run: npm install @@ -38,6 +38,8 @@ jobs: commit-message: Update block rules for Manifest V3 branch: update-block-rules title: Update manifest V3 block rules + add-paths: | + src/rules.json body: | This pull request updates the block rules based on the latest changes. Files changed: