Copy Link!

Copy the link to current web page, in Markdown or HTML, have the URL decoded to Unicode string, or have the protocol removed.

  1. // ==UserScript==
  2. // @name Copy Link!
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.1
  5. // @description Copy the link to current web page, in Markdown or HTML, have the URL decoded to Unicode string, or have the protocol removed.
  6. // @author firetree
  7. // @match *://*/*
  8. // @grant GM_registerMenuCommand
  9. // @grant GM_setClipboard
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. let href
  17.  
  18. /**
  19. * @param {function(string):string} textProvider
  20. * @param {boolean?} doChain
  21. */
  22. function setClipboard(textProvider, doChain) {
  23. if (typeof href === 'undefined') href = location.href
  24.  
  25. let result = textProvider(href)
  26.  
  27. GM_setClipboard(result)
  28.  
  29. if (doChain) href = result
  30. }
  31.  
  32. function strip(href) {
  33. return href.replace(/^https?:\/\//, '').replace(/\/$/, '')
  34. }
  35.  
  36. const commands = [
  37. ['Copy Link', () => setClipboard(href => href)],
  38. ['Copy Title', () => GM_setClipboard(document.title)],
  39. ['Decode URL', () => setClipboard(href => decodeURIComponent(href), true)],
  40. ['Strip', () => setClipboard(href => strip(href))],
  41. ['Markdown', () => setClipboard(href => `[${document.title}](${href})`)],
  42. ['Markdown Strip', () => setClipboard(href => `[${strip(href)}](${href})`)],
  43. ['HTML', () => setClipboard(href => `<a href="${href}">${document.title}</a>`)],
  44. ['HTML Strip', () => setClipboard(href => `<a href="${href}">${strip(href)}</a>`)],
  45. ]
  46.  
  47. for (let [name, func] of commands) {
  48. GM_registerMenuCommand(name, func)
  49. }
  50. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址