imgbox tweaker

Adds custom formatted links and other minor tweaks.

  1. // ==UserScript==
  2. // @name imgbox tweaker
  3. // @namespace surrealmoviez.info
  4. // @description Adds custom formatted links and other minor tweaks.
  5. // @include https://imgbox.com/
  6. // @include https://imgbox.com/upload/edit/*
  7. // @include https://imgbox.com/gallery/edit/*
  8. // @require https://code.jquery.com/jquery-2.1.4.min.js
  9. // @version 0.0.2
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. 'use strict';
  14. this.$ = this.jQuery = jQuery.noConflict(true);
  15.  
  16. /**
  17. * Sets array elements into placeholders of a pattern.
  18. * @param {string} Base pattern. Placeholders as {%i} for the i-th replacement
  19. * array.
  20. * @param {...string[]} Replacement sources for the pattern. The first array
  21. * will set the returned array length.
  22. * @return {string[]} Replaced pattern elements.
  23. */
  24. function createPatternedArray() {
  25. var pattern = arguments[0];
  26. var modArray = [];
  27. for (var i = 0; i < arguments[1].length; i++) {
  28. modArray[i] = pattern;
  29. }
  30. for (var j = 1; j < arguments.length; j++) {
  31. for (var k = 0; k < modArray.length; k++) {
  32. var replacement = arguments[j][k] || '';
  33. modArray[k] = modArray[k].split('{%' + j + '}').join(replacement);
  34. }
  35. }
  36. return modArray;
  37. }
  38.  
  39. $(document).ready(function() {
  40. // Index page
  41. if ($('#upload-form').length === 1) {
  42. // Set defaults to enable 1-click upload
  43. $('#dropdown-content-type').val('2');
  44. $('#thumbnail-option').val('250r');
  45. $('#comments-option').val('0');
  46. $('#gallery-option').val('3');
  47. }
  48.  
  49. // Upload result
  50. if ($('#codes-full').length === 1) {
  51. // Display all available outputs
  52. $('#codes-full').show().css('visibility', 'visible')
  53. .insertBefore('#codes-thumb');
  54. $('#codes-thumb').show().css('visibility', 'visible');
  55.  
  56. // Extract direct links to full images and thumbs
  57. var links = $('#code-link-full').text().trim().split('\n');
  58. var thumbs = [];
  59. $($('#code-html-thumb').text()).find('img').each(function() {
  60. thumbs.push($(this).attr('src'));
  61. });
  62.  
  63. // Modify the existing outputs and titles, display all options
  64. $('#codes-full > .span4:eq(0) span').text('Full size plain');
  65. $('#code-html-full')
  66. .text('<center>' +
  67. createPatternedArray('<img src="{%1}">', links).join('\n\n') +
  68. '</center>')
  69. .prev('div').children('span').text('Full size HTML');
  70. $('#code-bb-full')
  71. .text('[center]' +
  72. createPatternedArray('[img]{%1}[/img]', links).join('\n\n') +
  73. '[/center]')
  74. .prev('div').children('span').text('Full size BBCode');
  75. $('#code-link-thumb')
  76. .text(thumbs.join('\n'))
  77. .prev('div').children('span').text('Thumbs plain');
  78. $('#code-html-thumb')
  79. .text('<center>' +
  80. createPatternedArray('<a href="{%1}" target="imgbox-full-size">' +
  81. '<img src="{%2}"></a>', links, thumbs).join('\n\n') +
  82. '</center>')
  83. .prev('div').children('span').text('Linked thumbs HTML');
  84. $('#code-bb-thumb')
  85. .text('[center]' +
  86. createPatternedArray('[url={%1}][img]{%2}[/img][/url]', links, thumbs)
  87. .join('\n\n') +
  88. '[/center]')
  89. .prev('div').children('span').text('Linked thumbs BBCode');
  90. }
  91. });