hover-copy

Hover over A or IMG, then press Ctrl+c to copy link.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         hover-copy
// @namespace    https://github.com/nameldk/user-script
// @version      0.1
// @description  Hover over A or IMG, then press Ctrl+c to copy link.
// @author       You
// @match        https://*/*
// @match        http://*/*
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // copy from: https://chrome.google.com/webstore/detail/hover-and-copy/moanghbdjdafhoppikcalbkggpnbhhid
    $(document).ready(function () {
        var $body = $('body');

        function isUrlValid(url) {
            var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
            return regexp.test(url) || /^data:image\//.test(url);
        }

        var inputForCopy = $('<input id="input_for_copy">');

        $body.append(inputForCopy);

        inputForCopy.css({
            position: 'absolute',
            left: -9999
        });

        $body.on('mouseenter', 'a, img', function (e) {
            var hoverTarget = $(e.target);
            var hoverLink;

            if (hoverTarget.is('img')) {
                hoverLink = hoverTarget.attr('src');
            } else {
                hoverLink = hoverTarget.attr('href');
                if (typeof hoverLink === 'undefined') {
                    hoverLink = hoverTarget.closest('a').attr('href');
                }
            }

            if (!isUrlValid(hoverLink)) {
                hoverLink = window.location.origin + '/' + hoverLink;
            }

            inputForCopy.focus({
                preventScroll: true,
            });

            inputForCopy.val(hoverLink);
            inputForCopy.select();

        }).on('mouseleave', 'a, img', function () {
            inputForCopy.blur();
        })
    });
})();