diff --git a/src/content.js b/src/content.js index 64489ae..e58b366 100644 --- a/src/content.js +++ b/src/content.js @@ -72,29 +72,41 @@ function onTrigger(e, type){ selectedText: window.getSelection().toString().trim(), availLeft: window.screen.availLeft, type: type } - if (type == 'drag' || type == 'shiftClick') { + let nodeName, link; + if (type == 'drag' || type == 'shiftClick') { /// Handle IMG wrapped in A if (t.parentNode && t.parentNode.nodeName == 'A'){ if (configs.imageWithLinkPreferLink){ - message['link'] = t.parentNode.href; - message['nodeName'] = t.parentNode.nodeName; + nodeName = t.parentNode.nodeName; + link = t.parentNode.href; } else { - message['link'] = t.src; - message['nodeName'] = t.nodeName; + nodeName = t.nodeName; + link = t.src; } } else if (t.childNodes && t.childNodes.length == 1 && t.firstChild.nodeName == 'IMG') { if (configs.imageWithLinkPreferLink){ - message['link'] = t.href; - message['nodeName'] = t.nodeName; + nodeName = t.nodeName; + link = t.href; } else { - message['link'] = t.firstChild.src; - message['nodeName'] = t.firstChild.nodeName; + nodeName = t.firstChild.nodeName; + link = t.firstChild.src; } } else { - message['link'] = t.src ?? t.href ?? t.parentNode.href; - message['nodeName'] = t.nodeName; + nodeName = t.nodeName; + link = t.src ?? t.href ?? t.parentNode.href; + } + + /// Handle IMG with source in sourceset + if (nodeName == 'IMG' && !link && t.parentNode && t.parentNode.nodeName == 'PICTURE') { + const src = t.parentNode.querySelector('source'); + if (src) link = src.getAttribute('srcset'); } + + message['nodeName'] = nodeName; + message['link'] = link; } - chrome.runtime.sendMessage(message) + + if (link) + chrome.runtime.sendMessage(message) } \ No newline at end of file diff --git a/src/options/options.css b/src/options/options.css index 5307032..1eaaa92 100644 --- a/src/options/options.css +++ b/src/options/options.css @@ -1,5 +1,6 @@ body { min-width: 381px; + padding: 4px; } #settingsTitle{ padding: 0 6px;