Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Markdown share for SE
- // @version 1
- // @grant none
- // @include https://stackoverflow.com/questions/*
- // ==/UserScript==
- function makeMarkdown() {
- const title = document.querySelector("#question-header h1").textContent;
- const href = document.querySelector(".js-share-link").href;
- const url = href.slice(0, href.lastIndexOf("/"));
- return `[${title}](${url})`;
- }
- function makeLink(text) {
- const link = document.createElement("a");
- link.classList.add("js-share-link");
- link.href = "#";
- link.addEventListener("click", (event) => {
- event.preventDefault();
- console.log(text);
- });
- link.textContent = "share markdown"
- return link
- }
- function addLink(el) {
- const menu = document.querySelector(".post-menu");
- menu.appendChild(el);
- }
- const markdown = makeMarkdown();
- const link = makeLink(markdown);
- addLink(link);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement