-
Notifications
You must be signed in to change notification settings - Fork 161
/
google-unlocked.user.js
121 lines (110 loc) · 4.84 KB
/
google-unlocked.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
// ==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;
$('#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 loadingElement = $('#cc_loading')
const timeoutsElement = $('#cc_timeouts')
const errorsElement = $('#cc_errors')
let firstRun = true
let totalFetchs = 0
$('div i > a').each((i, a) => {
if (a.href === 'https://www.google.com/support/answer/1386831') return;
totalFetchs++
// 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
return 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">
<a href="http://${i[1]}" target="_blank">${i[1]} (${i[2]} URLs)</a>
</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()
}
})
})
// Cleanup
.finally(() => {
totalFetchs--
if (totalFetchs > 0) return;
loadingElement.remove()
})
// Promise error when rejected, ignore
.catch(e => {})
})
})