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, {
mark: label,
url: info.linkUrl,
elementId: info.targetElementId
elementId: info.targetElementId,
debug: overrides.debug
}, null, response => {
if (!response.identifier) return;
response.tabId = tab.id;

View File

@ -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;
}

View File

@ -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);
})