Bookmarklets to User Scripts (Everywhere)

Any page that has a bookmarklet will show a monkey icon

  1. // ==UserScript==
  2. // @name Bookmarklets to User Scripts (Everywhere)
  3. // @version 0.1.1
  4. // @description Any page that has a bookmarklet will show a monkey icon
  5. // @description next to it, click that icon and it will create a UserScript
  6. // @description for you to use in Tampermonkey
  7. // @author
  8. // @include *://*/*
  9. // @icon data:image/gif;base64,R0lGODlhEAAQAOYAAM6KjNaanO%2Byte%2B6vffDxr2anGtZWq2qraWipXt5e4SChHt9e5SWlISGhK2uraWmpb1RALVNAK1JAKVJAJRBAMZdEL1ZEIxJGIxdOb1NAKVFAJxBAJQ8AM5dELVVEJxNGJRRIYxNIb1pMaVlOa1tQq1JCKVNGJRJGKVVIZxRIZRNIYxVMbV5UoxpUoxtWpQ8CJxNIbVhMZxZMZRVMaV1Wr1hMZRdQr1pQs55UqVhQsZ1UtZ9Ws59Wr1xUs55WrVtUsZ1Wq1pUpRdSsaCa5SOjM6Ca855Y8Z9a86Gc86Cc715a96ajNaOhN6WjNaSjIx1c4RlY9aOjN6enM6mpd62teempf%2FHxv%2FPzgAAAP%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAFkALAAAAAAQABAAQAewgFmCg4SFgi8eAVdYWIuNARUaGA2CQQNXV1U3VZgDOTSDSVYGjKWMBlZIQgiEGxqvEhIaM4QiEEeYmAS5V0MRGgpZUbzEmE4jD4IhFjxNAs9NOx0nT4ZZIBwcFCnWgj9LTDESNUxLPS6DLBJKvAC8ShMXWSQaQJiMjpg%2BGh%2BUHkWcilUx0mGFgywCqGApQGwKlikCVBzIIkOHlGJXpOCAAYVQCxQaIkTIUMKEDSKDAgEAOw%3D%3D
  10. // @grant none
  11. // @license MIT
  12. // @namespace https://gf.qytechs.cn/users/13026
  13. // ==/UserScript==
  14.  
  15. /**
  16. *
  17. * This UserScript was originally created by
  18. * [Jesse Ruderman](mailto:jruderman@gmail.com) it would only create
  19. * userscripts from his website at
  20. * [Jesse's Bookmarklets Site](https://www.squarefree.com/bookmarklets/)
  21. * but it seemed to be
  22. * broken and did not create a UserScript. I changed the code so that it
  23. * would take the javascript from a bookmarklet (on any website) and
  24. * create a UserScript and open it in a new tab. I continue to use his
  25. * icon and the general idea of his. Much appreciated! With my new
  26. * version, you can open any webpage, and if you see the monkey icon
  27. * there you can click on it and a new window will open with the
  28. * UserScript mostly created for you. Copy the contents and then paste
  29. * it into a new UserScript in Tampermonkey or your preferred manager.
  30. *
  31. */
  32.  
  33. // Define the regex pattern to check if a link is a bookmarklet.
  34. const bookmarkletPattern = /javascript:\(function\(\).*\{.*\}\)\(\)/;
  35.  
  36. // Iterate through all the links present on the webpage.
  37. for (let i = 0; i < document.links.length; i++) {
  38. let bookmarklet = document.links[i];
  39.  
  40. // Check if the link matches the bookmarklet pattern using the regex test.
  41. if (bookmarkletPattern.test(bookmarklet.href)) {
  42. // Extract the name of the bookmarklet. If not present, default to 'Unnamed Bookmarklet'.
  43. let bookmarkletName = bookmarklet.textContent.trim() || "Unnamed Bookmarklet";
  44.  
  45. // Decode the content of the bookmarklet and remove typical wrappers.
  46. let bookmarkletContent = decodeURIComponent(bookmarklet.href);
  47. let contentWithoutJS = bookmarkletContent
  48. .substring(11)
  49. .replace(/^\(function\(\)\{|\}\)\(\);?$/g, "");
  50.  
  51. // Create an image element and set its properties.
  52. let img = document.createElement("img");
  53. img.src =
  54. "data:image/gif;base64,R0lGODlhEAAQAOYAAM6KjNaanO%2Byte%2B6vffDxr2anGtZWq2qraWipXt5e4SChHt9e5SWlISGhK2uraWmpb1RALVNAK1JAKVJAJRBAMZdEL1ZEIxJGIxdOb1NAKVFAJxBAJQ8AM5dELVVEJxNGJRRIYxNIb1pMaVlOa1tQq1JCKVNGJRJGKVVIZxRIZRNIYxVMbV5UoxpUoxtWpQ8CJxNIbVhMZxZMZRVMaV1Wr1hMZRdQr1pQs55UqVhQsZ1UtZ9Ws59Wr1xUs55WrVtUsZ1Wq1pUpRdSsaCa5SOjM6Ca855Y8Z9a86Gc86Cc715a96ajNaOhN6WjNaSjIx1c4RlY9aOjN6enM6mpd62teempf%2FHxv%2FPzgAAAP%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAFkALAAAAAAQABAAQAewgFmCg4SFgi8eAVdYWIuNARUaGA2CQQNXV1U3VZgDOTSDSVYGjKWMBlZIQgiEGxqvEhIaM4QiEEeYmAS5V0MRGgpZUbzEmE4jD4IhFjxNAs9NOx0nT4ZZIBwcFCnWgj9LTDESNUxLPS6DLBJKvAC8ShMXWSQaQJiMjpg%2BGh%2BUHkWcilUx0mGFgywCqGApQGwKlikCVBzIIkOHlGJXpOCAAYVQCxQaIkTIUMKEDSKDAgEAOw%3D%3D";
  55. img.alt = `View ${bookmarkletName} as a user script.`;
  56. img.title = img.alt;
  57. img.style.border = "none";
  58. img.style.display = "inline";
  59. img.style.position = "relative";
  60. img.style.zIndex = "1000";
  61.  
  62. // Construct the content for the user script.
  63. let scriptContent = `
  64. // ==UserScript==
  65. // @name ${bookmarkletName}
  66. // @description Runs the ${bookmarkletName} bookmarklet from ${location.href}
  67. // ==/UserScript==
  68. ${contentWithoutJS}
  69. `;
  70.  
  71. // Create a new anchor tag, set its properties, and attach the onclick event handler.
  72. let a = document.createElement("a");
  73. a.href = "#";
  74. a.onclick = function () {
  75. let newWindow = window.open("", "_blank");
  76. newWindow.document.write("<pre>" + scriptContent + "</pre>");
  77. return false;
  78. };
  79. a.appendChild(img);
  80.  
  81. // Insert the new anchor tag (with the image) just before the bookmarklet link.
  82. bookmarklet.parentNode.insertBefore(a, bookmarklet);
  83.  
  84. // Increment the index since we added a new link.
  85. i++;
  86. }
  87. }

QingJ © 2025

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