From e089fe12688d9e60e9872b269bdb9fda587340e7 Mon Sep 17 00:00:00 2001 From: MengYX Date: Mon, 8 Feb 2021 00:26:40 +0800 Subject: [PATCH 1/5] Change: Web Manifest --- public/manifest.json | 21 --------------------- vue.config.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 21 deletions(-) delete mode 100644 public/manifest.json diff --git a/public/manifest.json b/public/manifest.json deleted file mode 100644 index 300d003..0000000 --- a/public/manifest.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "音乐解锁", - "short_name": "音乐解锁", - "description": "在任何设备上解锁已购的加密音乐!", - "icons": [ - { - "src": "./img/icons/android-chrome-192x192.png", - "sizes": "192x192", - "type": "image/png" - }, - { - "src": "./img/icons/android-chrome-512x512.png", - "sizes": "512x512", - "type": "image/png" - } - ], - "start_url": "./index.html", - "display": "standalone", - "background_color": "#000000", - "theme_color": "#4DBA87" -} diff --git a/vue.config.js b/vue.config.js index ca68c15..545f248 100644 --- a/vue.config.js +++ b/vue.config.js @@ -2,6 +2,36 @@ module.exports = { publicPath: '', productionSourceMap: false, pwa: { + manifestPath: "web-manifest.json", + name: "音乐解锁", + themeColor: "#4DBA87", + msTileColor: "#000000", + manifestOptions: { + start_url: "./index.html", + description: "在任何设备上解锁已购的加密音乐!", + icons: [ + { + 'src': './img/icons/android-chrome-192x192.png', + 'sizes': '192x192', + 'type': 'image/png' + }, + { + 'src': './img/icons/android-chrome-512x512.png', + 'sizes': '512x512', + 'type': 'image/png' + } + ] + }, + appleMobileWebAppCapable: 'yes', + iconPaths: { + faviconSVG: './img/icons/safari-pinned-tab.svg', + favicon32: './img/icons/favicon-32x32.png', + favicon16: './img/icons/favicon-16x16.png', + appleTouchIcon: './img/icons/apple-touch-icon-152x152.png', + maskIcon: './img/icons/safari-pinned-tab.svg', + msTileImage: './img/icons/msapplication-icon-144x144.png' + }, + workboxPluginMode: "GenerateSW", workboxOptions: { skipWaiting: true } From 042b1ca0ddb1d6967420b922d6d2ccd008bd9e10 Mon Sep 17 00:00:00 2001 From: MengYX Date: Mon, 8 Feb 2021 01:28:30 +0800 Subject: [PATCH 2/5] Add Feature: Browser Extension --- extension-manifest.json | 15 +++++++++++++++ make-extension.js | 20 ++++++++++++++++++++ package.json | 3 ++- src/extension/popup.html | 1 + src/extension/popup.js | 1 + 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 extension-manifest.json create mode 100644 make-extension.js create mode 100644 src/extension/popup.html create mode 100644 src/extension/popup.js diff --git a/extension-manifest.json b/extension-manifest.json new file mode 100644 index 0000000..ffcf14f --- /dev/null +++ b/extension-manifest.json @@ -0,0 +1,15 @@ +{ + "manifest_version": 2, + "name": "音乐解锁", + "short_name": "音乐解锁", + "icons": { + "128": "./img/icons/msapplication-icon-144x144.png" + }, + "description": "在任何设备上解锁已购的加密音乐!", + "offline_enabled": true, + "options_page": "./index.html", + "homepage_url": "https://github.com/ix64/unlock-music", + "browser_action": { + "default_popup": "./popup.html" + } +} diff --git a/make-extension.js b/make-extension.js new file mode 100644 index 0000000..2f68dd0 --- /dev/null +++ b/make-extension.js @@ -0,0 +1,20 @@ +const fs = require('fs') +const path = require('path') +const src = "./src/extension/" +const dst = "./dist" +fs.readdirSync(src).forEach(file => { + let srcPath = path.join(src, file) + let dstPath = path.join(dst, file) + fs.copyFileSync(srcPath, dstPath) + console.log(`Copy: ${srcPath} => ${dstPath}`) +}) + +const manifestRaw = fs.readFileSync("./extension-manifest.json", "utf-8") +const manifest = JSON.parse(manifestRaw) + +const pkgRaw = fs.readFileSync("./package.json", "utf-8") +const pkg = JSON.parse(pkgRaw) + +manifest["version"] = pkg["version"] +fs.writeFileSync("./dist/manifest.json", JSON.stringify(manifest), "utf-8") +console.log("Write: manifest.json") diff --git a/package.json b/package.json index b97884f..25e7f44 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", - "fix-compatibility": "node ./src/fix-compatibility.js" + "fix-compatibility": "node ./src/fix-compatibility.js", + "make-extension": "node ./make-extension.js" }, "dependencies": { "base64-js": "^1.5.1", diff --git a/src/extension/popup.html b/src/extension/popup.html new file mode 100644 index 0000000..b28b4e7 --- /dev/null +++ b/src/extension/popup.html @@ -0,0 +1 @@ + diff --git a/src/extension/popup.js b/src/extension/popup.js new file mode 100644 index 0000000..244624f --- /dev/null +++ b/src/extension/popup.js @@ -0,0 +1 @@ +window.open(chrome.runtime.getURL('./index.html')); From c6ea98333e5a6f4363139510f452cb1641db7aaa Mon Sep 17 00:00:00 2001 From: MengYX Date: Mon, 8 Feb 2021 01:47:31 +0800 Subject: [PATCH 3/5] Update CI: Add Extension Build --- .github/workflows/build.yml | 17 ++++++++++++++++- .github/workflows/release.yml | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 748cdb2..8e4291c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,9 +27,11 @@ jobs: build: [ legacy, modern ] include: - build: legacy - BUILD_ARGS: + BUILD_ARGS: "" + BUILD_EXTENSION: true - build: modern BUILD_ARGS: "-- --modern" + BUILD_EXTENSION: false steps: - uses: actions/checkout@v2 @@ -59,8 +61,21 @@ jobs: npm run build ${{ matrix.BUILD_ARGS }} tar -czvf dist.tar.gz -C ./dist . + - name: Build Extension + if: ${{ matrix.BUILD_EXTENSION }} + run: | + npm run make-extension + zip -rJ9 extension.zip ./dist + - name: Publish artifact uses: actions/upload-artifact@v2 with: name: unlock-music-${{ matrix.build }}.tar.gz path: ./dist.tar.gz + + - name: Publish artifact - Extension + if: ${{ matrix.BUILD_EXTENSION }} + uses: actions/upload-artifact@v2 + with: + name: extension.zip + path: ./extension.zip diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1e4370..3a1645a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,6 +37,8 @@ jobs: npm run build tar -czf legacy.tar.gz -C ./dist . zip -rJ9 legacy.zip ./dist + npm run make-extension + zip -rJ9 extension.zip ./dist - name: Build Modern env: @@ -109,6 +111,16 @@ jobs: asset_name: modern.zip asset_content_type: application/zip + - name: Upload Release Assets - extension.zip + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./extension.zip + asset_name: extension.zip + asset_content_type: application/zip + - name: Upload Release Assets - sha256sum.txt uses: actions/upload-release-asset@v1.0.2 env: From ce2642ad1f8e36c738ecd3fc80890e47aebeec77 Mon Sep 17 00:00:00 2001 From: MengYX Date: Mon, 8 Feb 2021 03:02:33 +0800 Subject: [PATCH 4/5] Fix: [Extension] Remove inline script (for extension's Content Security Policy reason) Fix: [Extension] Disable Service Worker --- extension-manifest.json | 3 ++- public/index.html | 37 ++++-------------------------------- public/ixarea-stats.js | 10 ++++++++++ public/loader.js | 25 ++++++++++++++++++++++++ src/registerServiceWorker.js | 3 ++- 5 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 public/ixarea-stats.js create mode 100644 public/loader.js diff --git a/extension-manifest.json b/extension-manifest.json index ffcf14f..9aa8b61 100644 --- a/extension-manifest.json +++ b/extension-manifest.json @@ -11,5 +11,6 @@ "homepage_url": "https://github.com/ix64/unlock-music", "browser_action": { "default_popup": "./popup.html" - } + }, + "content_security_policy": "script-src 'self' https://stats.ixarea.com; object-src 'self'" } diff --git a/public/index.html b/public/index.html index bd60e18..33e39ab 100644 --- a/public/index.html +++ b/public/index.html @@ -5,13 +5,10 @@ - - - - 音乐解锁 + @@ -27,12 +24,12 @@ style="border:0"/>

请勿直接运行源代码!

-
- + diff --git a/public/ixarea-stats.js b/public/ixarea-stats.js new file mode 100644 index 0000000..5cb9f71 --- /dev/null +++ b/public/ixarea-stats.js @@ -0,0 +1,10 @@ +var _paq = window._paq || []; +_paq.push(["setRequestMethod", "POST"], ["trackPageView"], ["enableLinkTracking"], + ["setSiteId", "2"], ["setTrackerUrl", "https://stats.ixarea.com/ixarea-stats/report"]); + +var tag = document.createElement('script'); +tag.type = 'text/javascript'; +tag.async = true; +tag.src = 'https://stats.ixarea.com/ixarea-stats.js'; +var s = document.getElementsByTagName('script')[0]; +s.parentNode.insertBefore(tag, s); diff --git a/public/loader.js b/public/loader.js new file mode 100644 index 0000000..b257fa5 --- /dev/null +++ b/public/loader.js @@ -0,0 +1,25 @@ +(function () { + setTimeout(function () { + var ele = document.getElementById("loader-tips-timeout"); + if (ele != null) { + ele.hidden = false; + } + }, 2000); + + var ua = navigator && navigator.userAgent; + var detected = (function () { + var m; + if (!ua) return true; + if (/MSIE |Trident\//.exec(ua)) return true; // no IE + m = /Edge\/([\d.]+)/.exec(ua); // Edge >= 17 + if (m && Number(m[1]) < 17) return true; + m = /Chrome\/([\d.]+)/.exec(ua); // Chrome >= 58 + if (m && Number(m[1]) < 58) return true; + m = /Firefox\/([\d.]+)/.exec(ua); // Firefox >= 45 + return m && Number(m[1]) < 45; + })(); + if (detected) { + document.getElementById('loader-tips-outdated').hidden = false; + document.getElementById("loader-tips-timeout").hidden = false; + } +})(); diff --git a/src/registerServiceWorker.js b/src/registerServiceWorker.js index 5f6a312..a2c6497 100644 --- a/src/registerServiceWorker.js +++ b/src/registerServiceWorker.js @@ -2,7 +2,8 @@ import {register} from 'register-service-worker' -if (process.env.NODE_ENV === 'production') { +if (process.env.NODE_ENV === 'production' && window.location.protocol === "https:") { + register(`${process.env.BASE_URL}service-worker.js`, { ready() { console.log('App is being served from cache by a service worker.') From 549983a928590cddaade5688904a0ba6d44b6e3d Mon Sep 17 00:00:00 2001 From: MengYX Date: Mon, 8 Feb 2021 03:35:26 +0800 Subject: [PATCH 5/5] Adapt: [Extension] for Firefox --- src/extension/popup.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/extension/popup.js b/src/extension/popup.js index 244624f..cfb7565 100644 --- a/src/extension/popup.js +++ b/src/extension/popup.js @@ -1 +1,2 @@ -window.open(chrome.runtime.getURL('./index.html')); +const bs = chrome || browser +window.open(bs.runtime.getURL('./index.html'))