forked from samuraiexx/roll_together
-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.js
82 lines (70 loc) · 1.95 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Constants and functions used by both background.js and content_script.js
const DEBUG = true;
const DISPLAY_DEBUG_TIME = false;
const LIMIT_DELTA_TIME = 3; // In Seconds
const googleGreen = "#009688";
const googleAquaBlue = "#00BBD3";
const crunchyrollOrange = "#F78C25";
const wRed = "#F72445";
const chineseSilver = "#CCC";
const defaultcolorOptions = [googleGreen, googleAquaBlue, crunchyrollOrange, wRed];
const Actions = {
PLAY: 'play',
PAUSE: 'pause',
READY: 'ready',
ENDED: 'ended',
TIMEUPDATE: 'timeupdate',
}
const States = {
PLAYING: 'playing',
PAUSED: 'paused',
}
const Site = {
FUNIMATION: 'funimation',
CRUNCHYROLL: 'crunchyroll',
WAKANIM: 'wakanim',
}
// For messages generated by background.js capturing actions from the server.
const BackgroundMessageTypes = {
REMOTE_UPDATE: 'remote_update',
ROOM_CONNECTION: 'room_connection'
}
// For messages generated by content_script.js capturing actions on the webpage.
const WebpageMessageTypes = {
LOCAL_UPDATE: 'local_update',
ROOM_CONNECTION: 'room_connection',
CONNECTION: 'connection',
}
function log() {
const args = DISPLAY_DEBUG_TIME ? [(new Date()).toJSON()] : [];
args.push(...arguments);
return DEBUG && console.log(...args);
}
function getBackendUrl() {
return new Promise(callback => {
chrome.storage.sync.get({ backendUrl: "" }, function (data) {
callback(data.backendUrl);
});
});
}
function getDefaultRoomId() {
return new Promise(callback => {
chrome.storage.sync.get({ defaultRoomId: "" }, function (data) {
callback(data.defaultRoomId);
});
});
}
function getExtensionColor() {
return new Promise(callback => {
chrome.storage.sync.get({ extensionColor: wRed }, function (data) {
callback(data.extensionColor);
});
});
}
function getColorMenu() {
return new Promise(callback => {
chrome.storage.sync.get({ colorOptions: defaultcolorOptions }, function (data) {
callback(data.colorOptions);
});
});
}