Skip to content

Commit

Permalink
Merge pull request #277 from jdi-testing/issue_209
Browse files Browse the repository at this point in the history
add change highlight layers options
  • Loading branch information
MariiaNebesnova authored Aug 9, 2021
2 parents 243d145 + 5a7326e commit c56664d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 25 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "JDN",
"description": "",
"devtools_page": "index.html",
"version": "3.0.35",
"version": "3.0.36",
"permissions": [
"activeTab",
"tabs",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jdi-react-extension",
"version": "3.0.35",
"version": "3.0.36",
"description": "jdi react extension",
"scripts": {
"start": "npm run webpack",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,31 +297,43 @@ export const runContextMenu = () => {
{ jdi_class_name, element_id, skipGeneration },
types
) => [
{
text: `<b>Block type: ${jdi_class_name}</b>`,
sub: typesMenu(types),
},
{
text: "Remove",
events: {
click: () =>
chrome.runtime.sendMessage({
message: "REMOVE_ELEMENT",
param: element_id,
}),
{
text: `<b>Block type: ${jdi_class_name}</b>`,
sub: typesMenu(types),
},
},
{
text: `Switch ${skipGeneration ? "on" : "off"}`,
events: {
click: () =>
chrome.runtime.sendMessage({
message: "TOGGLE_ELEMENT",
param: element_id,
}),
{
text: "Remove",
events: {
click: () =>
chrome.runtime.sendMessage({
message: "REMOVE_ELEMENT",
param: element_id,
}),
},
},
},
];
{
text: `Switch ${skipGeneration ? "on" : "off"}`,
events: {
click: () =>
chrome.runtime.sendMessage({
message: "TOGGLE_ELEMENT",
param: element_id,
}),
},
},
{
text: `Bring to front`,
events: {
click: () => chrome.storage.local.set({ JDN_BRING_TO_FRONT: { hash: Date.now(), element_id } }),
},
},
{
text: `Bring to background`,
events: {
click: () => chrome.storage.local.set({ BRING_TO_BACKGROUND: { hash: Date.now(), element_id } }),
},
},
];

const typesMenu = (types) => {
return types.map((type) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export function highlightOrder() {
const getOverlappedHighlightings = (id) => {
const overlappedNodes = [];
const origNode = document.getElementById(id);
const { left: origLeft, right: origRight, top: origTop, bottom: origBottom } = origNode.getBoundingClientRect();

const proposedNodes = document.querySelectorAll('[jdn-highlight=true]');
proposedNodes.forEach((node) => {
const { left, right, top, bottom } = node.getBoundingClientRect();
if (
((left >= origLeft && left <= origRight) ||
(right >= origLeft && right <= origRight)) &&
((top >= origTop && top <= origBottom) ||
(bottom >= origTop && bottom <= origBottom))
) overlappedNodes.push(node);
});

return overlappedNodes;
}

const getUtterZIndex = (nodes, comparation) => {
const zIndex = nodes.reduce(
((accum, current) => {
return Math[comparation](window.getComputedStyle(current).zIndex, accum)
}), window.getComputedStyle(nodes[0]).zIndex
);
return zIndex;
}

const bringToFront = (id) => {
const maxZIndex = getUtterZIndex(getOverlappedHighlightings(id), 'max');
const node = document.getElementById(id);
node.style.zIndex = maxZIndex + 1;
}

const bringToBack = (id) => {
const minZIndex = getUtterZIndex(getOverlappedHighlightings(id), 'min');
const node = document.getElementById(id);
node.style.zIndex = minZIndex - 1;
}

const messageHandler = ({ message, param }, sender, sendResponse) => {
if (message === "PING_SCRIPT" && (param.scriptName === "highlightOrder")) {
sendResponse({ message: true });
}
};

chrome.runtime.onMessage.addListener(messageHandler);
chrome.storage.onChanged.addListener((event) => {
if (event.hasOwnProperty('JDN_BRING_TO_FRONT')) bringToFront(event.JDN_BRING_TO_FRONT.newValue.element_id);
if (event.hasOwnProperty('BRING_TO_BACKGROUND')) bringToBack(event.BRING_TO_BACKGROUND.newValue.element_id);
});
}
2 changes: 2 additions & 0 deletions src/js/blocks/autoFind/autoFindProvider/pageDataHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getPageData } from "./contentScripts/pageData";
import { urlListener } from "./contentScripts/urlListener";
import { getPage, predictedToConvert } from "./pageObject";
import { autoFindStatus } from "./AutoFindProvider";
import { highlightOrder } from "./contentScripts/highlightOrder";
/* global chrome*/

let documentListenersStarted;
Expand Down Expand Up @@ -113,6 +114,7 @@ export const runDocumentListeners = (actions) => {
if (!documentListenersStarted) {
setUrlListener(actions["HIGHLIGHT_OFF"]);
connector.attachContentScript(runContextMenu);
connector.attachContentScript(highlightOrder);
documentListenersStarted = true;
}
};
Expand Down

0 comments on commit c56664d

Please sign in to comment.