🏠 Home 

快捷键复制 MarkDown 格式的超链接或标题

用快捷键复制 MarkDown 格式的超链接或标题到剪贴板


Install this script?
  1. // ==UserScript==
  2. // @name 快捷键复制 MarkDown 格式的超链接或标题
  3. // @namespace https://greasyfork.org/users/518374
  4. // @version 0.3
  5. // @description 用快捷键复制 MarkDown 格式的超链接或标题到剪贴板
  6. // @author InMirrors
  7. // @match *://*/*
  8. // @grant GM_registerMenuCommand
  9. // @grant GM_setClipboard
  10. // @icon https://plugins.jetbrains.com/files/18897/166369/icon/pluginIcon.png
  11. // @license MIT
  12. // ==/UserScript==
  13. (function() {
  14. 'use strict';
  15. function copyWithConfirmation(text) {
  16. GM_setClipboard(text);
  17. // Show confirmation message
  18. var confirmation = document.createElement("div");
  19. confirmation.innerHTML = "Copied";
  20. confirmation.style.cssText = `
  21. position : fixed;
  22. left : 50%;
  23. bottom : 30px;
  24. padding : 10px;
  25. background : lightgreen;
  26. opacity : 0.8;
  27. border-radius : 20px;
  28. box-shadow: 0px 0px 3px teal;
  29. font-weight : bold;
  30. font-size:15px;
  31. z-index : 999;
  32. `
  33. document.body.appendChild(confirmation);
  34. // Remove after 2 seconds
  35. setTimeout(function() {
  36. confirmation.remove();
  37. }, 2000);
  38. }
  39. GM_registerMenuCommand("复制标题及链接", () => copyWithConfirmation(`[${document.title}](${document.URL})`));
  40. GM_registerMenuCommand("仅复制标题", () => copyWithConfirmation(document.title));
  41. GM_registerMenuCommand("仅复制链接", () => copyWithConfirmation(document.URL));
  42. document.onkeydown = function(event) { // 修改以下的 if 条件实现自定义快捷键,键值请参见:https://keycode.info/
  43. if (event.altKey && event.keyCode == 82) {
  44. copyWithConfirmation(document.title);
  45. }
  46. if (event.shiftKey && event.altKey && event.keyCode == 82) {
  47. copyWithConfirmation(`[${document.title}](${document.URL})`);
  48. }
  49. if (event.altKey && event.keyCode == 72) {
  50. copyWithConfirmation(`<a href="${document.URL}">${document.title}</a>`);
  51. }
  52. }
  53. })();