VoidPaste

Auto transform pasted image links.

当前为 2023-10-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name VoidPaste
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.2
  5. // @description Auto transform pasted image links.
  6. // @author voidnyan
  7. // @match https://anilist.co/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const imageUrls = [
  16. "https://i.ibb.co"
  17. ];
  18. const imageWidth = "320";
  19.  
  20. let isShiftPressed = false;
  21.  
  22. window.addEventListener("keydown", (event) => {
  23. if (event.key !== "Shift") {
  24. return;
  25. }
  26.  
  27. isShiftPressed = true;
  28. });
  29.  
  30. window.addEventListener("keyup", (event) => {
  31. if (event.key !== "Shift") {
  32. return;
  33. }
  34.  
  35. isShiftPressed = false;
  36. });
  37.  
  38. window.addEventListener("paste", (event) => {
  39. const clipboard = event.clipboardData.getData("text/plain").trim();
  40.  
  41. if (!clipboard.startsWith(imageUrls) || !isShiftPressed){
  42. return;
  43. }
  44.  
  45. event.preventDefault();
  46. let transformedClipboard = "";
  47. const urlList = clipboard.split("\n");
  48.  
  49. for (const url of urlList){
  50. transformedClipboard += `[ img${imageWidth}(${url}) ](${url})\n\n`;
  51. }
  52.  
  53. window.document.execCommand('insertText', false, transformedClipboard);
  54. });
  55.  
  56. })();