Completed
Push — master ( cf6cc8...8131ad )
by Dongxin
41s
created

render.js ➔ onParse   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
cc 5
c 5
b 0
f 1
nc 7
nop 1
dl 0
loc 64
rs 8.6346

1 Function

Rating   Name   Duplication   Size   Complexity  
B render.js ➔ ... ➔ init 0 36 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
// Copyright © 2017 TangDongxin
2
3
// Permission is hereby granted, free of charge, to any person obtaining
4
// a copy of this software and associated documentation files (the "Software"),
5
// to deal in the Software without restriction, including without limitation
6
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
// and/or sell copies of the Software, and to permit persons to whom the
8
// Software is furnished to do so, subject to the following conditions:
9
10
// The above copyright notice and this permission notice shall be included
11
// in all copies or substantial portions of the Software.
12
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21
// ===========================================
22
// JSON PARSER
23
// ===========================================
24
function onParse(result) {
0 ignored issues
show
Unused Code introduced by
The parameter result is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
25
    var chrome = this.chrome || this.browser;
0 ignored issues
show
Unused Code introduced by
The assignment to variable chrome seems to be never used. Consider removing it.
Loading history...
26
    var jsonRe = /^\s*(?:\[\s*(?=-?\d|true|false|null|["[{])[^]*\]|\{\s*"[^]+\})\s*$/;
27
    var body = document.body;
28
    var str, jsonpMatch, tag;
0 ignored issues
show
Unused Code introduced by
The variable jsonpMatch seems to be never used. Consider removing it.
Loading history...
29
30
    console.log(strictOnly);
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...
Bug introduced by
The variable strictOnly seems to be never declared. If this is a global, consider adding a /** global: strictOnly */ 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...
31
    if (strictOnly) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable strictOnly is declared in the current environment, consider using typeof strictOnly === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
32
        // only render when the contentType is json
33
        if (/[+\/]json$/i.test(document.contentType)) {
34
            init();
35
            str = body.textContent;
36
            draw(str, body);
37
        }
38
    } else {
39
        // check whether the content is json or like json
40
        try {
41
            if (jsonRe.test(body.textContent)) {
42
                init();
43
                draw(first.textContent, body);
0 ignored issues
show
Bug introduced by
The variable first seems to be never declared. If this is a global, consider adding a /** global: first */ 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...
44
            }
45
        } catch (e) {
46
            dlog(e);
47
            // ignore
48
        }
49
    }
50
51
    function init() {
52
        if (tag) {
53
            return;
54
        }
55
56
        tag = document.createElement("style");
57
        tag.textContent = [
58
            '.R', ',.D', '{font:' + fontSize + ' ' + fontStyle + '}' +
0 ignored issues
show
Bug introduced by
The variable fontStyle seems to be never declared. If this is a global, consider adding a /** global: fontStyle */ 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...
Bug introduced by
The variable fontSize seems to be never declared. If this is a global, consider adding a /** global: fontSize */ 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...
59
            '.D', '{margin-left:0.5em; padding-left:2em; margin-top: 1px; border-left:1px dashed; border-color: #93A1A1;}' +
60
            '.X', '{border:1px solid #ccc; padding:1em}' +
61
            'a.L', '{text-decoration:none}' +
62
            'a.L', ':hover,a.L', ':focus{text-decoration:underline}' +
63
            'i.I', '{cursor:pointer;color:#ccc}' +
64
            'i.H', ',i.I', ':hover{text-shadow: 1px 1px 3px #999; color:#333}' +
65
            'i.I', ':before{content:" ▼ "}' +
66
            'i.C', ':before{content:" ▶ "}' +
67
            'i.C', '+.D', '{width:1px; height:1px; margin:0; padding:0; border:0; display:inline-block; overflow:hidden}' +
68
            '.S', '{color:' + strColor + '}' + // string
0 ignored issues
show
Bug introduced by
The variable strColor seems to be never declared. If this is a global, consider adding a /** global: strColor */ 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...
69
            '.K', '{color:' + keyColor + '}' + // key
0 ignored issues
show
Bug introduced by
The variable keyColor seems to be never declared. If this is a global, consider adding a /** global: keyColor */ 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...
70
            '.E', '{color:#BCADAD}' + // error
71
            '.B', '{color:' + intColor + '}' + // number and bool
0 ignored issues
show
Bug introduced by
The variable intColor seems to be never declared. If this is a global, consider adding a /** global: intColor */ 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...
72
            '.E', ',.B', '{font-style: italic}' + // number bold
73
            'h3.E', '{margin:0 0 1em}'
74
        ].join(RAND);
0 ignored issues
show
Bug introduced by
The variable RAND seems to be never declared. If this is a global, consider adding a /** global: RAND */ 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
        tag.textContent += 'i.I' + RAND + ':after{content:attr(data-content)}';
77
        tag.textContent += 'body {background: ' + bgColor + '; color:' + defaultColor + ';}';
0 ignored issues
show
Bug introduced by
The variable bgColor seems to be never declared. If this is a global, consider adding a /** global: bgColor */ 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...
Bug introduced by
The variable defaultColor seems to be never declared. If this is a global, consider adding a /** global: defaultColor */ 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
        tag.textContent += '.HIDE {width:200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }';
79
        tag.textContent += '* {font:' + fontSize + ' ' + fontStyle + ' !important;}';
80
        tag.textContent += '.black_overlay{ display: none; position: fixed; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index:1001; -moz-opacity: 0.6; opacity:.60; filter: alpha(opacity=60); }';
81
        tag.textContent += '.white_content { display: none; position: fixed; top: 10%; left: 13%; width: 70%; min-width: 500px; min-height: 300px; height: 60%; padding: 1%; border: 16px solid orange; background-color: white; z-index:1002; overflow: auto; }';
82
        tag.textContent += 'str:hover{text-shadow: 1px 1px 3px #999; color:#333}';
83
        tag.textContent += 'json:hover{text-shadow: 1px 1px 3px #999; color:#333}';
84
85
        document.head.appendChild(tag);
86
    }
87
}
88