Completed
Push — master ( e07925...8add84 )
by Dongxin
31s
created

options.js ➔ setPreviewColor   B

Complexity

Conditions 1
Paths 128

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 128
nop 1
dl 0
loc 10
rs 8.8571
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
34
function onError(error) {
35
    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...
36
}
37
38
function saveOptions(e) {
39
    e.preventDefault();
40
    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...
41
        bgColor:      document.querySelector("#bgColor").value,
42
        intColor:     document.querySelector("#intColor").value,
43
        strColor:     document.querySelector("#strColor").value,
44
        keyColor:     document.querySelector("#keyColor").value,
45
        defaultColor: document.querySelector("#defaultColor").value,
46
        fontStyle:    document.querySelector("#fontStyle").value,
47
        fontSize:     document.querySelector("#fontSize").value,
48
49
        strictOnly:   document.querySelector("#strictOnly").checked,
50
        hideDetails:  document.querySelector("#hideDetails").checked,
51
        dontBeatify:  document.querySelector("#dontBeatify").checked,
52
        strLength:    document.querySelector("#strLength").value,
53
    });
54
    alert("Success");
55
    browser.storage.local.get().then(setCurrentChoice, onError);
56
}
57
58
function setCurrentChoice(result) {
59
    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...
60
    document.querySelector("#bgColor").value      = result.bgColor      || "#FDF6E3";
61
    document.querySelector("#intColor").value     = result.intColor     || "#657A81";
62
    document.querySelector("#strColor").value     = result.strColor     || "#2AA198";
63
    document.querySelector("#keyColor").value     = result.keyColor     || "#B58900";
64
    document.querySelector("#defaultColor").value = result.defaultColor || "#586E75";
65
    document.querySelector("#fontStyle").value    = result.fontStyle    || "Consolas";
66
    document.querySelector("#fontSize").value     = result.fontSize     || "14px";
67
    document.querySelector("#strLength").value    = result.strLength    || "300";
68
69
    document.querySelector("#strictOnly").checked  = result.strictOnly   || false;
70
    document.querySelector("#hideDetails").checked = result.hideDetails  || false;
71
    document.querySelector("#dontBeatify").checked = result.dontBeatify  || false;
72
73
    setPreviewColor(result);
74
}
75
76
function restoreOptions() {
77
    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...
78
}
79
80
document.addEventListener("DOMContentLoaded", restoreOptions);
81
document.querySelector("form").addEventListener("submit", saveOptions);
82