This repository was archived by the owner on Oct 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjavadoc.js
More file actions
161 lines (142 loc) · 6.21 KB
/
javadoc.js
File metadata and controls
161 lines (142 loc) · 6.21 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
(function() {
if (!(document.head.innerHTML.indexOf('Generated by javadoc') > -1)) {
return;
}
chrome.extension.sendRequest({"action": "isRunning"}, function(response) {
if (response === null || response === '' || response === 'false') {
return;
}
(function() {
var _document = document;
var options = response;
//クラス名
var className = "";
try {
className = _document.querySelector('html>body>dl>dt>pre>b').innerText;
} catch (e) {
try {
var frame = _document.getElementsByName('classFrame')[0];
_document = frame.contentDocument;
frame.addEventListener('load', arguments.callee);
className = _document.querySelector('html>body>dl>dt>pre>b').innerText;
} catch (e2) {
console.error(e2);
return;
}
}
var fields = extractFields(_document, options.showModifiers);
var methods = extractMethods(_document, options.showModifiers);
var classView = _document.createElement('div');
classView.id = 'classView';
classView.setAttribute('style', 'font-size: 12px; line-height: 1.2em; z-index: 10; top:10px; right:10px; border: 1px solid; opacity: 0.8; box-shadow:0 0 3px #000; background-color:#fff; overflow: auto; max-height: 600px; max-width: 360px; position:fixed;');
classView.innerHTML = buildHtml(className, fields, methods);
_document.body.appendChild(classView);
})();
function extractFields(_document, showModifiers) {
var fields = [];
try {
var nameRef = _document.getElementsByName('field_summary')[0];
var fieldsTable = nameRef.nextElementSibling;
if (fieldsTable == null) {
fieldsTable = nameRef.parentElement.nextElementSibling;
}
var rows = fieldsTable.rows;
for (var i = 0; i < rows.length; i++) {
if (i == 0) continue;
var fieldType = rows[i].cells[0].innerText;
var fieldName = rows[i].cells[1].innerText.split(' ')[0];
var modifier = ' ';
// if (fieldType.indexOf('public ') > -1) {
// if (showModifiers.showPublic != 'true') continue;
// modifier = ' + ';
// fieldType = fieldType.replace('public ', '');
// } else if (fieldType.indexOf('protected ') > -1) {
// if (showModifiers.showProtected != 'true') continue;
// modifier = ' # ';
// fieldType = fieldType.replace('protected ', '');
// } else if (fieldType.indexOf('private ') > -1) {
// if (showModifiers.showPrivate != 'true') continue;
// modifier = ' - ';
// fieldType = fieldType.replace('private ', '');
// } else {
// if (showModifiers.showNone != 'true') continue;
// }
if (fieldType.indexOf('protected ') > -1) {
if (showModifiers.showProtected != 'true') continue;
modifier = ' # ';
fieldType = fieldType.replace('protected ', '');
} else if (fieldType.indexOf('private ') > -1) {
if (showModifiers.showPrivate != 'true') continue;
modifier = ' - ';
fieldType = fieldType.replace('private ', '');
} else if (fieldType.indexOf('package private ') > -1) {
if (showModifiers.showNone != 'true') continue;
fieldType = fieldType.replace('package private ', '');
} else {
if (showModifiers.showPublic != 'true') continue;
modifier = ' + ';
fieldType = fieldType.replace('public ', '');
}
if (fieldType.indexOf('static') > -1) {
fields[i] = ['<u>', modifier, '<a href=#', fieldName, ' style="color: #000; text-decoration: none;">', fieldName, '</a>', ' : ', fieldType.replace('static', '').trim(), '</u>'].join('');
} else {
fields[i] = [modifier, '<a href=#', fieldName, ' style="color: #000; text-decoration: none;">', fieldName, '</a>', ' : ', fieldType].join('');
}
console.log('fieldType:' + fieldType + " fieldName:" + fieldName);
}
} catch (e) { console.log(e); }
return fields;
}
function extractMethods(_document, showModifiers) {
var methods = [];
try {
var nameRef = _document.getElementsByName('method_summary')[0];
var methodsTable = nameRef.nextElementSibling;
if (methodsTable == null) {
methodsTable = nameRef.parentElement.nextElementSibling;
}
var rows = methodsTable.rows;
for (var i = 0; i < rows.length; i++) {
if (i == 0) continue;
var returnType = rows[i].cells[0].innerText;
var methodNameWithParams = rows[i].cells[1].getElementsByTagName('code')[0].innerText;
var modifier = ' ';
if (returnType.indexOf('protected ') > -1) {
if (showModifiers.showProtected != 'true') continue;
modifier = ' # ';
returnType = returnType.replace('protected ', '');
} else if (returnType.indexOf('private ') > -1) {
if (showModifiers.showPrivate != 'true') continue;
modifier = ' - ';
returnType = returnType.replace('private ', '');
} else if (returnType.indexOf('package private ') > -1) {
if (showModifiers.showNone != 'true') continue;
returnType = returnType.replace('package private ', '');
} else {
if (showModifiers.showPublic != 'true') continue;
modifier = ' + ';
returnType = returnType.replace('public ', '');
}
var aName = _document.querySelectorAll('a[name^="' + methodNameWithParams.split('(')[0] + '"]')[0];
if (returnType.indexOf('static') > -1) {
methods[i] = ['<u>', modifier, '<a href=#', aName.name, ' style="color: #000; text-decoration: none;">', methodNameWithParams, '</a>', ' : ', returnType.replace('static', '').trim(), '</u>'].join('');
} else {
methods[i] = [modifier, '<a href=#', aName.name, ' style="color: #000; text-decoration: none;">', methodNameWithParams, '</a>', ' : ', returnType].join('');
}
console.log('returnType:' + returnType + " methodNameWithParams:" + methodNameWithParams);
}
} catch (e) { console.log(e); }
return methods;
}
function buildHtml(className, fields, methods) {
return ['<h3 style="margin: 4px 0; padding: 0 6px; font-size: 1em;">',
'<a href="#skip-navbar_top" style="color: #000; text-decoration: none;">', className, '</a>',
'</h3>',
'<hr style="margin: 3px 0;">',
'<div style="padding: 0 6px;">', fields.join('<p style="margin-top: 0; margin-bottom: 0;">'), '</div>',
'<hr style="margin: 3px 0;">',
'<div style="padding: 0 6px;">', methods.join('<p style="margin-top: 0; margin-bottom: 0;">'), '</div>'
].join('')
}
});
})();