Skip to content

Commit

Permalink
Merge pull request #11 from emvaized/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
emvaized authored Dec 9, 2024
2 parents f06693b + 4ca6acf commit 1f99798
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions src/options/options.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
body {
min-width: 381px;
padding: 4px;
}
#settingsTitle{
padding: 0 6px;
Expand Down

0 comments on commit 1f99798

Please sign in to comment.