hover-copy

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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();
        })
    });
})();