Created
February 11, 2026 20:28
-
-
Save aerosol/00230d7a4e85a738a95c015fdfac6b96 to your computer and use it in GitHub Desktop.
Epiphany Web App Copy URL keyboard shortcut - inject as user-javascript.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Epiphany Custom Script: Copy URL on Ctrl+L | |
| // This script copies the current page URL to clipboard when pressing Ctrl+L | |
| (function() { | |
| 'use strict'; | |
| // Show load indicator | |
| showNotification('Copy URL script loaded - Press Ctrl+L to copy URL', 3000); | |
| // Try multiple event listeners for better coverage | |
| function handleKeyEvent(event) { | |
| // Check if Ctrl+L is pressed (case insensitive) | |
| if ((event.ctrlKey || event.metaKey) && (event.key === 'l' || event.key === 'L' || event.keyCode === 76)) { | |
| // Prevent default browser behavior | |
| event.preventDefault(); | |
| event.stopPropagation(); | |
| event.stopImmediatePropagation(); | |
| // Get current URL | |
| const url = window.location.href; | |
| // Always show we detected the keypress | |
| showNotification('Copying URL: ' + url, 2000); | |
| // Try multiple clipboard methods | |
| let copied = false; | |
| // Method 1: Modern Clipboard API | |
| if (navigator.clipboard && navigator.clipboard.writeText) { | |
| navigator.clipboard.writeText(url) | |
| .then(function() { | |
| showNotification('✓ URL copied successfully!', 2000); | |
| }) | |
| .catch(function(err) { | |
| fallbackCopyToClipboard(url); | |
| }); | |
| } else { | |
| // Method 2: Fallback | |
| fallbackCopyToClipboard(url); | |
| } | |
| return false; | |
| } | |
| } | |
| // Attach to window, document, and body with capture | |
| window.addEventListener('keydown', handleKeyEvent, true); | |
| document.addEventListener('keydown', handleKeyEvent, true); | |
| window.addEventListener('keypress', handleKeyEvent, true); | |
| document.addEventListener('keypress', handleKeyEvent, true); | |
| // Also try on keyup as last resort | |
| window.addEventListener('keyup', handleKeyEvent, true); | |
| // Fallback method for older browsers | |
| function fallbackCopyToClipboard(text) { | |
| const textArea = document.createElement('textarea'); | |
| textArea.value = text; | |
| textArea.style.position = 'fixed'; | |
| textArea.style.top = '0'; | |
| textArea.style.left = '0'; | |
| textArea.style.width = '1px'; | |
| textArea.style.height = '1px'; | |
| textArea.style.opacity = '0'; | |
| textArea.style.zIndex = '-1'; | |
| document.body.appendChild(textArea); | |
| textArea.focus(); | |
| textArea.select(); | |
| textArea.setSelectionRange(0, 99999); | |
| try { | |
| const successful = document.execCommand('copy'); | |
| if (successful) { | |
| showNotification('✓ URL copied (fallback method)!', 2000); | |
| } else { | |
| showNotification('✗ Copy failed - please copy manually', 3000); | |
| } | |
| } catch (err) { | |
| showNotification('✗ Copy error: ' + err.message, 3000); | |
| } | |
| document.body.removeChild(textArea); | |
| } | |
| // Show a brief visual notification | |
| function showNotification(message, duration) { | |
| duration = duration || 2000; | |
| const notification = document.createElement('div'); | |
| notification.textContent = message; | |
| notification.style.cssText = ` | |
| position: fixed; | |
| top: 20px; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| background: #2d2d2d; | |
| color: #fff; | |
| padding: 16px 24px; | |
| border-radius: 8px; | |
| font-family: system-ui, -apple-system, sans-serif; | |
| font-size: 16px; | |
| font-weight: 500; | |
| z-index: 2147483647; | |
| box-shadow: 0 4px 16px rgba(0,0,0,0.5); | |
| transition: opacity 0.3s; | |
| max-width: 80%; | |
| word-wrap: break-word; | |
| text-align: center; | |
| `; | |
| document.body.appendChild(notification); | |
| // Fade out and remove | |
| setTimeout(function() { | |
| notification.style.opacity = '0'; | |
| setTimeout(function() { | |
| if (notification.parentNode) { | |
| notification.parentNode.removeChild(notification); | |
| } | |
| }, 300); | |
| }, duration); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment