Support for snippet detection debugging

This commit is contained in:
shinigami-eyes 2018-12-16 16:42:20 +01:00
parent 1b6b2d360f
commit 34f4157392
3 changed files with 36 additions and 13 deletions

View File

@ -156,7 +156,8 @@ browser.contextMenus.onClicked.addListener(function (info, tab) {
browser.tabs.sendMessage(tab.id, { browser.tabs.sendMessage(tab.id, {
mark: label, mark: label,
url: info.linkUrl, url: info.linkUrl,
elementId: info.targetElementId elementId: info.targetElementId,
debug: overrides.debug
}, null, response => { }, null, response => {
if (!response.identifier) return; if (!response.identifier) return;
response.tabId = tab.id; response.tabId = tab.id;

View File

@ -4,3 +4,21 @@
.assigned-label-good { color: #014E0B !important; } .assigned-label-good { color: #014E0B !important; }
.has-assigned-label * { color: inherit !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;
}

View File

@ -132,10 +132,12 @@ function init() {
}); });
document.addEventListener('contextmenu', evt => {
lastRightClickedElement = evt.target;
}, true);
} }
var lastRightClickedElement = null;
var lastAppliedYouTubeUrl = null; var lastAppliedYouTubeUrl = null;
var lastAppliedYouTubeTitle = null; var lastAppliedYouTubeTitle = null;
@ -445,6 +447,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
//if (!links.length) console.log('Already empty :(') //if (!links.length) console.log('Already empty :(')
var identifier = links.length ? getIdentifier(links[0]) : getIdentifier(message.url); var identifier = links.length ? getIdentifier(links[0]) : getIdentifier(message.url);
if (!identifier) return; if (!identifier) return;
message.identifier = identifier;
var snippets = links.map(node => { var snippets = links.map(node => {
while (node) { while (node) {
@ -462,16 +465,17 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
//console.log('Reached the top without a satisfying element') //console.log('Reached the top without a satisfying element')
return null; return null;
}) })
snippets = snippets.filter((item, pos) => item && snippets.indexOf(item) == pos);
message.identifier = identifier; var exact = snippets.filter(x => x && x.contains(lastRightClickedElement))[0] || null;
message.snippets = snippets.filter((item, pos) => pos <= 10).map(x => {
var html = x.outerHTML; message.snippet = exact;
if(html){ if(message.debug){
html = html var debugClass = 'shinigami-eyes-debug-snippet-highlight';
.replace(/ alt=""/g, '') if(exact){
.replace(/__xts__%5B0%5D[\w\.\-]*/g, '__xts__') exact.classList.add(debugClass);
if (message.debug <= 1)
setTimeout(() => exact.classList.remove(debugClass), 10000)
}
} }
return html;
});
sendResponse(message); sendResponse(message);
}) })