From 99f7acd35bf69723acfcf2d8fca399b600725550 Mon Sep 17 00:00:00 2001 From: acgotaku Date: Sun, 10 Jun 2018 19:30:37 +0900 Subject: [PATCH] add 0.3.2 version --- background.js | 10 ++++++---- manifest.json | 2 +- package-lock.json | 2 +- package.json | 2 +- src/js/home.js | 12 ++++++++---- src/js/lib/core.js | 8 +++++++- src/js/lib/ui.js | 4 ++-- src/js/start.js | 4 +++- 8 files changed, 29 insertions(+), 15 deletions(-) diff --git a/background.js b/background.js index f6c01ea0..514fe391 100644 --- a/background.js +++ b/background.js @@ -47,7 +47,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { // Promise style `chrome.cookies.get()` const getCookie = (detail) => { return new Promise(function (resolve) { - chrome.cookies.get(detail, resolve) + chrome.cookies.getAll(detail, resolve) }) } @@ -56,9 +56,11 @@ const getCookies = (details) => { const list = details.map(item => getCookie(item)) Promise.all(list).then(function (cookies) { let obj = {} - for (let item of cookies) { - if (item !== null) { - obj[item.name] = item.value + for (let cookie of cookies) { + for (let item of cookie) { + if (item !== null) { + obj[item.name] = item.value + } } } resolve(obj) diff --git a/manifest.json b/manifest.json index 590fb0c5..3fc60b7f 100644 --- a/manifest.json +++ b/manifest.json @@ -24,5 +24,5 @@ "manifest_version": 2, "permissions": [ "cookies", "storage", "tabs", "*://*.115.com/*"], "name": "__MSG_appName__", - "version": "0.3.1" + "version": "0.3.2" } diff --git a/package-lock.json b/package-lock.json index d93ee029..1d9458c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "115", - "version": "0.3.1", + "version": "0.3.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 51758cab..455adee1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "115", - "version": "0.3.1", + "version": "0.3.2", "description": "Assistant for 115 to export download links to aria2-rpc.", "main": "background.js", "scripts": { diff --git a/src/js/home.js b/src/js/home.js index 570b20dd..b3cb31fb 100644 --- a/src/js/home.js +++ b/src/js/home.js @@ -25,7 +25,6 @@ class Home extends Downloader { UI.addContextMenuRPCSectionWithCallback(() => { this.addContextMenuEventListener() }) - Core.requestCookies([{ url: 'http://115.com/', name: 'UID' }, { url: 'http://115.com/', name: 'CID' }, { url: 'http://115.com/', name: 'SEID' }]) Core.showToast('初始化成功!', 'inf') this.mode = 'RPC' this.rpcURL = 'http://localhost:6800/jsonrpc' @@ -108,7 +107,11 @@ class Home extends Downloader { fetch(`//webapi.115.com/files/download?pickcode=${file}`, options).then((response) => { if (response.ok) { response.json().then((data) => { - resolve(data) + const path = data.file_url.match(/.*115.com(\/.*\/)/)[1] + Core.requestCookies([{path}]).then((cookies) => { + data.cookies = cookies + resolve(data) + }) }) } else { console.log(response) @@ -127,10 +130,11 @@ class Home extends Downloader { this.fileDownloadInfo.push({ name: files[item.pickcode].path + item.file_name, link: item.file_url, - sha1: files[item.pickcode].sha1 + sha1: files[item.pickcode].sha1, + cookies: item.cookies }) + resolve() }) - resolve() }) }) } diff --git a/src/js/lib/core.js b/src/js/lib/core.js index 9ef336d4..f8951f92 100644 --- a/src/js/lib/core.js +++ b/src/js/lib/core.js @@ -147,11 +147,16 @@ class Core { } // cookies format [{"url": "http://pan.baidu.com/", "name": "BDUSS"},{"url": "http://pcs.baidu.com/", "name": "pcsett"}] requestCookies (cookies) { - this.sendToBackground('getCookies', cookies, (value) => { this.cookies = value }) + return new Promise((resolve) => { + this.sendToBackground('getCookies', cookies, (value) => { + resolve(value) + }) + }) } aria2RPCMode (rpcPath, fileDownloadInfo) { const {authStr, path, options} = this.parseURL(rpcPath) fileDownloadInfo.forEach((file) => { + this.cookies = file.cookies const rpcData = { jsonrpc: '2.0', method: 'aria2.addUri', @@ -193,6 +198,7 @@ class Core { const downloadLinkTxt = [] const prefixTxt = 'data:text/plain;charset=utf-8,' fileDownloadInfo.forEach((file) => { + this.cookies = file.cookies let aria2CmdLine = `aria2c -c -s10 -k1M -x16 --enable-rpc=false -o ${JSON.stringify(file.name)} ${this.getHeader('aria2Cmd')} ${JSON.stringify(file.link)}` let aria2Line = [file.link, this.getHeader('aria2c'), ` out=${file.name}`].join('\n') const sha1Check = this.getConfigData('sha1Check') diff --git a/src/js/lib/ui.js b/src/js/lib/ui.js index 8dea5089..7ba84496 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.3.1' - this.updateDate = '2018/06/05' + this.version = '0.3.2' + this.updateDate = '2018/06/10' this.context = document.querySelector('iframe[rel="wangpan"]').contentDocument Store.on('updateView', (configData) => { this.updateSetting(configData) diff --git a/src/js/start.js b/src/js/start.js index 702c1bd6..f625ff54 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -11,4 +11,6 @@ function add115JS () { } } -iframe.addEventListener('load', add115JS) +if (iframe) { + iframe.addEventListener('load', add115JS) +}