Files
omarchy/default/chromium/extensions/copy-url/background.js
Jankees van Woezik 1e6ddf55ce Copy URL to clipboard from Chromium apps (#1458)
* Copy current URL to clipboard with browser extension

In Omarchy web apps it's impossible to get the curent URL to share it in
another applications. This commit adds a browser extension which is
included by default via the chromium-flags.conf config. With this
extension you can get the current URL via a keyboard shortcut.

The default shortcut for getting the current URL is `Ctrl+Shift+L`, this
shortcut can be changed via this page: chrome://extensions/shortcuts.

* Change the shortcut to Alt+Shift+L

In my testing and research I found out that not all shortcuts
are available as suggested_key. We still want to use L because
that's easy to remember because we associate it with the location bar.

* Improve notification language

* Move it to just Alt + L since that's not used

Better mirrors Ctrl + L as well

* Move this under default/chromium

* Fix symlink

* It didn't like Alt+L alone after all

---------

Co-authored-by: David Heinemeier Hansson <david@hey.com>
2025-09-15 12:22:28 +02:00

22 lines
705 B
JavaScript

chrome.commands.onCommand.addListener((command) => {
if (command === 'copy-url') {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const currentTab = tabs[0];
chrome.scripting.executeScript({
target: { tabId: currentTab.id },
func: () => {
navigator.clipboard.writeText(window.location.href);
}
}).then(() => {
chrome.notifications.create({
type: 'basic',
iconUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==',
title: ' URL copied to clipboard',
message: ''
});
});
});
}
});