Copy URL as Markdown Link

Right-click on a blank area of the page to copy the current page's title and URL as a Markdown formatted link to the clipboard.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name                Copy URL as Markdown Link
// @name:zh-CN          复制 Markdown 格式超链接
// @version             1.0.1
// @description         Right-click on a blank area of the page to copy the current page's title and URL as a Markdown formatted link to the clipboard.
// @description:zh-CN   在页面中空白位置右键,将当前页面的标题和 URL 以 Markdown 格式复制到剪贴板。
// @namespace           https://github.com/yxzlwz/browser_scripts
// @author              yxzlwz
// @match               *://*/*
// @grant               GM_registerMenuCommand
// ==/UserScript==

GM_registerMenuCommand("Generally", function () {
    copyMarkdownLink(false);
});

GM_registerMenuCommand("Without Query", function () {
    copyMarkdownLink(true);
});

GM_registerMenuCommand("Title Only", function () {
    navigator.clipboard.writeText(document.title);
});

function copyMarkdownLink(ignoreQuery) {
    let url = window.location.href;
    const title = document.title;

    if (ignoreQuery) {
        url = url.split("?")[0];
    }

    const markdownLink = `[${title}](${url})`;

    navigator.clipboard
        .writeText(markdownLink)
        .then(() => {
            console.log("URL copied as markdown link!");
        })
        .catch(error => {
            console.error("Error copying URL as markdown link:", error);
        });
}