Skip to content

Commit

Permalink
feat: copy URL of focus
Browse files Browse the repository at this point in the history
This works on list-based pages such as "All", "Videos", "News", etc.
It doesn't work for the "Image" page.
  • Loading branch information
mikez committed Nov 4, 2023
1 parent d92e185 commit 429d77f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,19 @@ class WebSearchNavigator {
});
return false;
});
this.register(getOpt('copyUrlKey'), () => {
const link = this.resultsManager.getElementToNavigate();
if (
link == null || link.localName !== 'a' || !link.href ||
!navigator.clipboard
) {
return true;
}
navigator.clipboard.writeText(link.href).then(
() => false,
(err) => true,
);
});
}

initChangeToolsNavigation() {
Expand Down
1 change: 1 addition & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const DEFAULT_KEYBINDINGS = {
showImagesLarge: ['z l'],
showImagesMedium: ['z e'],
showImagesIcon: ['z i'],
copyUrlKey: ['c', 'y'],
};

const DEFAULT_OPTIONS = {
Expand Down
4 changes: 4 additions & 0 deletions src/options_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ <h2>Keybindings</h2>
<label for="navigate-previous-result-page" class="option-desc">Previous page</label>
<input id="navigate-previous-result-page" class="input-keybinding" type="text" value="left">
</div>
<div class="option">
<label for="copy-url-key" class="option-desc">Copy URL of focus</label>
<input id="copy-url-key" class="input-keybinding" type="text" value="c, y">
</div>
</details>
<details>
<summary><h3>Results filtering</h3></summary>
Expand Down
1 change: 1 addition & 0 deletions src/options_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const KEYBINDING_TO_DIV = {
showImagesLarge: 'show-images-large',
showImagesMedium: 'show-images-medium',
showImagesIcon: 'show-images-icon',
copyUrlKey: 'copy-url-key',
};

/**
Expand Down

0 comments on commit 429d77f

Please sign in to comment.