imgbox tweaker

Adds custom formatted links and other improvements.

目前为 2022-11-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name imgbox tweaker
  3. // @namespace surrealmoviez.info
  4. // @description Adds custom formatted links and other improvements.
  5. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAASBJREFUeNpiZACCltZWASDVD8QJDPQBC4C4sKa6+gMj1PL9QGzAQF9wAYgdmaA+p7flDFA7+5noGOzYQAITwwADFmyCHBwcDL4+PgxqampUseTWrVsMm7dsYfjx4weGHNYQoKblIAAyC2QmNsCESwO1AS4zB2caQAf/fn1meHegGUwTA5jYeBmEHGrBNFUc8OFYP8P3BwdJ8tm7AwwMIm5dhB1LjGF/vjwnOWiJDq2BTgOjDhh1wKgDRh1AlAOIKdMxyngeSepVRqCK5cMxHqKLZJDlAlaF1HMApHarG0FpANSGozbAZSZWB4AakNR0BKxRSnQaALVeV69ZM3LKgQUDaP8CkAMKoR1FegOQnYVMoC4yqJdK55AA2eUIshsgwAAogFP6tsoybwAAAABJRU5ErkJggg==
  6. // @include https://imgbox.com/
  7. // @include https://imgbox.com/upload/edit/*
  8. // @include https://imgbox.com/gallery/edit/*
  9. // @require https://code.jquery.com/jquery-3.5.1.min.js
  10. // @version 1.0
  11. // @grant none
  12. // ==/UserScript==
  13. /*
  14. //==============================================================================
  15. // Version History:
  16. //==============================================================================
  17.  
  18. 1.0 - New feature: Working Copy buttons.
  19. Added an icon for the script.
  20.  
  21. 0.0.4 - Disabled centering for BBCode boxes (can be enabled with a variable below).
  22.  
  23. 0.0.3 - Fixed: the script wasn't working with the current imgbox.
  24.  
  25. 0.0.2 - Last version from SMz before his disappearance.
  26.  
  27. */
  28.  
  29. // Change this to true to enable [center] BBCode:
  30. const enable_center = false;
  31.  
  32. 'use strict';
  33. this.$ = this.jQuery = jQuery.noConflict(true);
  34.  
  35. /**
  36. * Sets array elements into placeholders of a pattern.
  37. * @param {string} Base pattern. Placeholders as {%i} for the i-th replacement
  38. * array.
  39. * @param {...string[]} Replacement sources for the pattern. The first array
  40. * will set the returned array length.
  41. * @return {string[]} Replaced pattern elements.
  42. */
  43. function createPatternedArray() {
  44. var pattern = arguments[0];
  45. var modArray = [];
  46. for (var i = 0; i < arguments[1].length; i++) {
  47. modArray[i] = pattern;
  48. }
  49. for (var j = 1; j < arguments.length; j++) {
  50. for (var k = 0; k < modArray.length; k++) {
  51. var replacement = arguments[j][k] || '';
  52. modArray[k] = modArray[k].split('{%' + j + '}').join(replacement);
  53. }
  54. }
  55. return modArray;
  56. }
  57.  
  58.  
  59. function copyInfoToClipboard(collect) {
  60. document.body.insertBefore(collect,document.body.firstChild);
  61. collect.focus();
  62. collect.select();
  63. const x = document.execCommand('copy');
  64. document.body.removeChild(collect);
  65. }
  66.  
  67.  
  68. $(document).ready(function() {
  69. // Index page
  70. if ($('#upload-form').length === 1) {
  71. // Set defaults to enable 1-click upload
  72. $('#dropdown-content-type').val('2');
  73. $('#thumbnail-option').val('250r');
  74. $('#comments-option').val('0');
  75. $('#gallery-option').val('3');
  76. }
  77.  
  78. // Upload result
  79. if ($('#codes-full').length === 1) {
  80. // Display all available outputs
  81. $('#codes-full').show().css('visibility', 'visible')
  82. .insertBefore('#codes-thumb');
  83. $('#codes-thumb').show().css('visibility', 'visible');
  84.  
  85. // Extract direct links to full images and thumbs
  86. var links = [];
  87. $($('#code-html-full').text()).find('img').each(function() {
  88. links.push($(this).attr('src'));
  89. });
  90.  
  91. var thumbs = [];
  92. $($('#code-html-thumb').text()).find('img').each(function() {
  93. thumbs.push($(this).attr('src'));
  94. });
  95.  
  96. // Modify the existing outputs and titles, display all options
  97. $('#code-link-full')
  98. .text(links.join('\n'))
  99. .prev('div').children('span').text('Full size plain');
  100. $('#code-html-full')
  101. .text('<center>' +
  102. createPatternedArray('<img src="{%1}">', links).join('\n\n') +
  103. '</center>')
  104. .prev('div').children('span').text('Full size HTML');
  105.  
  106. if(enable_center == true){
  107. $('#code-bb-full')
  108. .text('[center]' +
  109. createPatternedArray('[img]{%1}[/img]', links).join('\n\n') +
  110. '[/center]')
  111. .prev('div').children('span').text('Full size BBCode');
  112. } else {
  113. $('#code-bb-full')
  114. .text(createPatternedArray('[img]{%1}[/img]', links).join('\n\n'))
  115. .prev('div').children('span').text('Full size BBCode');
  116. }
  117.  
  118. $('#code-link-thumb')
  119. .text(thumbs.join('\n'))
  120. .prev('div').children('span').text('Thumbs plain');
  121. $('#code-html-thumb')
  122. .text('<center>' +
  123. createPatternedArray('<a href="{%1}" target="imgbox-full-size">' +
  124. '<img src="{%2}"></a>', links, thumbs).join('\n\n') +
  125. '</center>')
  126. .prev('div').children('span').text('Linked thumbs HTML');
  127.  
  128. if(enable_center == true){
  129. $('#code-bb-thumb')
  130. .text('[center]' +
  131. createPatternedArray('[url={%1}][img]{%2}[/img][/url]', links, thumbs)
  132. .join('\n\n') +
  133. '[/center]')
  134. .prev('div').children('span').text('Linked thumbs BBCode');
  135. } else {
  136. $('#code-bb-thumb')
  137. .text(createPatternedArray('[url={%1}][img]{%2}[/img][/url]', links, thumbs)
  138. .join('\n\n'))
  139. .prev('div').children('span').text('Linked thumbs BBCode');
  140. }
  141.  
  142. // Preparing copy buttons
  143. let buttons = $('.clipboard-button');
  144.  
  145. if (buttons.length > 2) {
  146. buttons.each(function() {
  147. let elem = $(this);
  148. elem.off("click");
  149. const collect_id = elem.attr("data-clipboard-target");
  150. const collect_txt = $('#' +collect_id).text();
  151.  
  152. let collect = document.createElement("textarea");
  153. collect.innerHTML+=collect_txt;
  154. elem.click(function() {
  155. copyInfoToClipboard(collect);
  156. });
  157. });
  158. }
  159. }
  160. });