Skip to content

Commit 55f09c2

Browse files
Merge pull request #362 from jdi-testing/issue-281
Протестировать отображение имени #281
2 parents 487348a + 3038d23 commit 55f09c2

4 files changed

Lines changed: 82 additions & 21 deletions

File tree

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "JDN",
44
"description": "",
55
"devtools_page": "index.html",
6-
"version": "3.0.53",
6+
"version": "3.0.54",
77
"permissions": [
88
"activeTab",
99
"tabs",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jdi-react-extension",
3-
"version": "3.0.53",
3+
"version": "3.0.54",
44
"description": "jdi react extension",
55
"scripts": {
66
"start": "npm run webpack",

src/js/blocks/autoFind/contentScripts/highlight.css

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040

4141
.cm_container li:hover {
4242
background-color: #212228;
43-
color: #1582D8;
43+
color: #1582d8;
4444
}
4545

4646
.cm_container li .cm_container_warning-option {
47-
color: #D82C15;
47+
color: #d82c15;
4848
}
4949

5050
.cm_container li .cm_icon_span {
@@ -157,6 +157,33 @@
157157
white-space: nowrap;
158158
}
159159

160+
.jdn-tooltip {
161+
position: absolute;
162+
display: inline-block;
163+
background-color: rgba(0, 0, 0, 0.8);
164+
border-radius: 4px;
165+
color: #fff;
166+
z-index: 5500;
167+
font-size: 10px;
168+
font-family: "Noto Sans", sans-serif;
169+
line-height: 16px;
170+
padding: 10px 8px 15px 10px;
171+
margin-top: 15px;
172+
}
173+
174+
.jdn-tooltip b {
175+
font-weight: bold;
176+
}
177+
178+
.jdn-tooltip::after {
179+
content: "";
180+
position: absolute;
181+
right: 10px;
182+
top: -18px;
183+
border: 9px solid transparent;
184+
border-bottom: 10px solid rgba(0, 0, 0, 0.8);
185+
}
186+
160187
.jdn-primary {
161188
background-color: rgba(21, 130, 216, 0.4);
162189
border: 1px solid rgba(21, 130, 216, 1);
@@ -216,7 +243,7 @@
216243
}
217244

218245
.jdn-change-element-name-modal__close-link:hover {
219-
color: #1582D8;
246+
color: #1582d8;
220247
}
221248

222249
.jdn-change-element-name-modal__title {
@@ -238,7 +265,7 @@
238265
right: 66px;
239266
transform: rotate(-45deg);
240267
animation-name: appearance;
241-
animation-duration: 0.25s;
268+
animation-duration: 0.25s;
242269
animation-delay: 0.5s;
243270
animation-iteration-count: 1;
244271
animation-fill-mode: forwards;
@@ -253,8 +280,8 @@
253280
100% {
254281
width: 15px;
255282
height: 8px;
256-
border-bottom: 1px solid #1582D8;
257-
border-left: 1px solid #1582D8;
283+
border-bottom: 1px solid #1582d8;
284+
border-left: 1px solid #1582d8;
258285
}
259286
}
260287

@@ -266,33 +293,37 @@
266293
width: 30px;
267294
height: 30px;
268295
border-radius: 50%;
269-
border: 1px solid #1582D8;
296+
border: 1px solid #1582d8;
270297
opacity: 0;
271298
animation-name: cirlce;
272-
animation-duration: 0.25s;
299+
animation-duration: 0.25s;
273300
animation-delay: 1s;
274301
animation-iteration-count: 1;
275302
animation-fill-mode: forwards;
276303
animation-play-state: running;
277304
}
278305

279306
@keyframes cirlce {
280-
0% { opacity: 0; }
281-
100% { opacity: 1; }
307+
0% {
308+
opacity: 0;
309+
}
310+
100% {
311+
opacity: 1;
312+
}
282313
}
283314

284315
.jdn-change-element-name-modal__form-input {
285316
width: 180px;
286317
padding: 3px 5px 4px;
287318
margin: 0 5px 0 0;
288319
color: #000;
289-
border: 1px solid #1582D8;
320+
border: 1px solid #1582d8;
290321
border-radius: 3px;
291322
}
292323

293324
.jdn-change-element-name-modal__form-button {
294325
padding: 5px 10px;
295-
background: #1582D8;
326+
background: #1582d8;
296327
color: #fff;
297328
border: none;
298329
border-radius: 3px;

src/js/blocks/autoFind/contentScripts/highlight.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,24 @@ export const highlightOnPage = () => {
3434
if (div) div.remove();
3535
};
3636

37+
const createLabelText = (element) => {
38+
const predictedProbabilityPercent = Math.round(element.predicted_probability * 100);
39+
return `${predictedProbabilityPercent}%, ${element.jdi_class_name}`;
40+
};
41+
3742
const assignType = (element) => {
3843
const div = document.getElementById(element.element_id);
39-
div.querySelector(".jdn-class").textContent = element.jdi_class_name;
44+
div.querySelector(".jdn-class").textContent = createLabelText(element);
4045
};
4146

4247
const changeElementName = (element) => {
4348
const div = document.getElementById(element.element_id);
44-
div.querySelector(".jdn-class").textContent = element.jdi_class_name;
49+
div.querySelector(".jdn-class").textContent = createLabelText(element);
4550
};
4651

4752
const drawRectangle = (
4853
element,
49-
{ element_id, jdi_class_name, predicted_probability }
54+
{ element_id, jdi_class_name, predicted_probability, predicted_label }
5055
) => {
5156
const divDefaultStyle = (rect) => {
5257
const { top, left, height, width } = rect || {};
@@ -59,14 +64,39 @@ export const highlightOnPage = () => {
5964
}
6065
: {};
6166
};
62-
67+
const tooltipDefaultStyle = (rect) => {
68+
const {right, top, height, width} = rect;
69+
return rect ? {
70+
right: `calc(100% - ${right + window.pageXOffset - width/2}px)`,
71+
top: `${top + window.pageYOffset + height}px`,
72+
} : {};
73+
};
74+
const predictedProbabilityPercent = Math.round(predicted_probability * 100);
6375
const div = document.createElement("div");
6476
div.id = element_id;
65-
div.className = "jdn-highlight jdn-primary"
77+
div.className = "jdn-highlight jdn-primary";
6678
div.setAttribute("jdn-highlight", true);
67-
div.innerHTML = `<div><span class="jdn-label"><span class="jdn-class">${jdi_class_name}</span> ${predicted_probability}</span></div>`;
68-
Object.assign(div.style, divDefaultStyle(element.getBoundingClientRect()));
79+
const tooltip = document.createElement('div');
80+
tooltip.className = 'jdn-tooltip';
81+
tooltip.innerHTML = `
82+
<p><b>Name:</b> ${predicted_label}</p>
83+
<p><b>Type:</b> ${jdi_class_name}</p>
84+
<p><b>Prediction accuracy:</b> ${predictedProbabilityPercent}%</p>`;
85+
const labelContainer = document.createElement('div');
86+
const label = document.createElement('span');
87+
label.className = 'jdn-label';
88+
label.innerHTML = `<span class="jdn-class">${predictedProbabilityPercent}%, ${jdi_class_name}</span>`;
89+
label.addEventListener('mouseover', () => {
90+
Object.assign(tooltip.style, tooltipDefaultStyle(label.getBoundingClientRect()));
91+
document.body.appendChild(tooltip);
92+
});
93+
label.addEventListener('mouseout', () => {
94+
document.body.removeChild(tooltip);
95+
});
6996

97+
Object.assign(div.style, divDefaultStyle(element.getBoundingClientRect()));
98+
labelContainer.appendChild(label);
99+
div.insertAdjacentElement('afterBegin', labelContainer);
70100
div.onclick = () => {
71101
chrome.runtime.sendMessage({
72102
message: "TOGGLE_ELEMENT",

0 commit comments

Comments
 (0)