diff --git a/background.js b/background.js index 1918a0a0..2a9e16c1 100644 --- a/background.js +++ b/background.js @@ -15,10 +15,13 @@ const httpSend = ({ url, options }, resolve, reject) => { chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { switch (request.method) { case 'addScript': - chrome.tabs.executeScript(sender.tab.id, { file: request.data }) + chrome.scripting.executeScript({ + target: { tabId: sender.tab.id }, + files: [request.data] + }) break case 'rpcData': - httpSend(request.data, (data) => { + httpSend(request.data, () => { sendResponse(true) }, (err) => { console.log(err) @@ -77,25 +80,26 @@ const getCookies = (details) => { } const showNotification = (id, opt) => { - if (!chrome.notifications) { - return - } chrome.notifications.create(id, opt, () => {}) setTimeout(() => { chrome.notifications.clear(id, () => {}) }, 5000) } // 软件版本更新提示 -const manifest = chrome.runtime.getManifest() -const previousVersion = localStorage.getItem('version') -if (previousVersion === '' || previousVersion !== manifest.version) { - const opt = { - type: 'basic', - title: '更新', - messa0ge: '115助手更新到' + manifest.version + '版本啦~\n此次更新添加会员下载功能~', - iconUrl: 'img/icon.jpg' +(async () => { + const manifest = chrome.runtime.getManifest() + const { version: previousVersion } = await chrome.storage.local.get('version') + if (previousVersion === '' || previousVersion !== manifest.version) { + const opt = { + type: 'basic', + title: '更新', + message: '115助手更新到' + manifest.version + '版本啦~\n此次更新升级到Manifest V3~', + iconUrl: 'img/icon.jpg' + } + const id = new Date().getTime().toString() + showNotification(id, opt) + await chrome.storage.local.set({ + version: manifest.version + }) } - const id = new Date().getTime().toString() - showNotification(id, opt) - localStorage.setItem('version', manifest.version) -} +})() diff --git a/gulpfile.esm.js b/gulpfile.esm.js index 70dea79c..49a2eedd 100644 --- a/gulpfile.esm.js +++ b/gulpfile.esm.js @@ -22,6 +22,8 @@ import plumber from 'gulp-plumber' import terser from 'gulp-terser' +import zip from 'gulp-zip' + const sass = gulpSass(dartSass) const paths = { @@ -132,9 +134,15 @@ function watch () { gulp.watch(paths.styles.src, styles) } +export function compress () { + return gulp.src(paths.compress.src) + .pipe(zip('chrome.zip')) + .pipe(gulp.dest(paths.compress.dest)) +} + const build = gulp.parallel(scripts, styles, images, copys, copyVendor) const serve = gulp.series(clean, build, watch) -const publish = gulp.series(clean, build) +const publish = gulp.series(clean, build, compress) exports.build = build exports.serve = serve diff --git a/manifest.json b/manifest.json index c3493dc9..1a8640ac 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,6 @@ { "background": { - "scripts": ["background.js"], - "persistent": false + "service_worker": "background.js" }, "content_scripts": [ { @@ -27,9 +26,13 @@ "48": "img/logo48.png", "128": "img/logo128.png" }, - "web_accessible_resources": ["js/115.js"], - "manifest_version": 2, - "permissions": ["cookies", "storage", "tabs", "*://*.115.com/*"], + "web_accessible_resources": [{ + "resources": ["js/115.js"], + "matches": ["*://*.115.com/*"] + }], + "manifest_version": 3, + "permissions": ["cookies", "storage", "notifications", "scripting"], + "host_permissions": ["*://*.115.com/*"], "name": "__MSG_appName__", - "version": "0.4.3" + "version": "0.5.0" } diff --git a/package.json b/package.json index a6ebd436..fb074c36 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dev": "cross-env NODE_ENV=development gulp serve", "build": "cross-env NODE_ENV=production gulp publish", "clean": "gulp clean", - "eslint:fix": "eslint --fix src", + "eslint:fix": "eslint --fix src background.js", "stylelint:fix": "stylelint \"src/**/*.scss\" --fix", "lint:fix": "npm run stylelint:fix && npm run eslint:fix" }, @@ -49,6 +49,7 @@ "gulp-rollup-each": "^4.0.1", "gulp-sass": "^5.1.0", "gulp-terser": "^2.0.1", + "gulp-zip": "^5.1.0", "imagemin-mozjpeg": "^9.0.0", "imagemin-pngquant": "^9.0.2", "postcss": "^8.4.14", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e8596aea..c571ff18 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,7 @@ specifiers: gulp-rollup-each: ^4.0.1 gulp-sass: ^5.1.0 gulp-terser: ^2.0.1 + gulp-zip: ^5.1.0 imagemin-mozjpeg: ^9.0.0 imagemin-pngquant: ^9.0.2 postcss: ^8.4.14 @@ -58,6 +59,7 @@ devDependencies: gulp-rollup-each: 4.0.1 gulp-sass: 5.1.0 gulp-terser: 2.1.0 + gulp-zip: 5.1.0_gulp@4.0.2 imagemin-mozjpeg: 9.0.0 imagemin-pngquant: 9.0.2 postcss: 8.4.14 @@ -2847,6 +2849,23 @@ packages: vinyl-sourcemaps-apply: 0.2.1 dev: true + /gulp-zip/5.1.0_gulp@4.0.2: + resolution: {integrity: sha512-XZr/y91IliK/SpR74g3TkZejGkGEmK7CSDjSghT1jXshgO+dFvpLIz9w9fpuwkew6i7k4F+G24TubNgq1ISzEw==} + engines: {node: '>=8'} + peerDependencies: + gulp: '>=4' + peerDependenciesMeta: + gulp: + optional: true + dependencies: + get-stream: 5.2.0 + gulp: 4.0.2 + plugin-error: 1.0.1 + through2: 3.0.2 + vinyl: 2.2.1 + yazl: 2.5.1 + dev: true + /gulp/4.0.2: resolution: {integrity: sha512-dvEs27SCZt2ibF29xYgmnwwCYZxdxhQ/+LFWlbAW8y7jt68L/65402Lz3+CKy0Ov4rOs+NERmDq7YlZaDqUIfA==} engines: {node: '>= 0.10'} @@ -6219,3 +6238,9 @@ packages: buffer-crc32: 0.2.13 fd-slicer: 1.1.0 dev: true + + /yazl/2.5.1: + resolution: {integrity: sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw==} + dependencies: + buffer-crc32: 0.2.13 + dev: true diff --git a/src/js/lib/ui.js b/src/js/lib/ui.js index 74c0b36b..56ed7c59 100644 --- a/src/js/lib/ui.js +++ b/src/js/lib/ui.js @@ -3,8 +3,8 @@ import Store from './store' class UI { constructor () { - this.version = '0.4.3' - this.updateDate = '2022/06/09' + this.version = '0.5.0' + this.updateDate = '2022/07/03' Store.on('updateView', (configData) => { this.updateSetting(configData) this.updateMenu(configData)