Prechádzať zdrojové kódy

use Y key to copy urls now + play pop feedback sound after copying

Noah Vogt 3 rokov pred
rodič
commit
53e4786c20
5 zmenil súbory, kde vykonal 40 pridanie a 31 odobranie
  1. 11 17
      README.md
  2. 21 9
      copylinkaddress.js
  3. 8 5
      manifest.json
  4. BIN
      sounds/ding.mp3
  5. BIN
      sounds/pop.mp3

+ 11 - 17
README.md

@@ -1,23 +1,17 @@
-### Use Chrome? Copy link address without right-clicking! Just use your standard keyboard shortcut!
+# Copy URL on Hover
+This is an extension for chromium-based browsers, so you can hover over a link and hit Y to yank it *like a real vim user*! For feedback, a pop sound will be played after copying.
 
-If you need to copy link addresses more than once, you know how annoying it is.
-You need to right-click, find the "Copy Link Address" menu item, and click it.
+If you need to copy link addresses more than once, you know how annoying it is. You need to right-click, find the "Copy link address" menu item, and click it. I find this not very efficient and overly complicated, which is why I use this extension for copying links.
 
-This extension makes your life easy. Just point to your link and hit your standard keyboard shortcut
-(Ctrl-C, or Cmd-C for Mac) and you're done!
+*Note:* This project is a fork from [dhruvtv/copylinkaddress](https://github.com/dhruvtv/copylinkaddress).
 
-Download it at the [Chrome Web Store](https://chrome.google.com/webstore/detail/kdejdkdjdoabfihpcjmgjebcpfbhepmh)
+## Installation
+To try the latest dev version of the extension follow the steps below.
 
-To try the latest dev version of the extension,
-
-1. Download the source (hit the 'ZIP' button you see at the top of the page) and extract to a directory
-2. In Chrome, launch chrome://extensions
-3. Enable Developer Mode
+1. Download the source (either hit the 'ZIP' button you see at the top of the page, or use `git clone`) and extract it to a directory
+2. In your chromium-based browser, launch `chrome://extensions`
+3. Enable 'Developer Mode'.
 4. Click 'Load Unpacked Extensions' and point to the above directory.
-5. Start using it!
-
-
-### Known Issues:
 
-1. Hovering over a link will make focused input lose focus (temporarily - focus restored when you move out of link).
-2. When the cursor is still in the URL box, hyperlink is not copied.
+## Known Issue:
+For my this bug is not really a problem, but for you it may be one: ***Hovering over a link will make focused text input fields lose focus*** (sometimes only temporarily - focus should be restored when you move away from the link). This fault is not yet resolved due to my very limited JavaScript Skills, but if you claim to be a "modern web developer" you are happily invited to fix this issue, of course.

+ 21 - 9
copylinkaddress.js

@@ -13,17 +13,29 @@ If, at the time of hover, the cursor was in a textbox (without anything selected
 it is technically a zero-length selection in Chrome. So, the extension goes ahead and clears that selection
 (thereby taking the cursor away from the textbox), saving the caret position.
 When you move away from the link, the caret position is restored.
-
 */
 
+COPYL_DEBUG = true;
+
+let url = chrome.runtime.getURL('sounds/pop.mp3');
+let a = new Audio(url);
+var previousCaretPosition = -1;
 var linkAddress = $('<span id="copylAddress" style="display: inline-block;" />');
 $('body').append(linkAddress);
-// This is a DOM element that has to be selectable but not visible to anybody
+/* This is a DOM element that has to be selectable but not visible to anybody */
 linkAddress.css({position: 'absolute', left:'-9999em'});
 
-var previousCaretPosition = -1;
+/* when the user presses y (=yank), copy URL to clipboard when hovering */
+window.onkeydown = function(event) {
+    if (event.key == "y") {
+        if (linkAddress.text().length != 0) {
+			document.execCommand('copy');
+            a.play();
+        }
+    }
+}
+
 
-COPYL_DEBUG = false;
 
 function write_to_console(text) {
     if (COPYL_DEBUG)
@@ -31,7 +43,7 @@ function write_to_console(text) {
 }
 
 function selectElement(el) {
-    // Check if anything is currently selected, if so backup
+    /* Check if anything is currently selected, if so backup */
     if (window.getSelection().rangeCount > 0) {
         previousCaretPosition = document.activeElement.selectionStart;
     }
@@ -73,9 +85,9 @@ function clearLinkAddress() {
 }
 
 $(function() {
-    // The code attaches itself to all anchor elements
+    /* The code attaches itself to all anchor elements */
     $("html").on("mouseenter", "a", function(){
-        // Everytime the user hovers (enters) a link
+        /* Everytime the user hovers (enters) a link */
         if(window.getSelection().toString()) {
             write_to_console("Something is already selected. Don't do anything.");
         } else {
@@ -88,7 +100,7 @@ $(function() {
 
         write_to_console("Current Selection: " + window.getSelection().toString());
     }).on("mouseleave", "a", function(){
-            // Every time the user leaves a link
+            /* Every time the user leaves a link */
             write_to_console("Leaving link.");
             clearLinkAddress();
         });
@@ -96,5 +108,5 @@ $(function() {
     $(window).on("beforeunload", function() {
         clearLinkAddress();
     });
+});
 
-});

+ 8 - 5
manifest.json

@@ -1,8 +1,8 @@
 {
     "manifest_version": 2,
-    "name": "Copy Link Address",
-    "version": "0.5.5",
-    "description": "Copy link address without right-clicking. Just hover the link and hit Ctrl-C / Cmd-C!",
+    "name": "Copy URL on Hover",
+    "version": "0.6.0",
+    "description": "Hover over a link and hit Y to yank (copy) it like a real vim user! For feedback, a pop sound will be played after copying.",
     "content_scripts": [
         {
         "matches": ["<all_urls>"],
@@ -12,5 +12,8 @@
     "icons": {
             "48": "/icons/icon48.png",
             "128": "/icons/icon128.png"
-    }
-}
+    },
+    	"web_accessible_resources": [
+		"sounds/pop.mp3"
+	]
+}

BIN
sounds/ding.mp3


BIN
sounds/pop.mp3