diff --git a/manifest.json b/manifest.json index 5bb5ce6..a05320d 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "JDN", "description": "", "devtools_page": "index.html", - "version": "3.0.35", + "version": "3.0.36", "permissions": [ "activeTab", "tabs", diff --git a/package.json b/package.json index f1151c9..aa7f1b4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/js/blocks/autoFind/autoFindProvider/contentScripts/contextMenu/contextmenu.js b/src/js/blocks/autoFind/autoFindProvider/contentScripts/contextMenu/contextmenu.js index 0e9e70c..fd282f4 100644 --- a/src/js/blocks/autoFind/autoFindProvider/contentScripts/contextMenu/contextmenu.js +++ b/src/js/blocks/autoFind/autoFindProvider/contentScripts/contextMenu/contextmenu.js @@ -297,31 +297,43 @@ export const runContextMenu = () => { { jdi_class_name, element_id, skipGeneration }, types ) => [ - { - text: `Block type: ${jdi_class_name}`, - sub: typesMenu(types), - }, - { - text: "Remove", - events: { - click: () => - chrome.runtime.sendMessage({ - message: "REMOVE_ELEMENT", - param: element_id, - }), + { + text: `Block type: ${jdi_class_name}`, + 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) => { diff --git a/src/js/blocks/autoFind/autoFindProvider/contentScripts/highlightOrder.js b/src/js/blocks/autoFind/autoFindProvider/contentScripts/highlightOrder.js new file mode 100644 index 0000000..e955f69 --- /dev/null +++ b/src/js/blocks/autoFind/autoFindProvider/contentScripts/highlightOrder.js @@ -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); + }); +} \ No newline at end of file diff --git a/src/js/blocks/autoFind/autoFindProvider/pageDataHandlers.js b/src/js/blocks/autoFind/autoFindProvider/pageDataHandlers.js index 4d08608..8494a3b 100644 --- a/src/js/blocks/autoFind/autoFindProvider/pageDataHandlers.js +++ b/src/js/blocks/autoFind/autoFindProvider/pageDataHandlers.js @@ -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; @@ -113,6 +114,7 @@ export const runDocumentListeners = (actions) => { if (!documentListenersStarted) { setUrlListener(actions["HIGHLIGHT_OFF"]); connector.attachContentScript(runContextMenu); + connector.attachContentScript(highlightOrder); documentListenersStarted = true; } };