Link To Markdown

网站链接转 Markdown 格式

  1. // ==UserScript==
  2. // @name Link To Markdown
  3. // @namespace https://www.yuelili.com/
  4. // @version 0.0.3
  5. // @description 网站链接转 Markdown 格式
  6. // @author Yueli
  7. // @match *://*/*
  8. // @icon https://raiseyang.github.io/static/markdown_copy.png
  9. // @require https://cdn.bootcss.com/jquery/2.1.2/jquery.min.js
  10. // @grant GM_setClipboard
  11. // @grant GM_addStyle
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. // @fork https://greasyfork.org/zh-CN/scripts/438841
  16. //
  17.  
  18. (function () {
  19. "use strict";
  20. const { $ } = window;
  21. const hostMap = {
  22. "www.bilibili.com": () =>
  23. document.title.replace("_哔哩哔哩_bilibili", "_B站") + "_" + document.querySelector('meta[name="author"]').getAttribute("content"),
  24. "space.bilibili.com": () => document.title.replace("_哔哩哔哩_bilibili", "_B站"),
  25. "blog.csdn.net": () => $("#articleContentId").text(),
  26. "juejin.cn": () => $(".article-title").text().trim(),
  27. "github.com": () => document.title.split(":")[0],
  28. "jianshu.com": () => document.title.split(" - 简书")[0],
  29. "cloud.tencent.com": () => document.title.split(" - 云+社区 - 腾讯云")[0],
  30. "medium.com": () => getMeta("og:title"),
  31. "www.zhihu.com": () => document.title.split(" - 知乎")[0].replace(/\(.*私信.*\)/g, ""),
  32. };
  33.  
  34. const getMeta = (prop) => $('meta[property="' + prop + '"]').attr("content");
  35.  
  36. // 创建按钮
  37. const button = document.createElement("button"); //创建一个input对象(提示框按钮)
  38. button.id = "markdown_copy";
  39. button.textContent = "拷贝链接";
  40. button.style.cssText = `
  41. position: fixed;
  42. bottom: 100px;
  43. right: 10px;
  44. background:#282C34;
  45. width: 92px;
  46. height: 30px;
  47. color:white;
  48. z-index:999;
  49. font-weight:bold;
  50. font-size:15px;
  51. opacity: 0;
  52. transition: opacity 0.3s ease-in-out;
  53. border-radius:50px;
  54. `;
  55. const hover_style = `button#markdown_copy:hover{opacity:1!important}`;
  56. GM_addStyle(hover_style);
  57.  
  58. //绑定按键点击功能
  59. button.onclick = function () {
  60. const link = window.location.href;
  61. const { host } = window.location;
  62. const title = hostMap[host] ? hostMap[host]() : document.title;
  63. const markdownLink = `[${title}](${link})`;
  64. GM_setClipboard(markdownLink, "text");
  65. };
  66.  
  67. $(function () {
  68. $("body").append(button); // 添加button按钮
  69. });
  70. })();