Completed
Push — master ( 646bd3...d1ab70 )
by Dongxin
24s
created

options.js (5 issues)

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
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
25
    document.getElementById("fontLabel").style.fontFamily         = result.fontStyle    || "Consolas";
26
    document.querySelector("#bgColorLabel").style.backgroundColor = result.bgColor      || "#FDF6E3";
27
    document.querySelector("#intColorLabel").style.color          = result.intColor     || "#657A81";
28
    document.querySelector("#strColorLabel").style.color          = result.strColor     || "#2AA198";
29
    document.querySelector("#keyColorLabel").style.color          = result.keyColor     || "#B58900";
30
    document.querySelector("#defaultColorLabel").style.color      = result.defaultColor || "#586E75";
31
32
    document.querySelector("#strictOnly").checked                 = result.strictOnly   || false;
33
    document.querySelector("#hideDetails").checked                = result.hideDetails  || false;
34
}
35
36
function onError(error) {
37
    console.log(`Error: ${error}`);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
38
}
39
40
function saveOptions(e) {
41
    e.preventDefault();
42
    browser.storage.local.set({
0 ignored issues
show
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...
43
        bgColor:      document.querySelector("#bgColor").value,
44
        intColor:     document.querySelector("#intColor").value,
45
        strColor:     document.querySelector("#strColor").value,
46
        keyColor:     document.querySelector("#keyColor").value,
47
        defaultColor: document.querySelector("#defaultColor").value,
48
        fontStyle:    document.querySelector("#fontStyle").value,
49
50
        strictOnly:   document.querySelector("#strictOnly").checked,
51
        hideDetails:  document.querySelector("#hideDetails").checked
52
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
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
67
    document.querySelector("#strictOnly").checked  = result.strictOnly   || false;
68
    document.querySelector("#hideDetails").checked = result.hideDetails  || false;
69
70
    setPreviewColor(result);
71
}
72
73
function restoreOptions() {
74
    browser.storage.local.get().then(setCurrentChoice, onError);
0 ignored issues
show
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...
75
}
76
77
document.addEventListener("DOMContentLoaded", restoreOptions);
78
document.querySelector("form").addEventListener("submit", saveOptions);
79