-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathcommon.js
53 lines (30 loc) · 953 Bytes
/
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
function log() {
if( !verbose ) return;
var args = Array.from( arguments );
args.unshift( 'background: #007AA3; color: #ffffff; text-shadow: 0 -1px #000; padding: 4px 0 4px 0; line-height: 0' );
args.unshift( `%c WebVREmu ` );
console.log.apply( console, args );
}
function fixSettings( settings ) {
if( settings === undefined ) return defaultSettings;
var res = {}
Object.keys( defaultSettings ).forEach( f => {
res[ f ] = ( settings[ f ] !== undefined ) ? settings[ f ] : defaultSettings[ f ];
} );
return res;
}
// chrome.storage can store Objects directly
function loadSettings() {
return new Promise( ( resolve, reject ) => {
chrome.storage.local.get( 'settings', obj => {
resolve( fixSettings( obj.settings ) );
} );
} );
}
function saveSettings( settings ) {
return new Promise( ( resolve, reject ) => {
chrome.storage.local.set( { 'settings': settings }, obj => {
resolve( obj );
} );
} );
}