Skip to content
This repository was archived by the owner on Sep 22, 2020. It is now read-only.

Commit 05dc49c

Browse files
authored
1.0.0-beta.4 (#4)
The release of 1.0.0-beta.4 version.
1 parent c8d87bc commit 05dc49c

33 files changed

+1478
-312
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
# 1.0.0-beta.4 (3 мая, 2018)
2+
3+
## Расширение
4+
5+
### Новые функции
6+
7+
* Отслеживание посещаемости.
8+
9+
### Добавлено
10+
11+
* Добавлена поддержка для новых постов и ответов.
12+
* Добавлена опция выключения активных постов после создания скриншота.
13+
14+
### Изменено
15+
16+
* Изменено название всплывающего меню c 2сh+ на 2ch-helper.
17+
* Небольшие изменения в дизайне всплывающего меню.
18+
* Небольшие изменения в дизайне настроек.
19+
* После изменения настроек новые настройки буду действовать без перезагрузки страницы.
20+
21+
## Проект
22+
23+
### Добавлено
24+
25+
* Добавлены запасные шрифты.
26+
* Добавлена документация для недокументированных модулей.
27+
* Добавлена иконка github в папку icons.
28+
29+
### Изменено
30+
31+
* Незначительные изменения кода.
32+
* Изменены названия иконок.
33+
* Небольшие изменения в Readme.
34+
135
# 1.0.0-beta.3 (23 февраля, 2018)
236

337
## Расширение

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
- создание скриншота постов и треда.
2121
- загрузка изображений, видео и треда.
22+
- отслеживание статистики посещаемости.
2223

2324
## Системные требования
2425

@@ -28,11 +29,12 @@
2829

2930
**GitHub**
3031

31-
1. Скачайте этот репозиторий.
32-
2. Перейдите на вкладку <chrome://extensions>.
33-
3. Включите режим разработчика.
34-
4. Нажмите на "Загрузить распакованное расширение...".
35-
5. Выберите папку "extension".
32+
1. Перейдите в раздел [releases](https://github.com/Amaimersion/2ch-helper/releases).
33+
2. Скачайте Latest release версию.
34+
3. Перейдите на вкладку <chrome://extensions>.
35+
4. Включите режим разработчика.
36+
5. Нажмите на "Загрузить распакованное расширение...".
37+
6. Выберите папку "extension".
3638

3739
## Лицензия
3840

extension/interaction/js/scripts/background/background-API.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ BackgroundAPI.getUserSettings = function() {
4040
// what settings to receive.
4141
const settings = [
4242
'settings_screenshot',
43-
'settings_download'
43+
'settings_download',
44+
'statistics'
4445
];
4546

4647
chrome.storage.sync.get(settings, (data) => {
@@ -49,6 +50,43 @@ BackgroundAPI.getUserSettings = function() {
4950
}
5051

5152

53+
/**
54+
* Updates user settings.
55+
*
56+
* @memberof BackgroundAPI
57+
* @static
58+
* @async
59+
*/
60+
BackgroundAPI.updateUserSettings = function() {
61+
this.getUserSettings();
62+
}
63+
64+
65+
/**
66+
* Saves user settings.
67+
* If field passed, then saves certain field settings, else saves all settings.
68+
*
69+
* @memberof BackgroundAPI
70+
* @static
71+
*
72+
* @param {String} [field]
73+
* A field of settings for saving.
74+
* If passed, then other settings will not be saved.
75+
*
76+
* @param {function()} [callback]
77+
* A callback that executes after saving.
78+
*/
79+
BackgroundAPI.saveUserSettings = function(field, callback) {
80+
callback = callback || function() {};
81+
82+
if (field) {
83+
chrome.storage.sync.set(this.userSettings[field], callback);
84+
} else {
85+
chrome.storage.sync.set(this.userSettings, callback);
86+
}
87+
}
88+
89+
5290
/**
5391
* Injects a script into the page.
5492
*

extension/interaction/js/scripts/background/background-on-message.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ BackgroundMessage.commandHandler = async function(request, sendResponse) {
141141
}
142142

143143
sendResponse({status: true});
144+
145+
} else if (command === 'updateUserSettings') {
146+
BackgroundAPI.updateUserSettings();
147+
sendResponse({status: true});
148+
149+
} else if (command === 'updateStatistics') {
150+
try {
151+
await BackgroundStatistics.updateStatistics(
152+
request.field, request.data
153+
);
154+
} catch (error) {
155+
throw error;
156+
}
144157
}
145158
}
146159

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/**
2+
* The module that handles statistics requests.
3+
*
4+
* @module BackgroundStatistics
5+
*/
6+
function BackgroundStatistics() {}
7+
8+
9+
/**
10+
* A names of settings in user profile.
11+
*
12+
* @memberof BackgroundStatistics
13+
* @static
14+
* @type {Object}
15+
*/
16+
BackgroundStatistics.fields = {
17+
main: 'statistics',
18+
totalSecondsSpent: 'totalSecondsSpent'
19+
};
20+
21+
22+
/**
23+
* Handles requests for statistics updates.
24+
*
25+
* @memberof BackgroundStatistics
26+
* @static
27+
* @async
28+
*
29+
* @param {String} field
30+
* A field of statistics for update.
31+
*
32+
* @param {Object} data
33+
* A data for update.
34+
*
35+
* @returns {Promise<void | Error>}
36+
* A promise for the update that will resolve when the update will end.
37+
* Resolve will contain nothing if success, otherwise reject will contain an error.
38+
*/
39+
BackgroundStatistics.updateStatistics = function(field, data) {
40+
return new Promise(async (resolve, reject) => {
41+
if (field === 'totalSecondsSpent') {
42+
try {
43+
await this.updateTotalSecondsSpent(
44+
data.loadedDate,
45+
data.closedDate
46+
);
47+
} catch (error) {
48+
return reject(error);
49+
}
50+
51+
return resolve();
52+
} else {
53+
const error = new Error();
54+
erroe.message = 'An unknown field.';
55+
56+
return reject(error);
57+
}
58+
});
59+
}
60+
61+
62+
/**
63+
* Handles 'totalSecondsSpent' field update.
64+
*
65+
* @memberof BackgroundStatistics
66+
* @static
67+
* @async
68+
*
69+
* @param {Number} loadedMs
70+
* A time of opening the page in milliseconds.
71+
*
72+
* @param {Number} closedMs
73+
* A time of closing the page in milliseconds.
74+
*
75+
* @returns {Promise<void | Error>}
76+
* A promise for the update that will resolve when the update will end.
77+
* Resolve will contain nothing if success, otherwise reject will contain an error.
78+
*/
79+
BackgroundStatistics.updateTotalSecondsSpent = function(loadedMs, closedMs) {
80+
return new Promise(async (resolve, reject) => {
81+
let seconds = 0;
82+
83+
seconds = closedMs - loadedMs;
84+
seconds /= 1000;
85+
seconds = Math.round(seconds);
86+
87+
const mainField = this.fields.main;
88+
const field = this.fields.totalSecondsSpent;
89+
90+
seconds += BackgroundAPI.userSettings[mainField][field];
91+
92+
try {
93+
await this.updateStatisticsField(field, seconds);
94+
} catch (error) {
95+
return reject(error);
96+
}
97+
98+
return resolve();
99+
});
100+
}
101+
102+
103+
/**
104+
* Updates certain field of user settings.
105+
*
106+
* @memberof BackgroundStatistics
107+
* @static
108+
* @async
109+
*
110+
* @param {String} field
111+
* A field to set.
112+
*
113+
* @param {any} value
114+
* A value to set.
115+
*
116+
* @returns {Promise<void | Error>}
117+
* A promise for the update that will resolve when the update will end.
118+
* Resolve will contain nothing if success, otherwise reject will contain an error.
119+
*/
120+
BackgroundStatistics.updateStatisticsField = function(field, value) {
121+
return new Promise((resolve, reject) => {
122+
const mainField = this.fields.main;
123+
const errorOccurrence = this.createErrorOccurrence(reject);
124+
console.log(errorOccurrence);
125+
126+
BackgroundAPI.userSettings[mainField][field] = value;
127+
128+
BackgroundAPI.saveUserSettings(mainField, () => {
129+
window.clearTimeout(errorOccurrence);
130+
return resolve();
131+
});
132+
});
133+
}
134+
135+
136+
/**
137+
* Creates timeout limit error occurrence.
138+
* Created to work in Promise.
139+
*
140+
* @memberof BackgroundStatistics
141+
* @static
142+
*
143+
* @param {Function} reject
144+
* A reject from Promise that will contain an error.
145+
*
146+
* @param {Number} [delay=5000]
147+
* Through how many milliseconds will happen timeout limit.
148+
* Defaults to 5000.
149+
*
150+
* @returns {Number}
151+
* A positive integer value which identifies the timer.
152+
*/
153+
BackgroundStatistics.createErrorOccurrence = function(reject, delay) {
154+
delay = delay || 5000;
155+
156+
return window.setTimeout(() => {
157+
const error = new Error();
158+
error.message = 'Timeout limit.';
159+
160+
reject(error);
161+
}, delay);
162+
}

extension/interaction/js/scripts/background/background-user-profile.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ UserProfile.defaultProfile = {
2121
fileNameThread: 'thread',
2222
format: 'jpeg',
2323
quality: 100,
24+
turnOffPostsYes: true,
25+
turnOffPostsNo: false,
2426
delay: 500
2527
},
2628

@@ -29,6 +31,10 @@ UserProfile.defaultProfile = {
2931
userName: false,
3032
fileName: '',
3133
delay: 500
34+
},
35+
36+
statistics: {
37+
totalSecondsSpent: 0
3238
}
3339
};
3440

extension/interaction/js/scripts/content/content-API.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ ContentAPI.getUserSettings = function() {
197197
chrome.storage.sync.get(settings, (data) => {
198198
this.userSettings = data;
199199
});
200+
201+
}
202+
203+
204+
/**
205+
* Updates user settings.
206+
*
207+
* @memberof ContentAPI
208+
* @static
209+
* @async
210+
*/
211+
ContentAPI.updateUserSettings = function() {
212+
this.getUserSettings();
200213
}
201214

202215

0 commit comments

Comments
 (0)