VoidPaste

Auto transform pasted image links.

安装此脚本
作者推荐脚本

您可能也喜欢VoidVerified

安装此脚本
  1. // ==UserScript==
  2. // @name VoidPaste
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.0
  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 imageFormats = [
  16. "jpg",
  17. "png",
  18. "gif",
  19. "webp",
  20. "apng",
  21. "avif",
  22. "jpeg",
  23. "svg",
  24. ];
  25. const imageWidth = "420";
  26.  
  27. let isShiftPressed = false;
  28.  
  29. window.addEventListener("keydown", (event) => {
  30. if (event.key !== "Shift") {
  31. return;
  32. }
  33.  
  34. isShiftPressed = true;
  35. });
  36.  
  37. window.addEventListener("keyup", (event) => {
  38. if (event.key !== "Shift") {
  39. return;
  40. }
  41.  
  42. isShiftPressed = false;
  43. });
  44.  
  45. window.addEventListener("paste", (event) => {
  46. const clipboard = event.clipboardData.getData("text/plain").trim();
  47.  
  48. if (!isShiftPressed){
  49. return;
  50. }
  51.  
  52. event.preventDefault();
  53. const rows = clipboard.split("\n");
  54. let urlList = [];
  55.  
  56.  
  57. for (const row of rows){
  58. if (!imageFormats.some(format => row.toLowerCase().endsWith(format))) {
  59. continue;
  60. }
  61.  
  62. urlList.push(`[ img${imageWidth}(${row}) ](${row})`);
  63. }
  64.  
  65. const transformedClipboard = urlList.join("\n\n");
  66.  
  67. window.document.execCommand('insertText', false, transformedClipboard);
  68. });
  69. })();