hover-copy

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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