forked from yanorei32/GSI4D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogleunlocker.js
147 lines (129 loc) · 5.5 KB
/
googleunlocker.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
// ==UserScript==
// @name Google Unlocked
// @version 1.6
// @namespace 45c9a6614fccd4edff9592da
// @description Google Unlocked scans hidden search results that were censored by Google due to complaints
// @home https://github.com/Ibit-to/google-unlocked
// @supportURL https://github.com/Ibit-to/google-unlocked/issues
// @updateURL https://raw.githubusercontent.com/Ibit-to/google-unlocked/master/google-unlocked.user.js
// @downloadURL https://raw.githubusercontent.com/Ibit-to/google-unlocked/master/google-unlocked.user.js
// @author Ibit - The Best Torrents
// @license MIT License
// @icon https://raw.githubusercontent.com/Ibit-to/google-unlocked/master/extension/32.png
// @include *://www.google.*/*
// @grant GM_xmlhttpRequest
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @noframes
// ==/UserScript==
/* eslint-env browser, es6, greasemonkey, jquery */
$(function () {
if (window.location.href.indexOf('//www.google') === -1) return;
const MAX_CONCURRENT_REQUESTS = 3;
let activeRequests = 0;
let requestQueue = [];
const loadingElement = $('#cc_loading');
function processQueue() {
if (requestQueue.length === 0 || activeRequests >= MAX_CONCURRENT_REQUESTS) {
if (requestQueue.length === 0 && activeRequests === 0) {
loadingElement.remove();
}
return;
}
const nextRequest = requestQueue.shift();
activeRequests++;
nextRequest().finally(() => {
activeRequests--;
processQueue();
});
}
$('#search div.g').last().after(`
<div id="cc">
<div id="cc_loading" style="display: inline-flex;align-items: center;"></div>
<h2 id="cc_timeouts" style="color:orange"></h2>
<h2 id="cc_errors" style="color:red"></h2>
</div>
`)
const s = $('#cc')
const timeoutsElement = $('#cc_timeouts')
const errorsElement = $('#cc_errors')
let firstRun = true;
let totalFetchs = 0;
// Give a loading feedback to user
firstRun && loadingElement.prepend(`
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="40px" height="40px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">
<path fill="#4285f4" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z">
<animateTransform attributeType="xml"
attributeName="transform"
type="rotate"
from="0 25 25"
to="360 25 25"
dur="0.6s"
repeatCount="indefinite"
/>
</path>
</svg>
<h2>Loading uncensored links...</h2>
`);
firstRun = false;
$('div i > a').each((i, a) => {
if (a.href === 'https://www.google.com/support/answer/1386831') return;
totalFetchs++;
const fetchFunction = () => new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'GET',
url: a.href,
timeout: 30000, // In milliseconds. If your connection is slow I'll suggest you to increase the time or just comment this line.
onload: (response) => {
if (response.status === 429) {
console.error('ERROR 429 Too Many Requests')
errorsElement.html('ERROR 429 Too Many Requests')
reject()
return;
}
let hm = {}
const links = response.responseText.matchAll(/class="infringing_url">([^\s-<]+)\s*-\s*([0-9]+)/g)
for (const i of links) {
if (i[1] in hm) continue;
hm[i[1]] = 1
let l = $('#l' + i[2])
if (l.length < 1) {
s.prepend(`<div id="l${i[2]}" data-num="${i[2]}"></div>`)
l = $('#l' + i[2])
}
l.append(`
<div class="g">
<div class="tF2Cxc">
<div class="yuRUbf">
<a href="http://${i[1]}" target="_blank" class="LC20lb DKV0Md">${i[1]} (${i[2]} URLs)</a>
</div>
</div>
</div>
`)
}
const divs = $('div[data-num]', s)
divs.sort((a, b) => b.dataset.num - a.dataset.num)
s.append(divs)
resolve()
},
onerror: (err) => {
console.error('Request Error!\n', err.error)
if (!$.trim(errorsElement.html())) errorsElement.append('Error on some requests');
reject()
},
ontimeout: () => {
console.warn(`[${i}] Request timeout`)
if (!$.trim(timeoutsElement.html())) timeoutsElement.append('Request timeouts:');
timeoutsElement.append(' ' + i)
reject()
}
})
});
requestQueue.push(fetchFunction);
});
processQueue();
// Cleanup, after the loop
if (totalFetchs <= 0) {
loadingElement.remove();
}
})