-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auto Load Big Image.user.js
349 lines (320 loc) · 10.3 KB
/
Auto Load Big Image.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
// ==UserScript==
// @name Auto Load Big Image
// @version 1.6
// @description Auto expand image width height quality for image urls with custom sizes.
// @author navchandar
// @match http*://*/*
// @exclude http*:*guim.co*/*
// @grant none
// @license MPL-2.0
// @run-at document-start
// @homepage https://navchandar.github.io/
// @homepage https://github.com/navchandar/
// @homepageURL https://navchandar.github.io/
// @contributionURL https://paypal.me/navchandar
// @contributionAmount $1.00
// @copyright 2019, navchandar (https://github.com/navchandar)
// @supportURL https://openuserjs.org/scripts/navchandar/Auto_Load_Big_Image/issues
// @setupURL https://openuserjs.org/install/navchandar/Auto_Load_Big_Image.user.js
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO3gAAAABJRU5ErkJggg==
// @namespace https://greasyfork.org/users/302262
// ==/UserScript==
function isNum(num) {
return !isNaN(num)
}
function getNum(text) {
return parseInt(text.replace(/[^0-9\.]/g, ''), 10);
}
function Load(uri) {
window.location.href = uri
}
function has(String, search) {
try {
if (String.indexOf(search) > -1) {
return true;
}
}
catch (err) {}
return false;
}
function getRegexMatch(String, regex) {
var finalText = "";
try {
var arr = String.match(regex);
if (arr != null && arr.length >= 1) {
finalText = arr[0];
}
}
catch (err) {}
return finalText;
}
function widthUpdate(uri, w) {
if (has(uri, w)) {
var res = uri.split(w);
if (res.length == 2) {
if (res[1] != "10000" && isNum(res[1])) {
var newuri = res[0] + w + "10000";
Load(newuri);
}
}
}
}
function sizeUpdate(uri, w) {
if (has(uri, w)) {
var res = uri.split(w);
if (res.length == 2) {
var end = "";
var width = "";
if (has(res[1], "&")) {
var arr = res[1].split("&");
for (var i = 1; i < arr.length; i++) {
end += "&" + arr[i];
}
width = arr[0]
}
else {
width = res[1]
}
if (width != "6000" && isNum(width)) {
var newuri = res[0] + w + "6000" + end;
Load(newuri);
}
}
}
}
function WidthandHeightUpdate(uri, format, width, height) {
if (has(uri, format) && has(uri, width) && has(uri, height)) {
var res1 = uri.split(width);
if (res1.length == 2) {
var res2 = res1[1].split(height);
if (res2.length == 2) {
if (res2[0] != "6000" && isNum(res2[0]) && isNum(res2[1])) {
var w = getNum(res2[0]);
var h = getNum(res2[1]);
var newh = parseInt((h / w) * 6000);
var newuri = res1[0] + width + "6000" + height + newh;
Load(newuri);
}
else {
if (res2[0] != "6000" && has(res2[1], "&") && (has(res2[1], "quality=") || has(res2[1], "q="))) {
var qual = "";
if (has(res2[1], "quality=")) {
qual = "&quality=";
}
if (has(res2[1], "q=")) {
qual = "&q=";
}
var res3 = res2[1].split(qual);
if (res3.length >= 2 && isNum(res2[0]) && isNum(res3[0]) && isNum(res3[1])) {
w = getNum(res2[0]);
h = getNum(res3[0]);
newh = parseInt((h / w) * 6000);
newuri = res1[0] + width + "6000" + height + newh + qual + "100";
Load(newuri);
}
}
}
}
}
}
}
function HeightandWidthUpdate(uri, format, height, width) {
if (has(uri, format) && has(uri, width) && has(uri, height)) {
var res1 = uri.split(height);
if (res1.length == 2) {
var res2 = res1[1].split(width);
if (res2.length >= 2) {
var end = "";
var w = "";
var h = res2[0];
if (has(res2[1], "&")) {
var arr = res2[1].split("&");
for (var i = 1; i < arr.length; i++) {
end += "&" + arr[i];
}
w = arr[0]
}
else {
w = res2[1]
}
if (w != "6000" && isNum(w) && isNum(h)) {
var w1 = getNum(w);
var h1 = getNum(h);
var newh = parseInt((h1 / w1) * 6000);
var newuri = res1[0] + height + newh + width + "6000" + end;
Load(newuri);
}
}
}
}
}
function QualityUpdate(uri, format, start, end) {
if (has(uri, format) && has(uri, start) && has(uri, end)) {
var res1 = uri.split(start);
if (res1.length >= 2 && has(res1[1], end)) {
var res2 = res1[1].split(end);
if (res2.length > 0 && res2[0] != 100 && isNum(res2[0])) {
var newuri = uri.replace((start + res2[0] + end), (start + "100" + end));
Load(newuri);
}
}
}
}
function ReplaceCustomCrop(uri, format, regex, replacement) {
if (has(uri, format)) {
try {
if (regex.test(uri)) {
var newuri = uri.replace(regex, replacement);
Load(newuri);
}
}
catch (err) {}
}
}
function UpdateCustomWidthandHeight(uri, format, regex) {
if (has(uri, format)) {
try {
if (regex.test(uri)) {
var res = getRegexMatch(uri, regex);
var rep = res.replace("/", "");
rep = rep.replace("/", "");
if (has(rep, "x") && has(rep, ",")) {
var res1 = rep.split("x");
var res2 = res1[1].split(",");
if (res1[0] != "6000" && res2.length >= 2 && isNum(res1[0]) && isNum(res2[0]) && isNum(res2[1])) {
var w = getNum(res1[0]);
var h = getNum(res2[0]);
var newh = parseInt((h / w) * 6000);
var replacement = "/" + 6000 + "x" + newh + ",100" + "/";
var newuri = uri.replace(res, replacement);
Load(newuri);
}
}
}
}
catch (err) {}
}
}
function CustomWidthandHeightUpdate(uri, width, height) {
if (has(uri, width) && has(uri, height)) {
var res1 = uri.split(width);
var res2 = res1[1].split(height);
if (isNum(res2[0]) && res2[0] != "6000") {
var w = getNum(res2[0]);
var h = getNum(res2[1].split("-")[0]);
var res = width + w + height + h;
var newh = parseInt((h / w) * 6000);
var replacement = width + 6000 + height + newh;
var newuri = uri.replace(res, replacement);
if (uri != newuri) {
Load(newuri);
}
}
}
}
function DPRUpdate(uri, d) {
if (has(uri, d)) {
var res = uri.split(d);
if (isNum(res[1]) && res[1] < 3) {
var newuri = res[0] + d + "3";
Load(newuri);
}
else if (!isNum(res[1]) && has(res[1], "&")) {
var res2 = res[1].split("&")[0];
if (isNum(res2) && res2 < 3) {
newuri = uri.replace((d + res2), (d + "3"));
Load(newuri);
}
}
}
}
function main(uri, format) {
if (has(uri, "image/upload/")) {
ReplaceCustomCrop(uri, "." + format, /q\_auto\//g, "q_auto:best/");
ReplaceCustomCrop(uri, "." + format, /f\_auto\,|fl\_lossy\,|c\_limit\,/g, "");
ReplaceCustomCrop(uri, "." + format, /upload\/[hw]\_\d+\,[hw]\_\d+\//g, "upload/");
}
if (has(uri, "wiki")) {
ReplaceCustomCrop(uri, ".svg", /thumb\/|\/\d+px[-]?\w+(.)*.svg(.)*/g, "");
ReplaceCustomCrop(uri, ".jpg", /thumb\/|\/\d+px[-]?\w+(.)*.jpg(.)*/g, "");
ReplaceCustomCrop(uri, ".png", /thumb\/|\/\d+px[-]?\w+(.)*.png(.)*/g, "");
ReplaceCustomCrop(uri, "." + format, /\/zoom\-crop\/(.)*/g, "");
}
if (has(uri, "blogspot") && !has(uri, "/s6000/")) {
ReplaceCustomCrop(uri, "." + format, /\/s\d+\//g, "/s6000/");
}
if (has(uri, "twimg") && !has(uri, "video")) {
ReplaceCustomCrop(uri, format, /\_normal\./g, ".");
if (has(uri, "name")) {
ReplaceCustomCrop(uri, format, /\?format\=jpg\&name\=(.)*/g, "?format=png&name=large");
ReplaceCustomCrop(uri, format, /\?format\=png\&name\=[^(large)(4)](.*)/g, "?format=png&name=large");
ReplaceCustomCrop(uri, format, /\?format\=png\&name\=medium/g, "?format=png&name=large");
}
else if (has(uri, "format")) {
ReplaceCustomCrop(uri, format, /\?format\=jp(.)*/g, "?format=png");
}
}
if (has(uri, "usercontent")) {
CustomWidthandHeightUpdate(uri, "=w", "-h");
ReplaceCustomCrop(uri, format, /\?s\=\d+\&v\=\d+/g, "");
}
widthUpdate(uri, "." + format + "?w=");
widthUpdate(uri, "." + format + "?width=");
WidthandHeightUpdate(uri, "." + format + "?", "w=", "&h=");
WidthandHeightUpdate(uri, "." + format + "?", "width=", "&height=");
HeightandWidthUpdate(uri, "." + format + "?", "h=", "&w=");
HeightandWidthUpdate(uri, "." + format + "?", "height=", "&width=");
// Remove crops
ReplaceCustomCrop(uri, "." + format, /\/\d+\,\d+\,\d+\,\d+\//g, "/");
ReplaceCustomCrop(uri, "." + format, /\?crop=\d+\%\d\w\d+\%\d\w\w+\%\w+/g, "");
ReplaceCustomCrop(uri, "." + format, /\?crop=\d+\%3A\d+|\?crop=\d+\:\d+/g, "");
ReplaceCustomCrop(uri, "." + format, /thumbor\/\d+x\d+\//g, "thumbor/origxorig/");
if (!has(uri, "%2F2000")) {
ReplaceCustomCrop(uri, "." + format, /\%2F\d+x0.jpg/g, "%2F2000x0.jpg");
}
if (!has(uri, "/2000")) {
ReplaceCustomCrop(uri, "." + format, /\/\d+x0.jpg/g, "/2000x0.jpg");
}
// Remove Blur and bring original
if (has(uri, '.it/') && has(uri, 'blur') && !has(uri, 'external-preview.')) {
if (has(uri, '?blur')) {
ReplaceCustomCrop(uri, format, /\?blur\=(.)*/g, "");
}
else if (has(uri, '?width=')) {
ReplaceCustomCrop(uri, format, /\?width\=(.)*/g, "");
}
if (has(uri, 'preview.')) {
ReplaceCustomCrop(uri, format, /preview/, "i");
}
}
// Remove watermark
ReplaceCustomCrop(uri, format, /\&mark64\=(.)*/g, "");
// Auto Enhance
ReplaceCustomCrop(uri, format, /auto\=compress/g, "auto=enhance");
ReplaceCustomCrop(uri, format, /\&cs\=tinysrgb/g, "");
UpdateCustomWidthandHeight(uri, "." + format, /\/\d+\x\d+\,\d+\//g);
QualityUpdate(uri, "." + format, "/q_", "/");
QualityUpdate(uri, "." + format, "/x,", "/");
QualityUpdate(uri, format, "&q=", "&");
sizeUpdate(uri, "." + format + "?size=");
DPRUpdate(uri, "&dpr=");
}
(function () {
'use strict';
var uri = window.location.href;
if (has(uri, "jpg")) {
main(uri, "jpg");
}
else if (has(uri, "png")) {
main(uri, "png");
}
else if (has(uri, "jpeg")) {
main(uri, "jpeg");
}
else if (has(uri, "webp")) {
main(uri, "webp");
}
else if (has(uri, "usercontent.com")) {
main(uri, "usercontent");
}
})();