Completed
Push — master ( c8749b...21bf41 )
by Dongxin
32s
created

options/options.js   A

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 62
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 62
rs 10
wmc 5
mnd 0
bc 5
fnc 5
bpm 1
cpm 1
noi 6

4 Functions

Rating   Name   Duplication   Size   Complexity  
A options.js ➔ restoreOptions 0 3 1
A options.js ➔ saveOptions 0 19 1
A options.js ➔ onError 0 3 1
A options.js ➔ setCurrentChoice 0 16 1
1
//////////////////////////////////////////////////////////////////////////////////////
2
// Copyright © 2017 TangDongxin
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining
5
// a copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
//////////////////////////////////////////////////////////////////////////////////////
22
23
function setPreviewColor(result) {
24
    console.log("load Color");
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
25
    document.querySelector("#fontStyleLabel").style.fontFamily    = result.fontStyle    || "Consolas";
26
    document.querySelector("#fontSizeLabel").style.fontSize       = result.fontSize     || "14px";
27
    document.querySelector("#bgColorLabel").style.backgroundColor = result.bgColor      || "#FDF6E3";
28
    document.querySelector("#intColorLabel").style.color          = result.intColor     || "#657A81";
29
    document.querySelector("#strColorLabel").style.color          = result.strColor     || "#2AA198";
30
    document.querySelector("#keyColorLabel").style.color          = result.keyColor     || "#B58900";
31
    document.querySelector("#defaultColorLabel").style.color      = result.defaultColor || "#586E75";
32
33
    document.querySelector("#strictOnly").checked                 = result.strictOnly   || false;
34
    document.querySelector("#hideDetails").checked                = result.hideDetails  || false;
35
    document.querySelector("#dontBeatify").checked                = result.dontBeatify  || false;
36
}
37
38
function onError(error) {
39
    console.log(`Error: ${error}`);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
40
}
41
42
function saveOptions(e) {
43
    e.preventDefault();
44
    browser.storage.local.set({
0 ignored issues
show
Bug introduced by
The variable browser seems to be never declared. If this is a global, consider adding a /** global: browser */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
45
        bgColor:      document.querySelector("#bgColor").value,
46
        intColor:     document.querySelector("#intColor").value,
47
        strColor:     document.querySelector("#strColor").value,
48
        keyColor:     document.querySelector("#keyColor").value,
49
        defaultColor: document.querySelector("#defaultColor").value,
50
        fontStyle:    document.querySelector("#fontStyle").value,
51
        fontSize:     document.querySelector("#fontSize").value,
52
53
        strictOnly:   document.querySelector("#strictOnly").checked,
54
        hideDetails:  document.querySelector("#hideDetails").checked,
55
        dontBeatify:  document.querySelector("#dontBeatify").checked
56
    });
57
    console.log(document.querySelector("#fontSize").value);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
58
    alert("Success");
59
    browser.storage.local.get().then(setCurrentChoice, onError);
60
}
61
62
function setCurrentChoice(result) {
63
    console.log(result);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
64
    document.querySelector("#bgColor").value      = result.bgColor      || "#FDF6E3";
65
    document.querySelector("#intColor").value     = result.intColor     || "#657A81";
66
    document.querySelector("#strColor").value     = result.strColor     || "#2AA198";
67
    document.querySelector("#keyColor").value     = result.keyColor     || "#B58900";
68
    document.querySelector("#defaultColor").value = result.defaultColor || "#586E75";
69
    document.querySelector("#fontStyle").value    = result.fontStyle    || "Consolas";
70
    document.querySelector("#fontSize").value     = result.fontSize     || "14px";
71
72
    document.querySelector("#strictOnly").checked  = result.strictOnly   || false;
73
    document.querySelector("#hideDetails").checked = result.hideDetails  || false;
74
    document.querySelector("#dontBeatify").checked = result.dontBeatify  || false;
75
76
    setPreviewColor(result);
77
}
78
79
function restoreOptions() {
80
    browser.storage.local.get().then(setCurrentChoice, onError);
0 ignored issues
show
Bug introduced by
The variable browser seems to be never declared. If this is a global, consider adding a /** global: browser */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
81
}
82
83
document.addEventListener("DOMContentLoaded", restoreOptions);
84
document.querySelector("form").addEventListener("submit", saveOptions);
85