Copy Link!

Copy the link to current web page, in Markdown or HTML, have the URL decoded to Unicode string, or have the protocol removed.

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

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

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         Copy Link!
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Copy the link to current web page, in Markdown or HTML, have the URL decoded to Unicode string, or have the protocol removed.
// @author       firetree
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    let href

    /**
     * @param {function(string):string} textProvider
     * @param {boolean?} doChain
     */
    function setClipboard(textProvider, doChain) {
        if (typeof href === 'undefined') href = location.href

        let result = textProvider(href)

        GM_setClipboard(result)

        if (doChain) href = result
    }

    function strip(href) {
        return href.replace(/^https?:\/\//, '').replace(/\/$/, '')
    }

    const commands = [
        ['Copy Link', () => setClipboard(href => href)],
        ['Copy Title', () => GM_setClipboard(document.title)],
        ['Decode URL', () => setClipboard(href => decodeURIComponent(href), true)],
        ['Strip', () => setClipboard(href => strip(href))],
        ['Markdown', () => setClipboard(href => `[${document.title}](${href})`)],
        ['Markdown Strip', () => setClipboard(href => `[${strip(href)}](${href})`)],
        ['HTML', () => setClipboard(href => `<a href="${href}">${document.title}</a>`)],
        ['HTML Strip', () => setClipboard(href => `<a href="${href}">${strip(href)}</a>`)],
    ]

    for (let [name, func] of commands) {
        GM_registerMenuCommand(name, func)
    }
})();