diff --git a/extension/background.js b/extension/background.js index 2d2d4d0..9cb05c9 100644 --- a/extension/background.js +++ b/extension/background.js @@ -156,7 +156,8 @@ browser.contextMenus.onClicked.addListener(function (info, tab) { browser.tabs.sendMessage(tab.id, { mark: label, url: info.linkUrl, - elementId: info.targetElementId + elementId: info.targetElementId, + debug: overrides.debug }, null, response => { if (!response.identifier) return; response.tabId = tab.id; diff --git a/extension/content.css b/extension/content.css index 88c8869..b06fd7f 100644 --- a/extension/content.css +++ b/extension/content.css @@ -4,3 +4,21 @@ .assigned-label-good { color: #014E0B !important; } .has-assigned-label * { color: inherit !important; } +.shinigami-eyes-debug-snippet-highlight { + outline: 2px dashed darkorchid !important; + background-color: darkorchid !important; + color: white !important; + } + .shinigami-eyes-debug-snippet-highlight:after { + content: " "; + pointer-events: none; + z-index: 1000000; + display: block; + position: absolute; + height: 100%; + top: 0; + left: 0; + right: 0; + background-color: darkorchid !important; + opacity: 0.5; + } diff --git a/extension/content.js b/extension/content.js index 50a198f..2350af8 100644 --- a/extension/content.js +++ b/extension/content.js @@ -132,10 +132,12 @@ function init() { }); - + document.addEventListener('contextmenu', evt => { + lastRightClickedElement = evt.target; + }, true); } - +var lastRightClickedElement = null; var lastAppliedYouTubeUrl = null; var lastAppliedYouTubeTitle = null; @@ -445,6 +447,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => { //if (!links.length) console.log('Already empty :(') var identifier = links.length ? getIdentifier(links[0]) : getIdentifier(message.url); if (!identifier) return; + message.identifier = identifier; var snippets = links.map(node => { while (node) { @@ -462,16 +465,17 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => { //console.log('Reached the top without a satisfying element') return null; }) - snippets = snippets.filter((item, pos) => item && snippets.indexOf(item) == pos); - message.identifier = identifier; - message.snippets = snippets.filter((item, pos) => pos <= 10).map(x => { - var html = x.outerHTML; - if(html){ - html = html - .replace(/ alt=""/g, '') - .replace(/__xts__%5B0%5D[\w\.\-]*/g, '__xts__') + + var exact = snippets.filter(x => x && x.contains(lastRightClickedElement))[0] || null; + + message.snippet = exact; + if(message.debug){ + var debugClass = 'shinigami-eyes-debug-snippet-highlight'; + if(exact){ + exact.classList.add(debugClass); + if (message.debug <= 1) + setTimeout(() => exact.classList.remove(debugClass), 10000) + } } - return html; - }); sendResponse(message); }) \ No newline at end of file