diff --git a/.eslintrc.json b/.eslintrc.json index f7f981f..c730018 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,5 +21,8 @@ "code": 100 } ] - } + }, + "ignorePatterns": [ + "**/third_party/**" + ] } \ No newline at end of file diff --git a/README.md b/README.md index 0b126fb..4d30b06 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,6 @@ Update URL and server configs under the folder `src/configs/`. Run `npm ci` to install dependencies exactly as they are listed in the package-lock.json file. -Run `npm run test` to create a zip file for uploading and testing. +Run `npm run lint` to check the coding style of all source code. + +Run `npm run test` to _create a zip file for uploading to Chrome Web Store_ and run tests against it. diff --git a/package.json b/package.json index 2c3349a..389274a 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "npm": "8.x" }, "scripts": { + "lint": "eslint ./ --ext .js,.mjs,.ts,.tsx", "clean": "rm -rf dist", "test": "npm run clean && node tools/create_zip.js && unzip -q dist/upload_to_chrome_store.zip -d dist/unzipped_chrome_extension && jest --verbose" }, diff --git a/src/modules/_icon.mjs b/src/modules/_icon.mjs index 872b109..6863a7c 100644 --- a/src/modules/_icon.mjs +++ b/src/modules/_icon.mjs @@ -49,7 +49,7 @@ export function setIcon(mode) { } if (isSpring()) { - chrome.action.setIcon({path: ICON_RELATIVE_PATH + 'icon19xmas.png'}); + chrome.action.setIcon({path: ICON_RELATIVE_PATH + 'icon19spring.png'}); chrome.action.setTitle( {title: 'Happy Spring Festival! (Unblock Youku ' + chrome.runtime.getManifest().version + ')'}); diff --git a/src/modules/settings.mjs b/src/modules/settings.mjs index 0070581..d97de25 100644 --- a/src/modules/settings.mjs +++ b/src/modules/settings.mjs @@ -33,7 +33,7 @@ export function getCustomProxy() { // Note: // * The function should be idempotent so it can be called multiple times. // * Make sure a Promise is returned so that the caller can wait for it. -async function applyModeSettings(mode) { +function applyModeSettings(mode) { if (mode === Modes.OFF) { return Promise.all([ Proxy.clearProxy(), @@ -41,19 +41,21 @@ async function applyModeSettings(mode) { Icon.setIcon(Modes.OFF), ]); } else { - // 1. Set proxy - const customProxy = await getCustomProxy(); - if (typeof customProxy === 'undefined' || + const setProxy = async () => { + const customProxy = await getCustomProxy(); + if (typeof customProxy === 'undefined' || typeof customProxy.proc === 'undefined' || typeof customProxy.addr === 'undefined') { - await Proxy.setDefaultProxy(); - } else { - await Proxy.setCustomProxy(customProxy.proc, customProxy.addr); - } - // 2. Set header modifier - await Header.setHeaderModifier(); - // 3. Set icon - Icon.setIcon(Modes.NORMAL); + return Proxy.setDefaultProxy(); + } else { + return Proxy.setCustomProxy(customProxy.proc, customProxy.addr); + } + }; + return Promise.all([ + setProxy(), + Header.setHeaderModifier(), + Icon.setIcon(Modes.NORMAL), + ]); } } @@ -78,8 +80,10 @@ export async function loadCurrentSettings() { // 2. Save the new mode into storage export async function setNewMode(mode) { - await applyModeSettings(mode); - await Storage.setItem(MODE_STORAGE_KEY, mode); + await Promise.all([ + applyModeSettings(mode), + Storage.setItem(MODE_STORAGE_KEY, mode), + ]); // Set this one-time text when the user changes the mode if (mode == Modes.OFF) { diff --git a/src/options.mjs b/src/options.mjs index f2a6c27..47fe732 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -102,6 +102,7 @@ $('#custom_proxy_enable').click(function() { 'warning', 'Set the custom proxy server, and changed mode to use proxy'); console.groupEnd(); + console.log('Finished setting the custom proxy'); }); }); @@ -119,6 +120,7 @@ $('#custom_proxy_reset').click(function() { showProxyMessage('warning', 'Reset custom proxy server, and changed mode to use proxy'); console.groupEnd(); + console.log('Finished clearing the custom proxy'); }); }); diff --git a/src/popup.mjs b/src/popup.mjs index 4fc4e68..4cf8b99 100644 --- a/src/popup.mjs +++ b/src/popup.mjs @@ -52,15 +52,15 @@ Icon.clearIconText(); $('input#input_off').change(function() { console.group('Clicked on the button to change the mode to OFF...'); Settings.setNewMode(Modes.OFF).then(() => { - console.log('Finished changing the mode to OFF'); console.groupEnd(); + console.log('Finished changing the mode to OFF'); }); }); $('input#input_normal').change(function() { console.group('Clicked on the button to change the mode to NORMAL...'); Settings.setNewMode(Modes.NORMAL).then(() => { - console.log('Finished changing the mode to NORMAL'); console.groupEnd(); + console.log('Finished changing the mode to NORMAL'); }); }); diff --git a/src/service_worker.mjs b/src/service_worker.mjs index 58303ee..e94c39e 100644 --- a/src/service_worker.mjs +++ b/src/service_worker.mjs @@ -10,8 +10,8 @@ import * as Settings from './modules/settings.mjs'; function initializeExtension() { console.group('To intialize the extension...'); Settings.loadCurrentSettings().then(() => { - console.log('Finished initializing the chrome extension'); console.groupEnd(); + console.log('Finished initializing the chrome extension'); }); } diff --git a/tools/create_zip.js b/tools/create_zip.js index 4a4f2df..71c1ea9 100644 --- a/tools/create_zip.js +++ b/tools/create_zip.js @@ -87,7 +87,7 @@ function getAllFilesFromList(folder, fileList) { if (shouldBeZipped(filePath)) { result.push(filePath); } else { - console.log('Excluding file: ' + filePath); + console.log('Excluding file from zipping: ' + filePath); } } else { result.push(...getAllFilesFromList(filePath, fs.readdirSync(filePath))); diff --git a/tools/produce_regex.mjs b/tools/produce_regex.mjs index 4cf5ba8..2645da1 100644 --- a/tools/produce_regex.mjs +++ b/tools/produce_regex.mjs @@ -1,26 +1,5 @@ import {PROXY_URLS} from '../src/configs/urls.mjs'; import {produceSquidRegexList} from './_regex_utils.mjs'; -const TEST_URL_LIST = [ - 'http://*/*', - 'https://*/*', - 'http://*.video.qq.com/*', - 'https://*.video.qq.com/*', - 'http://vd.l.qq.com/*', - 'https://vd.l.qq.com/*', - 'http://example.com', - 'https://example.com', - 'http://example.com/', - 'https://example.com/', - 'http://*.example.com/*', - 'https://*.example.com/*', - 'http://*.example.com/path.json?aaa=bbb', - 'https://*.example.com/path.json?aaa=bbb', - 'http://*.example.com/path.json?aaa=bbb*', - 'https://*.example.com/path.json?aaa=bbb*', - 'http://122.72.82.31/*', -]; - -// console.log(produceSquidRegexList(PROXY_URLS).join('\n') + '\n'); -console.log(produceSquidRegexList(TEST_URL_LIST).join('\n') + '\n'); +console.log(produceSquidRegexList(PROXY_URLS).join('\n') + '\n'); process.exit(0);