-
Notifications
You must be signed in to change notification settings - Fork 0
/
Imgbox_Tweaker.user.js
411 lines (365 loc) · 18 KB
/
Imgbox_Tweaker.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
// ==UserScript==
//
// @name Imgbox Tweaker
// @version 2.1
// @namespace https://github.com/Purfview/Imgbox-Tweaker
// @description Adds custom formatted links, working Copy to clipboard buttons, menu pre-select for 1-click uploading, links centering.
// @icon data:image/png;base64,iVB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D1rInSLAewClsM7kUKtB04DCDIa+AHNRkh1N4J0vK5YpCloY0bFKvivPcKtsUtwmL+94Sb0SQW2ZR2F+1WEZt++oXgMMbvQMwQhjTdD4LvT3sxPa4Lii3m9oNGMWPpoVLO/N9iwbrltuH4A8i6EyMTC8cWfoV/qSB6ELolJyse6+ttGcJQoht2MKzvQ1Wo9vpwWw2Ypuek6DpsDW5S4e/2fIeVmHcisShkcD6HALFhnVonN0Vh3u1PszNGkSDBKYJ8xBGxEEU5l2HEBcsg/lRyUTjBizAAI37bCGBj0YeFiKHy2FBtOlJ+Nf8BCbnsb61BX21AAAAAElFTkSuQmCC
// @license MIT
//
// @updateURL https://greasyfork.org/scripts/454582-imgbox-tweaker/code/Imgbox%20Tweaker.meta.js
// @downloadURL https://greasyfork.org/scripts/454582-imgbox-tweaker/code/Imgbox%20Tweaker.user.js
// @homepage https://github.com/Purfview/Imgbox-Tweaker
// @supportURL https://github.com/Purfview/Imgbox-Tweaker/issues
//
// @compatible firefox
// @compatible opera
// @compatible chrome
// @compatible safari
// @compatible edge
//
// @require https://code.jquery.com/jquery-3.5.1.min.js
// @require https://cdn.jsdelivr.net/gh/sizzlemctwizzle/GM_config@43fd0fe4de1166f343883511e53546e87840aeaf/gm_config.js
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
//
// @include https://imgbox.com/
// @include https://imgbox.com/upload/edit/*
// @include https://imgbox.com/gallery/edit/*
//
// @grant GM_registerMenuCommand
// @grant GM.registerMenuCommand
//
// @run-at document-start
//
// ==/UserScript==
/*
//==============================================================================
// Version History:
//==============================================================================
2.1 - New feature: Works when logged in.
2.0 - Major script rewrite.
Namespace change.
New feature: Settings menu.
New feature: Pre-select menu for 1-click uploading.
New feature: After upload auto-load into 'edit' page to get Copy buttons.
New feature: All Copy buttons are working.
New feature: Fully working centering option.
New feature: Support for classic Greasemonkey.
1.1 - Fixed: The script was breaking the upload page.
1.0 - New feature: Working Copy buttons.
Added an icon for the script.
0.0.4 - Disabled centering for BBCode boxes (can be enabled with a variable below).
0.0.3 - Fixed: the script wasn't working with the current imgbox.
0.0.2 - Last version from SMz before his disappearance.
*/
//==============================================================================
/**
* Sets array elements into placeholders of a pattern.
* @param {string} Base pattern. Placeholders as {%i} for the i-th replacement
* array.
* @param {...string[]} Replacement sources for the pattern. The first array
* will set the returned array length.
* @return {string[]} Replaced pattern elements.
*/
function createPatternedArray() {
var pattern = arguments[0];
var modArray = [];
for (var i = 0; i < arguments[1].length; i++) {
modArray[i] = pattern;
}
for (var j = 1; j < arguments.length; j++) {
for (var k = 0; k < modArray.length; k++) {
var replacement = arguments[j][k] || '';
modArray[k] = modArray[k].split('{%' + j + '}').join(replacement);
}
}
return modArray;
}
function copyInfoToClipboard(collect) {
document.body.insertBefore(collect,document.body.firstChild);
collect.focus();
collect.select();
const x = document.execCommand('copy');
document.body.removeChild(collect);
}
function startObserver() {
const obscfg = { attributes: true };
const obs = new MutationObserver(preselectMenus);
obs.observe($('#upload-form')[0], obscfg);
}
function preselectMenus(mutation, observer) {
observer.disconnect();
console.log("Imgbox Tweaker: '#upload-form' mutation detected. Starting preselectMenus().");
// Content preselect
let content_index;
const content_val = GM_config.get('menu_content');
if (content_val === 'Family Safe Content' ) { content_index = 1;
} else if (content_val === 'Adult Content') { content_index = 2;
} else { content_index = 0;
}
$('#dropdown-content-type').find('option[selected="selected"]').removeAttr("selected");
$('#dropdown-content-type option:eq('+content_index+')').attr('selected', "selected");
$('button[data-id="dropdown-content-type"]>.filter-option').text(content_val);
$('.dropdown-menu.inner.selectpicker:eq(0)').find('li').removeAttr('class');
$('.dropdown-menu.inner.selectpicker:eq(0)').find('li:eq('+content_index+')').addClass("selected");
// Thumbnail preselect
let thumb_index;
const thumb_val = GM_config.get('menu_thumb');
if (thumb_val.match('100x100 pixel \\(square\\)' )) { thumb_index = 0;
} else if (thumb_val.match('150x150 pixel \\(square\\)' )) { thumb_index = 1;
} else if (thumb_val.match('200x200 pixel \\(square\\)' )) { thumb_index = 2;
} else if (thumb_val.match('250x250 pixel \\(square\\)' )) { thumb_index = 3;
} else if (thumb_val.match('300x300 pixel \\(square\\)' )) { thumb_index = 4;
} else if (thumb_val.match('350x350 pixel \\(square\\)' )) { thumb_index = 5;
} else if (thumb_val.match('500x500 pixel \\(square\\)' )) { thumb_index = 6;
} else if (thumb_val.match('800x800 pixel \\(square\\)' )) { thumb_index = 7;
} else if (thumb_val.match('100x100 pixel \\(resized\\)')) { thumb_index = 8;
} else if (thumb_val.match('150x150 pixel \\(resized\\)')) { thumb_index = 9;
} else if (thumb_val.match('200x200 pixel \\(resized\\)')) { thumb_index = 10;
} else if (thumb_val.match('250x250 pixel \\(resized\\)')) { thumb_index = 11;
} else if (thumb_val.match('300x300 pixel \\(resized\\)')) { thumb_index = 12;
} else if (thumb_val.match('350x350 pixel \\(resized\\)')) { thumb_index = 13;
} else if (thumb_val.match('500x500 pixel \\(resized\\)')) { thumb_index = 14;
} else if (thumb_val.match('800x800 pixel \\(resized\\)')) { thumb_index = 15;
}
$('#thumbnail-option').find('option[selected="selected"]').removeAttr("selected");
$('#thumbnail-option option:eq('+thumb_index+')').attr('selected', "selected");
$('button[data-id="thumbnail-option"]>.filter-option').text(thumb_val);
$('.dropdown-menu.inner.selectpicker:eq(1)').find('li').removeAttr('class');
$('.dropdown-menu.inner.selectpicker:eq(1)').find('li:eq('+thumb_index+')').addClass("selected");
// Comments preselect
let comment_index;
const comment_val = GM_config.get('menu_comment');
if (comment_val === 'Enable Comments') { comment_index = 0;
} else { comment_index = 1;
}
$('#comments-option').find('option[selected="selected"]').removeAttr("selected");
$('#comments-option option:eq('+comment_index+')').attr('selected', "selected");
$('button[data-id="comments-option"]>.filter-option').text(comment_val);
$('.dropdown-menu.inner.selectpicker:eq(2)').find('li').removeAttr('class');
$('.dropdown-menu.inner.selectpicker:eq(2)').find('li:eq('+comment_index+')').addClass("selected");
// Check if logged in [Gallery preselect is not supported there]
if ($('.icon-comments').length) {
console.log("Imgbox Tweaker: Login detected. Skiping 'Gallery preselect'.");
return;
}
// Gallery preselect
let gallery_index;
const gallery_val = GM_config.get('menu_gallery');
if (gallery_val === 'Create a New Gallery') { gallery_index = 0;
} else { gallery_index = 1;
}
$('#gallery-option').find('option[selected="selected"]').removeAttr("selected");
$('#gallery-option option:eq('+gallery_index+')').attr('selected', "selected");
$('button[data-id="gallery-option"]>.filter-option').text(gallery_val);
$('.dropdown-menu.inner.selectpicker:eq(3)').find('li').removeAttr('class');
$('.dropdown-menu.inner.selectpicker:eq(3)').find('li:eq('+gallery_index+')').addClass("selected");
if (gallery_index === 1) {$('.new-gallery-title-input-container').addClass("hidden");}
}
function startImboxTweaker() {
// Upload menu-select page
if (GM_config.get('preselect_menu')) {
if ($('#upload-form').length === 1) {
console.log("Imgbox Tweaker: '#upload-form' detected. Starting MutationObserver.");
startObserver();
}
}
// Upload result page
if ($('#codes-full').length === 1) {
// Check if logged in [there is no Edit page and no Copy butons]
let not_login = true;
if ($('.icon-comments').length) {
not_login = false;
}
// Go to "upload edit" page to see Copy buttons
if (!Boolean(location.href.match('\\/edit\\/')) && not_login) {
console.log("Imgbox Tweaker: Restarting into 'upload edit' page.");
const edithref = $('div.text-right a').text();
window.location.replace(edithref +'?#');
return;
}
console.log("Imgbox Tweaker: Upload result page detected. Starting tweaks.");
// Display all available outputs
$('#codes-full').show().css('visibility', 'visible')
.insertBefore('#codes-thumb');
$('#codes-thumb').show().css('visibility', 'visible');
// Extract direct links to full images and thumbs
var links = [];
$($('#code-html-full').text()).find('img').each(function() {
links.push($(this).attr('src'));
});
var thumbs = [];
$($('#code-html-thumb').text()).find('img').each(function() {
thumbs.push($(this).attr('src'));
});
// Modify the existing outputs and titles, display all options
$('#code-link-full')
.text(links.join('\n'))
.prev('div').children('span').text('Full size plain');
if(GM_config.get('centered_links')){
$('#code-html-full')
.text('<center>' +createPatternedArray('<img src="{%1}">', links).join('\n\n') +'</center>')
.prev('div').children('span').text('Full size HTML');
} else {
$('#code-html-full')
.text(createPatternedArray('<img src="{%1}">', links).join('\n\n'))
.prev('div').children('span').text('Full size HTML');
}
if(GM_config.get('centered_links')){
$('#code-bb-full')
.text('[center]' +createPatternedArray('[img]{%1}[/img]', links).join('\n\n') +'[/center]')
.prev('div').children('span').text('Full size BBCode');
} else {
$('#code-bb-full')
.text(createPatternedArray('[img]{%1}[/img]', links).join('\n\n'))
.prev('div').children('span').text('Full size BBCode');
}
$('#code-link-thumb')
.text(thumbs.join('\n'))
.prev('div').children('span').text('Thumbs plain');
if(GM_config.get('centered_links')){
$('#code-html-thumb')
.text('<center>' +createPatternedArray('<a href="{%1}" target="imgbox-full-size"><img src="{%2}"></a>', links, thumbs).join('\n\n') +'</center>')
.prev('div').children('span').text('Linked thumbs HTML');
} else {
$('#code-html-thumb')
.text(createPatternedArray('<a href="{%1}" target="imgbox-full-size"><img src="{%2}"></a>', links, thumbs).join('\n\n'))
.prev('div').children('span').text('Linked thumbs HTML');
}
if(GM_config.get('centered_links')){
$('#code-bb-thumb')
.text('[center]' +createPatternedArray('[url={%1}][img]{%2}[/img][/url]', links, thumbs).join('\n\n') +'[/center]')
.prev('div').children('span').text('Linked thumbs BBCode');
} else {
$('#code-bb-thumb')
.text(createPatternedArray('[url={%1}][img]{%2}[/img][/url]', links, thumbs).join('\n\n'))
.prev('div').children('span').text('Linked thumbs BBCode');
}
// Fix Copy to clipboard buttons
let buttons = $('.clipboard-button');
if (buttons.length > 2 && not_login) {
buttons.each(function() {
const elem = $(this);
let collect_id, collect_txt;
if (elem.attr("data-clipboard-text")) {
collect_txt = elem.attr("data-clipboard-text")
} else {
collect_id = elem.attr("data-clipboard-target");
collect_txt = $('#' +collect_id).text();
}
let collect = document.createElement("textarea");
collect.innerHTML+=collect_txt;
elem.click(function() {
copyInfoToClipboard(collect);
});
});
}
}
}
//==============================================================================
// Settings Menu (GM_config)
//==============================================================================
var config_fields = {
'aftertitle': {
'section': ' ',
'label': '  ',
'type': 'hidden'
},
'centered_links': {
'type': 'checkbox',
'label': 'Enable centering on links?',
'default': false
},
'preselect_menu': {
'type': 'checkbox',
'label': 'Enable the pre-select menu feature?',
'default': true
},
'menu_content': {
'section': 'Pre-select menu:',
'type': 'select',
'options': ['SELECT CONTENT TYPE', 'Family Safe Content', 'Adult Content'],
'default': 'Family Safe Content'
},
'menu_thumb': {
'type': 'select',
'options': ['100x100 pixel (square)', '150x150 pixel (square)', '200x200 pixel (square)', '250x250 pixel (square)', '300x300 pixel (square)', '350x350 pixel (square)', '500x500 pixel (square)', '800x800 pixel (square)', '100x100 pixel (resized)', '150x150 pixel (resized)', '200x200 pixel (resized)', '250x250 pixel (resized)', '300x300 pixel (resized)', '350x350 pixel (resized)', '500x500 pixel (resized)', '800x800 pixel (resized)'],
'default': '100x100 pixel (resized)'
},
'menu_comment': {
'type': 'select',
'options': ['Enable Comments', 'Disable Comments'],
'default': 'Disable Comments'
},
'menu_gallery': {
'type': 'select',
'options': ['Create a New Gallery', 'Do Not Create a Gallery'],
'default': 'Do Not Create a Gallery'
},
};
//==============================================================================
// Initialize and register GM_config
//==============================================================================
GM_config.init({
'id': 'imgbox_tweaker',
'title': 'Imgbox Tweaker Settings',
'fields': config_fields,
'css': `#imgbox_tweaker_section_header_1 { \
background: #00ab00 !important; \
color: black !important; \
font-weight: bold !important; \
border: 0px !important; \
padding-left: 0px !important; \
text-align: middle !important;}\
.field_label { \
display: flex !important; \
align-items: center !important; \
font-weight: normal !important;}\
.config_var { \
margin-top: 2px !important; \
margin-bottom: 2px !important; \
display: flex !important; \
align-items: center !important;}\
#imgbox_tweaker_aftertitle_var { \
margin-top: 0px !important; \
margin-bottom: 0px !important;}\
input { \
margin-top: 0px !important; \
margin-bottom: 0px !important;}\
.grey_link { \
margin-left: 4px !important;}\
#imgbox_tweaker_section_header_0 { \
font-weight: bold !important; \
border: 0px !important; \
margin-top: 0px !important; \
background: #bfbfbf !important;}\
#imgbox_tweaker_header { \
background: black !important; \
color: white !important;}\
#imgbox_tweaker_section_0 { \
margin-top: 0px !important;}`,
'events':
{
'open': function() {
// Iframe position.
this.frame.style.top = '50px';
this.frame.style.left = 'auto';
this.frame.style.right = '150px';
this.frame.style.height = '50%';
this.frame.style.width = '450px';
$('#imgbox_tweaker').contents().find('input#imgbox_tweaker_field_ignore_list').attr('size', '47');
const modVersion = 'Imgbox Tweaker v' + GM.info.script.version;
const modUrl = 'https://greasyfork.org/en/scripts/454582-imgbox-tweaker';
$('#imgbox_tweaker').contents().find('#imgbox_tweaker_section_header_0').append($('<a href="'+modUrl+'" target ="_blank">'+modVersion+'</a>'));
$('#imgbox_tweaker').contents().find('#imgbox_tweaker_section_header_0').find('a').css({
'text-decoration': 'none',
'color': '#cb0000'
});
},
'close': function() {
location.reload();
}
}
});
GM.registerMenuCommand('Imgbox Tweaker Settings', function() {GM_config.open();});
window.addEventListener('DOMContentLoaded', startImboxTweaker);