Greasy Fork is available in English.

Catbox.moe to ChanWiki Converter

Convert Catbox.moe links to ChanWiki gallery and image formats and copy to clipboard

  1. // ==UserScript==
  2. // @name Catbox.moe to ChanWiki Converter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Convert Catbox.moe links to ChanWiki gallery and image formats and copy to clipboard
  6. // @match https://catbox.moe/
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. function createButton(text, icon) {
  14. const button = document.createElement('button');
  15. button.innerHTML = `<span style="margin-right: 5px;">${icon}</span>${text}`;
  16. button.style.marginRight = '10px';
  17. button.style.padding = '8px 16px';
  18. button.style.fontSize = '14px';
  19. button.style.fontWeight = 'bold';
  20. button.style.color = '#ffffff';
  21. button.style.backgroundColor = '#2c3e50';
  22. button.style.border = 'none';
  23. button.style.borderRadius = '4px';
  24. button.style.cursor = 'pointer';
  25. button.style.transition = 'background-color 0.3s';
  26. button.style.display = 'flex';
  27. button.style.alignItems = 'center';
  28.  
  29. button.addEventListener('mouseenter', function() {
  30. this.style.backgroundColor = '#34495e';
  31. });
  32.  
  33. button.addEventListener('mouseleave', function() {
  34. this.style.backgroundColor = '#2c3e50';
  35. });
  36.  
  37. return button;
  38. }
  39.  
  40. function copyToClipboard(text) {
  41. const textArea = document.createElement('textarea');
  42. textArea.value = text;
  43. document.body.appendChild(textArea);
  44. textArea.select();
  45. document.execCommand('copy');
  46. document.body.removeChild(textArea);
  47. }
  48.  
  49. const buttonContainer = document.createElement('div');
  50. buttonContainer.style.position = 'fixed';
  51. buttonContainer.style.top = '10px';
  52. buttonContainer.style.right = '10px';
  53. buttonContainer.style.zIndex = '9999';
  54. buttonContainer.style.display = 'flex';
  55.  
  56. const imageButton = createButton('Save as image', '🖼️');
  57.  
  58. const galleryButton = createButton('Save as gallery', '🖼️🖼️');
  59.  
  60. function getMatches() {
  61. const regex = /https:\/\/files\.catbox\.moe\/[a-zA-Z0-9]+\.[a-zA-Z]+/g;
  62. const pageText = document.body.innerText;
  63. return pageText.match(regex);
  64. }
  65.  
  66. function showCopiedMessage(button, originalText, originalIcon) {
  67. const originalBackground = button.style.backgroundColor;
  68. button.innerHTML = '<span style="margin-right: 5px;">✅</span>Copied!';
  69. button.style.backgroundColor = '#27ae60';
  70. setTimeout(() => {
  71. button.innerHTML = `<span style="margin-right: 5px;">${originalIcon}</span>${originalText}`;
  72. button.style.backgroundColor = originalBackground;
  73. }, 2000);
  74. }
  75.  
  76. imageButton.addEventListener('click', function() {
  77. const matches = getMatches();
  78. let imageText = '';
  79. if (matches) {
  80. matches.forEach(url => {
  81. imageText += `{{ObrazekNowy|l=${url}|float=right}}\n`;
  82. });
  83. copyToClipboard(imageText.trim());
  84. showCopiedMessage(imageButton, 'Save as image', '🖼️');
  85. } else {
  86. this.innerHTML = '<span style="margin-right: 5px;">❌</span>No links found';
  87. setTimeout(() => {
  88. this.innerHTML = '<span style="margin-right: 5px;">🖼️</span>Save as image';
  89. }, 2000);
  90. }
  91. });
  92.  
  93. galleryButton.addEventListener('click', function() {
  94. const matches = getMatches();
  95. let galleryText = '';
  96. if (matches) {
  97. matches.forEach(url => {
  98. galleryText += `{{Obrazek2|l=${url}}}\n`;
  99. });
  100. copyToClipboard(galleryText.trim());
  101. showCopiedMessage(galleryButton, 'Save as gallery', '🖼️🖼️');
  102. } else {
  103. this.innerHTML = '<span style="margin-right: 5px;">❌</span>No links found';
  104. setTimeout(() => {
  105. this.innerHTML = '<span style="margin-right: 5px;">🖼️🖼️</span>Save as gallery';
  106. }, 2000);
  107. }
  108. });
  109.  
  110. buttonContainer.appendChild(imageButton);
  111. buttonContainer.appendChild(galleryButton);
  112.  
  113. document.body.appendChild(buttonContainer);
  114. })();