From 1adfb7e525c9249300c421621f047b302feb84d7 Mon Sep 17 00:00:00 2001 From: Kim <85441644+emptycan1010@users.noreply.github.com> Date: Wed, 25 Feb 2026 18:01:28 +0900 Subject: [PATCH 1/2] feat: add UA toggle option and build github action --- .github/workflows/build.yml | 40 ++++++++++++++++++++++ src/entrypoints/background.ts | 64 ++++++++++++++++++++++++++++++++++- src/entrypoints/popup/App.tsx | 8 +++++ src/types/options.ts | 4 ++- wxt.config.ts | 3 +- 5 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..7c10293 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,40 @@ +name: Build Extension + +on: + push: + branches: + - '**' + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Lint + run: pnpm eslint . + + - name: Build + run: pnpm build + + - name: Upload chrome build artifact + uses: actions/upload-artifact@v4 + with: + name: chrome-mv3-dist + path: dist/chrome-mv3 + if-no-files-found: error diff --git a/src/entrypoints/background.ts b/src/entrypoints/background.ts index 245ad09..016feb7 100644 --- a/src/entrypoints/background.ts +++ b/src/entrypoints/background.ts @@ -1,7 +1,69 @@ import type { DownloadMessage, MessageType } from '../types/message' +import { DEFAULT_OPTIONS, getOption } from '../types/options' + +const CHZZK_USER_AGENT_RULE_ID = 1001 +const CHZZK_USER_AGENT = + 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36 OPR/65.0.3467.48' + +const setChzzkUserAgentRule = async (enabled: boolean): Promise => { + await chrome.declarativeNetRequest.updateDynamicRules({ + removeRuleIds: [CHZZK_USER_AGENT_RULE_ID], + addRules: enabled + ? [ + { + id: CHZZK_USER_AGENT_RULE_ID, + priority: 1, + action: { + type: 'modifyHeaders', + requestHeaders: [ + { + header: 'User-Agent', + operation: 'set', + value: CHZZK_USER_AGENT + } + ] + }, + condition: { + regexFilter: '^https://chzzk\\.naver\\.com/.*', + resourceTypes: ['main_frame', 'sub_frame', 'xmlhttprequest', 'media'] + } + } + ] + : [] + }) +} + +const syncChzzkUserAgentRule = (): void => { + getOption() + .then(({ uaChange }) => setChzzkUserAgentRule(uaChange)) + .catch(console.error) +} export default defineBackground(() => { -// Download message listener + syncChzzkUserAgentRule() + chrome.runtime.onInstalled.addListener(syncChzzkUserAgentRule) + chrome.runtime.onStartup.addListener(syncChzzkUserAgentRule) + + chrome.storage.onChanged.addListener((changes, areaName) => { + if (areaName !== 'local' || changes.option == null) { + return + } + + const nextOption = changes.option.newValue as Record | undefined + const prevOption = changes.option.oldValue as Record | undefined + + const nextUaChange = typeof nextOption?.uaChange === 'boolean' ? nextOption.uaChange : DEFAULT_OPTIONS.uaChange + const prevUaChange = typeof prevOption?.uaChange === 'boolean' ? prevOption.uaChange : DEFAULT_OPTIONS.uaChange + + if (nextUaChange === prevUaChange) { + return + } + + setChzzkUserAgentRule(nextUaChange) + .catch(console.error) + }) + + // Download message listener chrome.runtime.onMessage.addListener((request: MessageType) => { if (request.type === 'download') { const msg = request as DownloadMessage diff --git a/src/entrypoints/popup/App.tsx b/src/entrypoints/popup/App.tsx index cd07ef3..be6e0b6 100644 --- a/src/entrypoints/popup/App.tsx +++ b/src/entrypoints/popup/App.tsx @@ -60,6 +60,14 @@ export default function App (): React.ReactNode { + + Date: Wed, 25 Feb 2026 18:05:28 +0900 Subject: [PATCH 2/2] fix: pin pnpm version in github actions workflow --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c10293..6dc1559 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,8 @@ jobs: - name: Setup pnpm uses: pnpm/action-setup@v4 + with: + version: 9 - name: Setup Node.js uses: actions/setup-node@v4