Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Mouse hover copy link



  • Please log in to reply
8 replies to this topic
crystalblue
  • Members
  • 3 posts
  • Last active:
  • Joined: 24 Jun 2014

I came across a similar topic that suggested StatusBarGetText. Unfortunately I need to be able to refresh the page (in Chrome) while the script is running. Refreshing the page would update the status bar text to the current page URL — I need to have precise control with my mouse over which URLs to copy. 

 

What is the best/simplest method to achieve my goal? I am new to AHK and would appreciate any corrections and help. 



atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007
✓  Best Answer

Hi.

 

For this particular task I wouldn't use AutoHotkey. Chrome can't be fully controlled with AHK (unlike IE) and accessing the links sounds more like a task for JavaScript. I've found a Chrome extension that does what you want, but if you're as paranoid as me, you may want to do your own userscript (via Tampermonkey). It's pretty easy:

// ==UserScript==
// @name        URL Copy When Hover
// @namespace   com.atnbueno.url-copy-when-hover
// @include     http://www.autohotkey.com/*
// @require     http://code.jquery.com/jquery-2.1.1.min.js
// @version     0.1
// @grant       GM_setClipboard
// ==/UserScript==

$(document).ready(function() {
  $("a").hover(function() {
    GM_setClipboard($(this).attr("href"));
  });
});

Or, if you want to be more verbose:

// ==UserScript==
// @name        URL Copy When Hover
// @namespace   com.atnbueno.url-copy-when-hover
// @include     http://www.autohotkey.com/*
// @require     http://code.jquery.com/jquery-2.1.1.min.js
// @version     0.2
// @grant       GM_setClipboard
// ==/UserScript==

$(document).ready(function() {
  console.log('"URL Copy When Hover" ready');
  $("a").hover(function() {
    var URL = $(this).attr("href");
    GM_setClipboard(URL);
    console.log('"'+URL+'" copied to clipboard');
  });
});

In general I've found the combo Tampermonkey+AHK amazingly useful when dealing with Chrome (and Greasemonkey+AHK for Firefox).

 

 

Regards,

Antonio



crystalblue
  • Members
  • 3 posts
  • Last active:
  • Joined: 24 Jun 2014

 

This is brilliant, thank you! 



mhe
  • Members
  • 40 posts
  • Last active: Dec 04 2015 10:29 PM
  • Joined: 18 Oct 2007

atnbueno, thanks man that's really useful. I was actually using that extension you linked to but felt it was interfering with certain copy/paste behaviour, like rearranging words in input fields like on google, if your mouse left the input area it would deselect the input box or something and it was getting on my nerve.

 

I don't think your script does that, if it does, would it be possible to use some other hotkey and leave ctrl+c/v as it is?



atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007

Glad you find it useful, mhe.

 

The userscript above does nothing with keys, and it only affects links (the <a href=...> tags). It simply tells the browser "each time the mouse pointer passes over a link, copy the link URL to the clipboard".

 

If you want it to interact with an AutoHotkey script (for example, to copy the URL only when a hotkey is pressed), you can modify the userscript to add the URL to the webpage title instead of copying it, where it can be easily accessed with AutoHotkey.


Regards,
Antonio

mhe
  • Members
  • 40 posts
  • Last active: Dec 04 2015 10:29 PM
  • Joined: 18 Oct 2007

Ah i see, the hotkey method would be more useful for me, less clutter in my clipbook manager that way.



atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007

The modification is trivial. The userscript would be something like this (I've used "§" as delimiter):

// ==UserScript==
// @name        URL In Title When Hover
// @namespace   com.atnbueno.url-in-title-when-hover
// @include     http://www.autohotkey.com/*
// @require     http://code.jquery.com/jquery-2.1.1.min.js
// @grant       none
// @version     0.1
// ==/UserScript==

$(document).ready(function() {
  var originalTitle = document.title;
  $("a").hover(function() {
    document.title = originalTitle + "§" + this.href + "§";
  }, function() {
    document.title = originalTitle;
  });
});

And the corresponding AutoHotkey script would be something like this (the hotkey is Ctrl+Alt+c):

; AutoHotkey Version: AutoHotkey_L 1.1 (Unicode x86)
; Language:           English
; Platform:           Win7 SP1
; Author:             Antonio Bueno <user atnbueno at Google's free e-mail service>
; Description:        Gets URL from window title (URL expected between §s)
; Last Mod:           2014-08-06

GroupAdd, MonkeyBrowsers, ahk_class MozillaWindowClass
GroupAdd, MonkeyBrowsers, ahk_class Chrome_WidgetWin_1

#IfWinActive, ahk_group MonkeyBrowsers
^!c::
  WinGetTitle, BrowserTabTitle
  Loop, Parse, BrowserTabTitle, §
  If (A_Index==2)
    Clipboard := A_LoopField
Return

It works both in Firefox 31 and Chrome 36.

 


Regards,
Antonio

mhe
  • Members
  • 40 posts
  • Last active: Dec 04 2015 10:29 PM
  • Joined: 18 Oct 2007

Thanks atnbueno, i'll try it out later.



Ismail
  • Members
  • 1 posts
  • Last active: Sep 15 2014 05:00 PM
  • Joined: 15 Sep 2014

when i run your program in windows server 2008 then show this error.

--------------------------------------------------------------------------
Error at line 65.

Line Text:Try sURL:=accAddressBar.accValue(0)

Error:This line does not contain a recognized acton.

The program wiil exit