-
Notifications
You must be signed in to change notification settings - Fork 1
/
gpi_v2.js
executable file
·330 lines (277 loc) · 11.6 KB
/
gpi_v2.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
// ----------------------------------------------------------------------------------------
// Timings and classname for panic button
// ----------------------------------------------------------------------------------------
// Seconds, when the script should scan the search page for new images
const SECONDS_TO_FIRE = 1.25;
const SECONDS_TO_FIRE_CUT = SECONDS_TO_FIRE * 0.35;
// Our panic class (buttons)
const GOOGLE_PANIC_CLASS = 'Google-panic-image-btn-new';
// ----------------------------------------------------------------------------------------
// Global variables
// ----------------------------------------------------------------------------------------
let fireAt = 0;
// ----------------------------------------------------------------------------------------
// RegExParsers
const imgRegExBase = /\[,(http[s]{0,1}(%3a|:).[^\&]*\.(jpg|jpeg|gif|png|webm|svg|tiff|webp|avif))/i;
// Gathers all images and adds a "VIEW" link to the direct picture url
function rewampImgs () {
try {
const imgLinks = document.querySelectorAll('div.isv-r');
let isFacebook = false;
let pageLoad = '';
pageLoad = document.children[0].outerHTML.replace(/[\n\t\r]{1,}/g, '');
for (const img of imgLinks) {
if (hasControls(img)) continue;
isFacebook = false;
const imageID = img.dataset.id;
try {
const imgData = pageLoad.match(new RegExp('[0-9]?,"' + imageID + '",.*\],'))[0].split('"', 6);
imgData.splice(0, imgData.length - 3);
img.dataset.irul = imgData;
} catch (err) {
continue;
}
let imgURL = imgRegExBase1.exec(img.children[0].href);
if (imgURL === null) {
imgURL = imgFacebook.exec(img.dataset.irul);
if (imgURL !== null) isFacebook = true;
}
if (!isFacebook) {
if (imgURL === '' || imgURL === null) imgURL = imgRegExBase1.exec(img.dataset.irul);
if (imgURL === '' || imgURL === null) imgURL = imgRegExBase2.exec(img.children[0].href);
if (imgURL === null) imgURL = imgRegExBase2.exec(img.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
if (imgURL === null) imgURL = imgRegExBaseNoImage3.exec(img.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
if (imgURL === null) imgURL = imgRegExBaseNoImage2.exec(img.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
if (imgURL === null) {
if (imgURL === null) imgURL = imgRegExBaseNoImage1.exec(img.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
if (imgURL === null) imgURL = imgRegExBase.exec(img.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
if (imgURL === null) {
imgURL = imgRegExBaseNoImage.exec(img.dataset.irul);
if (imgURL === null) {
img.style.border = '6px solid #000';
continue;
}
}
}
}
imgURL = imgURL[1];
console.log('imgURL', imgURL);
try {
for (const entry of imgURL.match(/[\\]{1,}u[a-fA-F0-9]{0,4}/gi)) imgURL = imgURL.replace(entry, String.fromCharCode(parseInt(entry.replace(/\\u/gi, ''), 16)));
} catch (err) {
if (imgURL.indexOf(')') !== -1) {
const imgData = img.dataset.irul.split('/');
imgURL = 'https://' + decodeURIComponent(imgData[imgData.length - 1]);
} else {
imgURL = decodeURIComponent(imgURL);
}
}
const domButton = document.createElement('a');
domButton.target = '_blank';
domButton.href = imgURL;
domButton.role = 'button';
domButton.className = GOOGLE_PANIC_CLASS;
domButton.appendChild(document.createTextNode('VIEW'));
domButton.style.visibility = 'hidden';
domButton.style.position = 'absolute';
domButton.style.top = '10%';
domButton.style.left = '0px';
domButton.style.background = 'rgba(0,0,0,0.6)';
domButton.style.color = '#fff';
domButton.style['font-weight'] = 'bold';
domButton.style.padding = '0.5em 1.5em';
domButton.style['border-radius'] = '0px 12px 12px 0px';
domButton.style['z-index'] = '1';
domButton.style['font-size'] = '12px';
domButton.style['text-decoration'] = 'none';
domButton.style.border = '1px solid #aaa';
domButton.style['border-left'] = 'none';
img.appendChild(domButton);
img.removeEventListener('mouseenter', overlayControls);
img.removeEventListener('mousemove', overlayControls);
img.removeEventListener('mouseleave', hideControls);
img.addEventListener('mouseenter', overlayControls);
img.addEventListener('mousemove', overlayControls);
img.addEventListener('mouseleave', hideControls);
}
for (const btn of document.querySelectorAll('a.' + GOOGLE_PANIC_CLASS)) {
btn.removeEventListener('click', openImgLink);
btn.addEventListener('click', openImgLink);
}
} catch (err) {
console.log(err);
}
}
function openImgLink (evt) {
evt.preventDefault();
window.open(evt.target.href, '_blank');
}
function readURLforImg (imgLink) {
try {
let imgSrc = null;
imgLink.dataset.irul = imgLink.href;
for (const child of imgLink.childNodes) {
if (child.getAttribute('src') !== null) {
imgSrc = child.getAttribute('src');
break;
}
}
let isFacebook = false;
let imgURL = null;
if (imgSrc !== null) {
imgURL = imgSrc;
} else {
imgURL = imgRegExBase1.exec(imgLink.href);
if (imgURL === null) {
imgURL = imgFacebook.exec(imgLink.dataset.irul);
if (imgURL !== null) isFacebook = true;
}
if (!isFacebook) {
if (imgURL === '' || imgURL === null) imgURL = imgRegExBase1.exec(imgLink.dataset.irul);
if (imgURL === '' || imgURL === null) imgURL = imgRegExBase2.exec(imgLink.parentNode.children[0].href);
if (imgURL === null) imgURL = imgRegExBase2.exec(imgLink.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
if (imgURL === null) imgURL = imgRegExBaseNoImage3.exec(imgLink.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
if (imgURL === null) imgURL = imgRegExBaseNoImage2.exec(imgLink.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
if (imgURL === null) {
if (imgURL === null) imgURL = imgRegExBaseNoImage1.exec(imgLink.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
if (imgURL === null) imgURL = imgRegExBase.exec(imgLink.dataset.irul);
if (imgURL !== null && imgURL[1].startsWith('https://encrypted-tbn0.gstatic.com/images')) imgURL = null;
}
}
if (imgURL === null) return;
imgURL = imgURL[1];
}
if (imgURL.indexOf(')') !== -1) {
const imgData = imgLink.dataset.irul.split('/');
imgURL = 'https://' + decodeURIComponent(imgData[imgData.length - 1]);
} else imgURL = decodeURIComponent(imgURL);
const domButton = document.createElement('a');
domButton.target = '_blank';
domButton.href = imgURL;
domButton.role = 'button';
domButton.className = GOOGLE_PANIC_CLASS;
domButton.appendChild(document.createTextNode('VIEW'));
domButton.style.visibility = 'hidden';
domButton.style.position = 'absolute';
domButton.style.top = '10%';
domButton.style.left = '0px';
domButton.style.background = 'rgba(0,0,0,0.6)';
domButton.style.color = '#fff';
domButton.style['font-weight'] = 'bold';
if (imgSrc === null) domButton.style.padding = '0.65em 2em';
else domButton.style.padding = '1.25em 2em';
domButton.style['border-radius'] = '0px 12px 12px 0px';
domButton.style['z-index'] = '1';
domButton.style['font-size'] = '12px';
domButton.style['text-decoration'] = 'none';
domButton.style.border = '1px solid #aaa';
domButton.style['border-left'] = 'none';
imgLink.parentNode.appendChild(domButton);
for (const btn of document.querySelectorAll('a.' + GOOGLE_PANIC_CLASS)) {
btn.removeEventListener('click', openImgLink);
btn.addEventListener('click', openImgLink);
}
imgLink.parentNode.removeEventListener('mouseenter', overlayControls);
imgLink.parentNode.removeEventListener('mousemove', overlayControls);
imgLink.parentNode.removeEventListener('mouseleave', hideControls);
imgLink.parentNode.addEventListener('mouseenter', overlayControls);
imgLink.parentNode.addEventListener('mousemove', overlayControls);
imgLink.parentNode.addEventListener('mouseleave', hideControls);
imgLink.parentNode.dispatchEvent(new window.MouseEvent('mouseenter', { target: imgLink.parentNode }));
} catch (err) {
console.log(err);
}
}
function hasControls (parentNode) {
try {
const childNodeCount = parentNode.childNodes.length;
const nodes = parentNode.childNodes;
for (let x = childNodeCount - 1; x >= 0; --x) {
if (nodes[x].className === GOOGLE_PANIC_CLASS) {
return true;
}
}
return false;
} catch (err) {
console.log(err);
return false;
}
}
// ----------------------------------------------------------------------------------------
// Reschedule a parsing
function resetFire () {
fireAt = Date.now() + (SECONDS_TO_FIRE_CUT * 1000);
}
// ----------------------------------------------------------------------------------------
// Function which does schedule the processing
function waitForLoaded () {
if (Date.now() > fireAt) {
try {
rewampImgs();
} catch (err) {
console.log('[ERROR] in script, function rewampImgs():');
console.log(err);
}
try {
rewampImgs2();
} catch (err) {
console.log('[ERROR] in script, function rewampImgs2():');
console.log(err);
}
try {
rewampImgs3();
} catch (err) {
console.log('[ERROR] in script, function rewampImgs3():');
console.log(err);
}
try {
rewampImgs4();
} catch (err) {
console.log('[ERROR] in script, function rewampImgs3():');
console.log(err);
}
try {
const imgs = document.querySelectorAll('div#islsp div.isv-r');
for (const img of imgs) {
img.removeEventListener('click', resetFire);
img.addEventListener('click', resetFire);
}
} catch (err) {
console.log(err);
}
fireAt = Date.now() + (SECONDS_TO_FIRE * 1000);
}
window.requestAnimationFrame(waitForLoaded);
}
// ----------------------------------------------------------------------------------------
// Display the controls, when the mouse is hovered over the image
function overlayControls (event) {
const img = event.target;
for (const child of img.childNodes) {
if (child.className === GOOGLE_PANIC_CLASS) {
child.style.visibility = 'visible';
break;
}
}
}
// Hide the controls, if the mouse is moved out of the image
function hideControls (event) {
const img = event.target;
for (const child of img.childNodes) {
if (child.className === GOOGLE_PANIC_CLASS) {
child.style.visibility = 'hidden';
break;
}
}
}
// ----------------------------------------------------------------------------------------
window.requestAnimationFrame(waitForLoaded);