-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdirect-links-out.user.js
332 lines (322 loc) · 10.3 KB
/
direct-links-out.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
// ==UserScript==
// @name Direct links out
// @name:ru Прямые ссылки наружу
// @description Removes all "You are leaving our site" and redirection stuff from links
// @description:ru Убирает "Бла-бла-бла, Вы покидаете наш сайт" и переадресации из ссылок
// @namespace https://github.com/nokeya
// @author nokeya
// @update https://github.com/nokeya/direct-links-out/raw/master/direct-links-out.user.js
// @icon https://raw.githubusercontent.com/nokeya/direct-links-out/master/icon.png
// @version 2.19
// @grant none
//google
// @include *://google.*
// @include *://www.google.*
// @include *://encrypted.google.*
//yandex
// @match *://yandex.ru/*
// @match *://yandex.ua/*
// @match *://yandex.by/*
// @match *://yandex.kz/*
// @match *://yandex.com.tr/*
// @match *://yandex.com/*
// @match *://*.yandex.ru/*
// @match *://*.yandex.ua/*
// @match *://*.yandex.by/*
// @match *://*.yandex.kz/*
// @match *://*.yandex.com.tr/*
// @match *://*.yandex.com/*
//youtube
// @match *://youtube.com/*
// @match *://*.youtube.com/*
//wikimapia
// @match *://wikimapia.org/*
//deviantart
// @match *://deviantart.com/*
// @match *://*.deviantart.com/*
//joyreactor
// @match *://joyreactor.cc/*
// @match *://*.joyreactor.cc/*
// @match *://reactor.cc/*
// @match *://*.reactor.cc/*
// @match *://joyreactor.com/*
// @match *://*.joyreactor.com/*
//vk
// @match *://vk.com/*
// @match *://*.vk.com/*
//ok
// @match *://ok.ru/*
// @match *://*.ok.ru/*
//steam
// @match *://steamcommunity.com/*
// @match *://*.steamcommunity.com/*
//fb
// @match *://facebook.com/*
// @match *://*.facebook.com/*
//twitter
// @match *://twitter.com/*
// @match *://*.twitter.com/*
//4pda
// @match *://4pda.ru/*
// @match *://*.4pda.ru/*
//kickass
// @match *://kat.cr/*
// @match *://kickassto.co/*
// @match *://katproxy.is/*
// @match *://thekat.tv/*
// @match *://*.kat.cr/*
// @match *://*.kickassto.co/*
// @match *://*.katproxy.is/*
// @match *://*.thekat.tv/*
//AMO
// @match *://addons.mozilla.org/*
//pixiv
// @match *://pixiv.net/*
// @match *://*.pixiv.net/*
//tumblr
// @match *://tumblr.com/*
// @match *://*.tumblr.com/*
//danieldefo
// @match *://danieldefo.ru/*
// @match *://*.danieldefo.ru/*
//yaplakal
// @match *://yaplakal.com/*
// @match *://*.yaplakal.com/*
//soundcloud
// @match *://soundcloud.com/*
// @match *://*.soundcloud.com/*
//upwork
// @match *://upwork.com/*
// @match *://*.upwork.com/*
//picarto
// @match *://picarto.tv/*
// @match *://*.picarto.tv/*
//taker
// @match *://taker.im/*
// @match *://*.taker.im/*
//forumavia
// @match *://*.forumavia.ru/*
//slack
// @match *://*.slack.com/*
//instagram
// @match *://instagram.com/*
// @match *://*.instagram.com/*
// ==/UserScript==
(function() {
// anchors and functions
var anchor;
var after;
var rwLink = function(){};
var rwAll = function(){};
var retTrue = function() { return true; }; //dummy function to always return true
// simple rewrite link - based on anchors
function rwSimple(link){
if (anchor){
var ndx = link.href.indexOf(anchor);
if (ndx != -1){
var newlink = link.href.substring(ndx + anchor.length);
if (after){
ndx = newlink.indexOf(after);
if (ndx != -1)
newlink = newlink.substring(0, ndx);
}
link.href = unescape(newlink);
}
}
}
function rwaSimple(){
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; ++i)
rwLink(links[i]);
}
// vk
function rwVK(link){
if (link.className === 'page_media_link_thumb')
{
var parent = link.parentNode;
link.href = parent.getAttribute("href");
parent.removeAttribute('href');
parent.removeAttribute('onclick');
link.removeAttribute('onclick');
}
var ndx = link.href.indexOf(anchor);
if (ndx != -1){
var newlink = link.href.substring(ndx + anchor.length);
var afterArr = ['&post=', '&el=snippet', '&cc_key='];
for (var i = 0; i < afterArr.length; ++i){
ndx = newlink.indexOf(afterArr[i]);
if (ndx != -1)
newlink = newlink.substring(0, ndx);
}
link.href = unescape(newlink);
}
}
// twitter
function rwTwitter(link){
if (link.hasAttribute('data-expanded-url')){
link.href = link.getAttribute('data-expanded-url');
link.removeAttribute('data-expanded-url');
}
}
function rwaTwitter(){
var links = document.getElementsByClassName('twitter-timeline-link');
for (var i = 0; i < links.length; ++i)
rwLink(links[i]);
}
// kickass
function rwKickass(link){
var ndx = link.href.indexOf(anchor);
if (ndx != -1){
link.href = window.atob(unescape(link.href.substring(ndx + anchor.length, link.href.length - 1)));
link.className = '';
}
}
// youtube
function rwYoutube(link){
if (/redirect/i.test(link.className))
link.setAttribute('data-redirect-href-updated', 'true');
rwSimple(link);
}
// facebook
function rwFacebook(link){
if (/referrer_log/i.test(link.onclick)){
link.removeAttribute('onclick');
link.removeAttribute('onmouseover');
}
rwSimple(link);
}
// google
function rwGoogle(link){
// replace global rwt script
if (window.rwt && window.rwt != retTrue){
delete window.rwt;
Object.defineProperty(window, 'rwt', { value: retTrue, writable: false });
}
// main search
if (link.hasAttribute('onmousedown'))
link.removeAttribute('onmousedown');
// images
if (link.hasAttribute('jsaction')){
var tmp = link.getAttribute('jsaction');
if (tmp)
link.setAttribute('jsaction', tmp.replace(/(mousedown:irc.rl|keydown:irc.rlk)/g,''));
}
}
// yandex
function rwYandex(link){
// main search
if (link.hasAttribute('onmousedown'))
link.removeAttribute('onmousedown');
// images
anchor = '&img_url=';
after = '&pos=';
rwSimple(link);
}
//mozilla addons store
function rwAMO(link){
if (/outgoing.prod.mozaws.net/i.test(link.href)){
var tmp = link.href;
link.href = "#";
// we have to fight mozilla's replacing of direct redirect string with jquery events
setTimeout(function(){ link.href = unescape(tmp.replace(/(http|https):\/\/outgoing.prod.mozaws.net\/v1\/[0-9a-zA-Z]+\//i,'')); }, 100);
}
}
// daniueldefo
function rwDanielDefo(link){
if (link.hasAttribute('data-proxy-href'))
link.removeAttribute('data-proxy-href');
}
// slack
function rwSlack(link){
link.removeAttribute('onclick');
link.removeAttribute('onmouseover');
}
// determine anchors, functions and listeners
(function ()
{
rwLink = rwSimple;
rwAll = rwaSimple;
var loc = window.location.hostname;
if (/google/i.test(loc))
rwLink = rwGoogle;
else if (/youtube/i.test(loc)){
anchor = 'redirect?q=';
after = '&redir_token=';
rwLink = rwYoutube;
}
else if (/facebook/i.test(loc)){
anchor = 'u=';
after = '&h=';
rwLink = rwFacebook;
}
else if (/instagram/i.test(loc)){
anchor = 'u=';
after = '&e=';
}
else if (/twitter/i.test(loc)){
rwLink = rwTwitter;
rwAll = rwaTwitter;
}
else if (/yandex/i.test(loc))
rwLink = rwYandex;
else if (/vk/i.test(loc)){
anchor = 'to=';
rwLink = rwVK;
}
else if (/ok/i.test(loc)){
anchor = 'st.link=';
after = '&st.name=';
}
else if (/pixiv/i.test(loc))
anchor = 'jump.php?';
else if (/tumblr/i.test(loc)){
anchor = "redirect?z=";
after = "&t=";
}
else if (/deviantart/i.test(loc))
anchor = 'outgoing?';
else if (/(steam|reactor)/i.test(loc))
anchor = 'url=';
else if (/(kat|kickass)/i.test(loc)){
anchor = 'confirm/url/';
rwLink = rwKickass;
}
else if (/soundcloud/i.test(loc))
anchor = "exit.sc/?url=";
else if (/upwork/i.test(loc))
anchor = 'leaving-odesk?ref=';
else if (/4pda/i.test(loc)){
anchor = 'go/?u=';
after = '&e=';
}
else if (/mozilla/i.test(loc))
rwLink = rwAMO;
else if (/danieldefo/i.test(loc))
rwLink = rwDanielDefo;
else if (/yaplakal/i.test(loc))
anchor = "go/?";
else if (/wikimapia.org/i.test(loc))
anchor = 'external_link?url=';
else if (/forumavia.ru/i.test(loc))
anchor = '/e/?l=';
else if (/picarto/i.test(loc)){
anchor = "referrer?go=";
after = "&ref=";
}
else if (/taker/i.test(loc))
anchor = "phpBB2/goto/";
else if (/slack/i.test(loc))
rwLink = rwSlack;
document.addEventListener('DOMNodeInserted', function(event){
if (!event || !event.target || !(event.target instanceof HTMLElement))
return;
var node = event.target;
if (node instanceof HTMLAnchorElement)
rwLink(node);
var links = node.getElementsByTagName('a');
for (var i = 0; i < links.length; ++i)
rwLink(links[i]);
}, false);
})();
rwAll();
})();