Advertisement
Guest User

Untitled

a guest
Mar 20th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Markdown share for SE
  3. // @version 1
  4. // @grant none
  5. // @include https://stackoverflow.com/questions/*
  6. // ==/UserScript==
  7. function makeMarkdown() {
  8. const title = document.querySelector("#question-header h1").textContent;
  9. const href = document.querySelector(".js-share-link").href;
  10. const url = href.slice(0, href.lastIndexOf("/"));
  11.  
  12. return `[${title}](${url})`;
  13. }
  14.  
  15. function makeLink(text) {
  16. const link = document.createElement("a");
  17. link.classList.add("js-share-link");
  18. link.href = "#";
  19. link.addEventListener("click", (event) => {
  20. event.preventDefault();
  21. console.log(text);
  22. });
  23. link.textContent = "share markdown"
  24.  
  25. return link
  26. }
  27.  
  28. function addLink(el) {
  29. const menu = document.querySelector(".post-menu");
  30. menu.appendChild(el);
  31. }
  32.  
  33. const markdown = makeMarkdown();
  34. const link = makeLink(markdown);
  35. addLink(link);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement