stackoverflow make markdown link for question and answers automatically

stackoverflow make markdown link for question and answers automatically :)

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         stackoverflow make markdown link for question and answers automatically
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description    stackoverflow make markdown link for question and answers automatically :)
// @author        批小将
// @match         https://*.stackexchange.com/*
// @match         https://stackoverflow.com/*
// @match         https://serverfault.com/*
// @grant         none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    function makeShareMDLink(){
        let shareBtnTemplate = `<button class="js-copy-link-btn s-btn s-btn__link">Copy MD link</button>`;
        let shareTags = document.querySelectorAll('div.my8');
        for(let i = 0; i < shareTags.length; i++){
            let shareTag = shareTags[i];
            let shareLink = shareTag.firstChild.value;
            let shareBtn = shareTag.nextSibling.firstChild;
            shareBtn.insertAdjacentHTML('afterend', shareBtnTemplate);
            shareBtn.nextSibling.addEventListener('click', function(){
                //Define the MD link as you like, here it's `[answer](https://stackoverflow.com/answerlink)`
                let shareText = "answer";
                let shareMDText = '[' + shareText + '](' + shareLink + ')';
                navigator.clipboard.writeText(shareMDText);
            })

        }
    }

    function makeQuestionMDlink(){
        let btnTemplate = `<button class="ws-nowrap s-btn s-btn__primary" id="makeMDbtn" style="margin-top: 5px;">make MD link</button>`;
        let askQuestionTag = document.querySelector('div.aside-cta');
        askQuestionTag.insertAdjacentHTML('beforeend', btnTemplate);
        let btn = document.getElementById('makeMDbtn');

        let shareBtnTemplate = '<button class="js-copy-link-btn s-btn s-btn__link">Copy MD link</button>';

        btn.addEventListener('click', function(){
            let qTag = document.querySelector('#question-header .question-hyperlink');
            let link = qTag.href;
            let text = qTag.innerText;

            let markdownText = '[' + text + '](' + link + ')';
            navigator.clipboard.writeText(markdownText);
        });
    }

   let timeout = 1000;

    makeQuestionMDlink();
    setTimeout(function(){
        makeShareMDLink();
    }, timeout);

})();