Skip to content

Commit

Permalink
release v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
doufen-org committed Aug 23, 2019
1 parent 006cbba commit f61233a
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 33 deletions.
10 changes: 7 additions & 3 deletions extension/backup.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@
</div>
</div>
</div>
<div class="content">
<p class="help"><strong>注意:</strong>仅备份当前登录用户的数据。如需备份其他账号数据,请先退出当前账号,再登录需要备份的账号。</p>
</div>
</div>
<div class="container thin" id="accounts">
<!-- accounts -->
Expand Down Expand Up @@ -202,6 +199,13 @@
<input type="text" class="input" name="user-homepage" placeholder="输入用户主页。例如:https://www.douban.com/people/doufen-org/" disabled>
</p>
</div>
<div class="field">
<div class="control">
<label class="checkbox">
<input type="checkbox" name="task" value="Files"> 同步相册、日记、评论以及广播中的图片至 <a href="https://cloudinary.com/" target="_blank">Cloudinary</a>
</label>
</div>
</div>
</fieldset>
<p class="help">
<span class="icon is-size-6 has-text-danger">
Expand Down
2 changes: 1 addition & 1 deletion extension/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ class Photo extends Panel {
for (let { photo, version } of collection) {
let $photo = $(TEMPLATE_PHOTO);
$photo.find('.image img').attr('src', photo.cover).click(() => {
PictureModal.show(photo.cover.replace('/m/','/l/'));
PictureModal.show(photo.raw);
});
$photo.find('.description').text(photo.description);
version < currentVersion && $photo.addClass('is-obsolete');
Expand Down
4 changes: 2 additions & 2 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "豆伴:豆瓣账号备份工具",
"short_name": "豆伴",
"author": "豆坟",
"version": "0.4.2",
"version_name": "0.4.2 beta",
"version": "0.5.0",
"version_name": "0.5.0 beta",
"description": "能将指定的豆瓣用户数据备份到本地,并支持导出 Excel 文档。",
"manifest_version": 2,
"icons": {
Expand Down
15 changes: 14 additions & 1 deletion extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</div>
<div class="columns">
<div class="column is-10">
<label>请求间隔</label>
<label>请求间隔</label>
<p class="help">请求间隔过短可能导致被豆瓣服务器屏蔽。</p>
</div>
<div class="column">
Expand All @@ -112,6 +112,19 @@
</div>
</div>
</div>
<div class="columns">
<div class="column is-10">
<label>图片云存储 <a href="https://blog.doufen.org/posts/how-to-upload-images-to-cloudinary/" class="tag is-success">如何设置</a></label>
<p class="help">允许将广播、日记、评论以及相册中的图片上传到 <a href="https://cloudinary.com/" target="_blank">Cloudinary</a> 云存储中。</p>
</div>
<div class="column">
<div class="field">
<p class="control">
<input class="input" type="text" name="同步图片.cloudName" placeholder="Cloud name">
</p>
</div>
</div>
</div>
<div class="field is-grouped is-grouped-centered">
<p class="control">
<a class="button is-link" name="save">保存</a>
Expand Down
37 changes: 26 additions & 11 deletions extension/options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Settings from './settings.js';
import {SERVICE_SETTINGS, Task} from './service.js';
import {SERVICE_SETTINGS} from './service.js';
import {TASK_FILES_SETTINGS} from './tasks/files.js';
import Notification from './ui/notification.js';
import TabPanel from './ui/tab.js';

Expand Down Expand Up @@ -123,10 +124,21 @@ class GeneralPanel {
}
};

let TextInput = class extends Control {
set value(value) {
value && (this.element.value = value);
}

get value() {
return this.element.value || '';
}
};

const CONTROL_METAS = [
//{name: 'assistant.enable', type: BoolSwitch},
{name: 'service.debug', type: BoolSwitch},
{name: 'service.requestInterval', type: TimeInput},
{name: '同步图片.cloudName', type: TextInput},
];

this.controls = new Object();
Expand All @@ -138,34 +150,37 @@ class GeneralPanel {
this.saveButton = document.querySelector('.button[name="save"]');
this.resetButton = document.querySelector('.button[name="reset"]');

this.saveButton.addEventListener('click', event => {
this.saveButton.addEventListener('click', async () => {
for (let name in this.controls) {
this.settings[name] = this.controls[name].value;
}
this.save(this.settings);
await this.save(this.settings);
});

this.resetButton.addEventListener('click', event => {
this.resetButton.addEventListener('click', async () => {
for (let name in this.controls) {
this.controls[name].value = this.defaults[name];
}
this.save(this.defaults);
await this.save(this.defaults);
});
}

save(settings) {
async save(settings) {
try {
chrome.storage.sync.set(settings, result => {
Notification.show('保存成功');
});
await Settings.save(settings);
let service = (await new Promise(resolve => {
chrome.runtime.getBackgroundPage(resolve);
})).service;
service.loadSettings();
Notification.show('保存成功');
} catch (e) {
Notification.show('保存失败', {type: 'danger'});
}
}

static async render() {
let settings = await Settings.load(SERVICE_SETTINGS);
let defaults = SERVICE_SETTINGS;
let settings = await Settings.load(SERVICE_SETTINGS, TASK_FILES_SETTINGS);
let defaults = Object.assign({}, SERVICE_SETTINGS, TASK_FILES_SETTINGS);
return new GeneralPanel('.page-tab-content[name="general"]', settings, defaults);
}
}
Expand Down
24 changes: 17 additions & 7 deletions extension/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Storage from './storage.js';
export const SERVICE_SETTINGS = {
'service.debug': false,
'service.requestInterval': 1000,
'service.cloudinary': '',
};


Expand Down Expand Up @@ -488,6 +489,9 @@ class StateChangeEvent extends Event {
* Class Service
*/
export default class Service extends EventTarget {
/**
* Constructor
*/
constructor() {
super();
Object.assign(this, {
Expand All @@ -504,6 +508,16 @@ export default class Service extends EventTarget {
chrome.runtime.onConnect.addListener(port => this.onConnect(port));
}

/**
* Load settings
*/
async loadSettings() {
let settings = await Settings.load(SERVICE_SETTINGS);
Settings.apply(this, settings);
this.logger.debug('Service settings loaded.');
return this;
}

/**
* Get name
*/
Expand Down Expand Up @@ -775,13 +789,9 @@ export default class Service extends EventTarget {
static async startup() {
const RUN_FOREVER = true;

let service = Service.instance;
let service = await Service.instance.loadSettings();
let logger = service.logger;

let settings = await Settings.load(SERVICE_SETTINGS);
Settings.apply(service, settings);
logger.debug('Service settings loaded.');

let browserMainVersion = (/Chrome\/([0-9]+)/.exec(navigator.userAgent)||[,0])[1];
let extraOptions = (browserMainVersion >= 72) ? ['blocking', 'requestHeaders', 'extraHeaders'] : ['blocking', 'requestHeaders'];

Expand All @@ -795,10 +805,10 @@ export default class Service extends EventTarget {
return {requestHeaders: details.requestHeaders};
}, {urls: ['http://*.douban.com/*', 'https://*.douban.com/*']}, extraOptions);
let lastRequest = 0;
let fetchURL = (resource, init) => {
let fetchURL = (resource, init, continuous = false) => {
let promise = service.continue();
let requestInterval = lastRequest + service.requestInterval - Date.now();
if (requestInterval > 0) {
if (!continuous && requestInterval > 0) {
promise = promise.then(() => {
return new Promise(resolve => {
setTimeout(resolve, requestInterval);
Expand Down
12 changes: 7 additions & 5 deletions extension/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
* Class Settings
*/
export default class Settings {
constructor (settings, defaults) {
return Object.assign(defaults, settings);
}

static apply(target, settings) {
for (let key in settings) {
try {
Expand All @@ -28,6 +24,12 @@ export default class Settings {
let settings = await new Promise(resolve => {
chrome.storage.sync.get(Object.keys(defaults), resolve);
});
return new Settings(settings, defaults);
return Object.assign({}, defaults, settings);
}

static async save(settings) {
return await new Promise(resolve => {
chrome.storage.sync.set(settings, resolve);
});
}
}
3 changes: 3 additions & 0 deletions extension/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const SCHEMA_LOCAL = [
doumailContact: 'id, rank',
version: 'table, version',
},
{
files: '++id, &url',
},
];


Expand Down
2 changes: 1 addition & 1 deletion extension/tasks/doumail.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Photo extends Task {
};
let readMore = true;
for (let start = 0; readMore; start += PAGE_SIZE) {
let postData = new FormData();
let postData = new URLSearchParams();
postData.append('start', start);
postData.append('target_id', userId);
postData.append('ck', this.session.cookies.ck);
Expand Down
Loading

0 comments on commit f61233a

Please sign in to comment.