-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinktubeplusplus.user.js
606 lines (562 loc) · 24.8 KB
/
linktubeplusplus.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
// ==UserScript==
// @name LinkTube
// @version 2017.11.23
// @description Replaces an embedded video with a link to the video page.
// @author sebaro
// @namespace http://isebaro.com/linktube
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @downloadURL https://raw.githubusercontent.com/sebaro/linktube/master/linktubeplusplus.user.js
// @updateURL https://raw.githubusercontent.com/sebaro/linktube/master/linktubeplusplus.user.js
// @icon https://raw.githubusercontent.com/sebaro/linktube/master/linktube.png
// @include *
// @grant GM_xmlhttpRequest
// @grant GM.xmlHttpRequest
// ==/UserScript==
/*
Copyright (C) 2011 - 2017 Sebastian Luncan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Website: http://isebaro.com/linktube
Contact: http://isebaro.com/contact
*/
(function() {
// ==========Variables========== //
// Userscript
var userscript = 'LinkTube';
// Contact
var contact = 'http://isebaro.com/contact';
// Warning
var warning = 'Couldn\'t get the video link. Please report it <a href="' + contact + '">here</a>.';
// Options
var option = {'secure': true};
// ==========Fixes========== //
// Don't run on frames or iframes
if (window.top != window.self) return;
// ==========Functions========== //
function createMyElement (type, content) {
var obj = document.createElement(type);
if (type == 'div') {
if (content) obj.innerHTML = content;
}
return obj;
}
function getMyElement (element, get, tag) {
var obj;
if (get == 'parent') obj = element.parentNode;
else if (get == 'source') obj = element.src;
else if (get == 'name') obj = element.name;
else if (get == 'value') obj = element.value;
else if (get == 'children') obj = element.getElementsByTagName(tag);
return obj;
}
function modifyMyElement (obj, type, content, clear) {
if (type == 'div') {
if (content) obj.innerHTML = content;
}
if (clear) {
if (obj.hasChildNodes()) {
while (obj.childNodes.length >= 1) {
obj.removeChild(obj.firstChild);
}
}
}
}
function styleMyElement (obj, styles) {
for (var property in styles) {
if (styles.hasOwnProperty(property)) obj.style[property] = styles[property];
}
}
function appendMyElement (parent, child) {
if (parent == 'body') document.body.appendChild(child);
else parent.appendChild(child);
}
function removeMyElement (parent, child) {
if (parent == 'body') document.body.removeChild(child);
else parent.removeChild(child);
}
function replaceMyElement (parent, orphan, child) {
parent.replaceChild(orphan, child);
}
function cleanMyContent (content, unesc) {
var myNewContent = content;
if (unesc) myNewContent = unescape (myNewContent);
myNewContent = myNewContent.replace (/\\u0025/g,'%');
myNewContent = myNewContent.replace (/\\u0026/g,'&');
myNewContent = myNewContent.replace (/\\/g,'');
myNewContent = myNewContent.replace (/\n/g,'');
return myNewContent;
}
function YouTube (url, target) {
/* Decrypt Signature */
var ytScriptSrc;
function ytDecryptSignature (s) {return null;}
function ytDecryptFunction () {
var ytSignFuncName, ytSignFuncBody, ytSwapFuncName, ytSwapFuncBody, ytFuncMatch;
ytScriptSrc = ytScriptSrc.replace(/(\r\n|\n|\r)/gm, '');
ytSignFuncName = ytScriptSrc.match(/"signature"\s*,\s*(.*?)\(/);
ytSignFuncName = (ytSignFuncName) ? ytSignFuncName[1] : null;
if (ytSignFuncName) {
ytFuncMatch = ytSignFuncName.replace(/\$/, '\\$') + '\\s*=\\s*function\\s*' + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\}';
ytSignFuncBody = ytScriptSrc.match(ytFuncMatch);
ytSignFuncBody = (ytSignFuncBody) ? ytSignFuncBody[1] : null;
if (ytSignFuncBody) {
ytSwapFuncName = ytSignFuncBody.match(/((\$|_|\w)+)\.(\$|_|\w)+\(\w,[0-9]+\)/);
ytSwapFuncName = (ytSwapFuncName) ? ytSwapFuncName[1] : null;
if (ytSwapFuncName) {
ytFuncMatch = 'var\\s+' + ytSwapFuncName.replace(/\$/, '\\$') + '=\\s*\\{(.*?)\\};';
ytSwapFuncBody = ytScriptSrc.match(ytFuncMatch);
ytSwapFuncBody = (ytSwapFuncBody) ? ytSwapFuncBody[1] : null;
}
if (ytSwapFuncBody) ytSignFuncBody = 'var ' + ytSwapFuncName + '={' + ytSwapFuncBody + '};' + ytSignFuncBody;
ytSignFuncBody = 'try {' + ytSignFuncBody + '} catch(e) {return null}';
ytDecryptSignature = new Function('a', ytSignFuncBody);
}
}
}
/* Parse Videos */
function ytVideos() {
var ytVideoFormats = {
'5': 'Very Low Definition FLV',
'17': 'Very Low Definition 3GP',
'18': 'Low Definition MP4',
'22': 'High Definition MP4',
'34': 'Low Definition FLV',
'35': 'Standard Definition FLV',
'36': 'Low Definition 3GP',
'37': 'Full High Definition MP4',
'38': 'Ultra High Definition MP4',
'43': 'Low Definition WebM',
'44': 'Standard Definition WebM',
'45': 'High Definition WebM',
'46': 'Full High Definition WebM',
'82': 'Low Definition 3D MP4',
'83': 'Standard Definition 3D MP4',
'84': 'High Definition 3D MP4',
'85': 'Full High Definition 3D MP4',
'100': 'Low Definition 3D WebM',
'101': 'Standard Definition 3D WebM',
'102': 'High Definition 3D WebM',
'135': 'Standard Definition Video MP4',
'136': 'High Definition Video MP4',
'137': 'Full High Definition Video MP4',
'138': 'Ultra High Definition Video MP4',
'139': 'Low Bitrate Audio MP4',
'140': 'Medium Bitrate Audio MP4',
'141': 'High Bitrate Audio MP4',
'171': 'Medium Bitrate Audio WebM',
'172': 'High Bitrate Audio WebM',
'244': 'Standard Definition Video WebM',
'247': 'High Definition Video WebM',
'248': 'Full High Definition Video WebM',
'266': 'Ultra High Definition Video MP4',
'272': 'Ultra High Definition Video WebM',
'298': 'High Definition Video MP4',
'299': 'Full High Definition Video MP4',
'302': 'High Definition Video WebM',
'303': 'Full High Definition Video WebM',
'313': 'Ultra High Definition Video WebM'
};
var ytVideoFound = false;
var ytVideos = ytVideosContent.split(',');
var ytVideoParse, ytVideoCodeParse, ytVideoCode, myVideoCode, ytVideo;
for (var i = 0; i < ytVideos.length; i++) {
if (!ytVideos[i].match(/^url/)) {
ytVideoParse = ytVideos[i].match(/(.*)(url=.*$)/);
if (ytVideoParse) ytVideos[i] = ytVideoParse[2] + '&' + ytVideoParse[1];
}
ytVideoCodeParse = ytVideos[i].match (/itag=(\d{1,3})/);
ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
if (ytVideoCode) {
myVideoCode = ytVideoFormats[ytVideoCode];
if (myVideoCode) {
ytVideo = cleanMyContent(ytVideos[i], true);
ytVideo = ytVideo.replace(/url=/, '').replace(/&$/, '');
if (ytVideo.match(/itag=/) && ytVideo.match(/itag=/g).length > 1) {
if (ytVideo.match(/itag=\d{1,3}&/)) ytVideo = ytVideo.replace(/itag=\d{1,3}&/, '');
else if (ytVideo.match(/&itag=\d{1,3}/)) ytVideo = ytVideo.replace(/&itag=\d{1,3}/, '');
}
if (ytVideo.match(/clen=/) && ytVideo.match(/clen=/g).length > 1) {
if (ytVideo.match(/clen=\d+&/)) ytVideo = ytVideo.replace(/clen=\d+&/, '');
else if (ytVideo.match(/&clen=\d+/)) ytVideo = ytVideo.replace(/&clen=\d+/, '');
}
if (ytVideo.match(/lmt=/) && ytVideo.match(/lmt=/g).length > 1) {
if (ytVideo.match(/lmt=\d+&/)) ytVideo = ytVideo.replace(/lmt=\d+&/, '');
else if (ytVideo.match(/&lmt=\d+/)) ytVideo = ytVideo.replace(/&lmt=\d+/, '');
}
if (ytVideo.match(/type=(video|audio).*?&/)) ytVideo = ytVideo.replace(/type=(video|audio).*?&/, '');
else ytVideo = ytVideo.replace(/&type=(video|audio).*$/, '');
if (ytVideo.match(/xtags=[^%=]*&/)) ytVideo = ytVideo.replace(/xtags=[^%=]*?&/, '');
else if (ytVideo.match(/&xtags=[^%=]*$/)) ytVideo = ytVideo.replace(/&xtags=[^%=]*$/, '');
if (ytVideo.match(/&sig=/)) ytVideo = ytVideo.replace(/&sig=/, '&signature=');
else if (ytVideo.match(/&s=/)) {
var ytSig = ytVideo.match(/&s=(.*?)(&|$)/);
if (ytSig) {
var s = ytSig[1];
s = ytDecryptSignature(s);
if (s) ytVideo = ytVideo.replace(/&s=.*?(&|$)/, '&signature=' + s + '$1');
else ytVideo = '';
}
else ytVideo = '';
}
ytVideo = cleanMyContent(ytVideo, true);
if (ytVideo.indexOf('ratebypass') == -1) ytVideo += '&ratebypass=yes';
if (ytVideo && ytVideo.indexOf('http') == 0) {
if (ytVideoTitle) ytVideo += '&title=' + ytVideoTitle;
if (!ytVideoFound) ytVideoFound = true;
ytVideoList += '<a href="' + ytVideo + '">' + myVideoCode + '</a><br>';
}
}
}
}
if (!ytVideoFound) {
if (ytVideosContent.indexOf('conn=rtmp') != -1) ytVideoList = 'ERROR: RTMP!';
else ytVideoList = 'ERROR: No videos!';
}
}
var ytVideosContent;
var ytVideoTitle;
var ytVideoLength;
var ytVideoList = '';
try {
GM.xmlHttpRequest({
method: 'GET',
url: url,
onload: function(response) {
if (response.readyState === 4 && response.status === 200) {
/* Get Page Source */
ytPageSource = response.responseText;
/* Get Video Title */
ytVideoTitle = ytPageSource.match(/"title":"(.*?)","lengthSeconds"/);
ytVideoTitle = (ytVideoTitle) ? ytVideoTitle[1] : null;
if (!ytVideoTitle) {
ytVideoTitle = ytPageSource.match(/document.title\s*=\s*"(.*?)"/);
ytVideoTitle = (ytVideoTitle) ? ytVideoTitle[1] : null;
}
if (!ytVideoTitle) {
ytVideoTitle = ytPageSource.match(/meta\s+itemprop="name"\s+content="(.*?)"/);
ytVideoTitle = (ytVideoTitle) ? ytVideoTitle[1] : null;
}
if (!ytVideoTitle) {
ytVideoTitle = ytPageSource.match(/meta\s+property="og:title"\s+content="(.*?)"/);
ytVideoTitle = (ytVideoTitle) ? ytVideoTitle[1] : null;
}
if (ytVideoTitle) {
ytVideoTitle = ytVideoTitle.replace(/"/g, '\'').replace(/"/g, '\'').replace(/"/g, '\'');
ytVideoTitle = ytVideoTitle.replace(/'/g, '\'').replace(/'/g, '\'');
ytVideoTitle = ytVideoTitle.replace(/&/g, 'and').replace(/&/g, 'and');
ytVideoTitle = ytVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
ytVideoTitle = ytVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
ytVideoTitle = ytVideoTitle.replace(/^YouTube\s-\s/, '');
}
/* Get Video Length */
ytVideoLength = ytPageSource.match(/"lengthSeconds":"(.*?)"/);
ytVideoLength = (ytVideoLength) ? ytVideoLength[1] : null;
if (ytVideoLength) {
ytVideoLength = new Date(ytVideoLength * 1000).toISOString().substr(11, 8).replace(/00:0?/, '');
}
else {
ytVideoLength = ytPageSource.match(/meta\s+itemprop="duration"\s+content="(.*?)"/);
ytVideoLength = (ytVideoLength) ? ytVideoLength[1].replace('PT', '').replace('M', ':').replace('S', '') : null;
}
/* Get Videos Content */
var ytVideosEncodedFmts, ytVideosAdaptiveFmts;
ytVideosEncodedFmts = ytPageSource.match(/"url_encoded_fmt_stream_map":\s*"(.*?)"/);
ytVideosEncodedFmts = (ytVideosEncodedFmts) ? ytVideosEncodedFmts[1] : null;
if (ytVideosEncodedFmts) ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, false);
ytVideosAdaptiveFmts = ytPageSource.match(/"adaptive_fmts":\s*"(.*?)"/);
ytVideosAdaptiveFmts = (ytVideosAdaptiveFmts) ? ytVideosAdaptiveFmts[1] : null;
if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, false);
if (ytVideosEncodedFmts) {
ytVideosContent = ytVideosEncodedFmts;
}
if (ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmts = ytVideosAdaptiveFmts.replace(/clen=\d+&/g, '').replace(/&clen=\d+/g, '');
ytVideosAdaptiveFmts = ytVideosAdaptiveFmts.replace(/lmt=\d+&/g, '').replace(/&lmt=\d+/g, '');
if (ytVideosContent) ytVideosContent += ',' + ytVideosAdaptiveFmts;
else ytVideosContent = ytVideosAdaptiveFmts;
}
/* Get Videos */
if (ytVideosContent) {
if (ytVideosContent.match(/&s=/) || ytVideosContent.match(/,s=/) || ytVideosContent.match(/u0026s=/)) {
var ytScriptURL = ytPageSource.match(/"js":\s*"(.*?)"/);
ytScriptURL = (ytScriptURL) ? ytScriptURL[1] : null;
if (ytScriptURL) {
ytScriptURL = 'https:' + cleanMyContent(ytScriptURL, false);
GM.xmlHttpRequest({
method: 'GET',
url: ytScriptURL,
onload: function(response) {
if (response.readyState === 4 && response.status === 200) {
ytScriptSrc = response.responseText;
if (ytScriptSrc) {
ytDecryptFunction();
ytVideos();
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>' + ytVideoList;
modifyMyElement (target, 'div', ytVideoList, false);
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No script!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No script response!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
});
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No script!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
else {
ytVideos();
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>' + ytVideoList;
modifyMyElement (target, 'div', ytVideoList, false);
}
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No videos content!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No videos!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
});
}
catch(e) {
try {
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function(response) {
if (response.readyState === 4 && response.status === 200) {
/* Get Page Source */
ytPageSource = response.responseText;
/* Get Video Title */
ytVideoTitle = ytPageSource.match(/"title":"(.*?)","lengthSeconds"/);
ytVideoTitle = (ytVideoTitle) ? ytVideoTitle[1] : null;
if (!ytVideoTitle) {
ytVideoTitle = ytPageSource.match(/document.title\s*=\s*"(.*?)"/);
ytVideoTitle = (ytVideoTitle) ? ytVideoTitle[1] : null;
}
if (!ytVideoTitle) {
ytVideoTitle = ytPageSource.match(/meta\s+itemprop="name"\s+content="(.*?)"/);
ytVideoTitle = (ytVideoTitle) ? ytVideoTitle[1] : null;
}
if (!ytVideoTitle) {
ytVideoTitle = ytPageSource.match(/meta\s+property="og:title"\s+content="(.*?)"/);
ytVideoTitle = (ytVideoTitle) ? ytVideoTitle[1] : null;
}
if (ytVideoTitle) {
ytVideoTitle = ytVideoTitle.replace(/"/g, '\'').replace(/"/g, '\'').replace(/"/g, '\'');
ytVideoTitle = ytVideoTitle.replace(/'/g, '\'').replace(/'/g, '\'');
ytVideoTitle = ytVideoTitle.replace(/&/g, 'and').replace(/&/g, 'and');
ytVideoTitle = ytVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
ytVideoTitle = ytVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
ytVideoTitle = ytVideoTitle.replace(/^YouTube\s-\s/, '');
}
/* Get Video Length */
ytVideoLength = ytPageSource.match(/"lengthSeconds":"(.*?)"/);
ytVideoLength = (ytVideoLength) ? ytVideoLength[1] : null;
if (ytVideoLength) {
ytVideoLength = new Date(ytVideoLength * 1000).toISOString().substr(11, 8).replace(/00:0?/, '');
}
else {
ytVideoLength = ytPageSource.match(/meta\s+itemprop="duration"\s+content="(.*?)"/);
ytVideoLength = (ytVideoLength) ? ytVideoLength[1].replace('PT', '').replace('M', ':').replace('S', '') : null;
}
/* Get Videos Content */
var ytVideosEncodedFmts, ytVideosAdaptiveFmts;
ytVideosEncodedFmts = ytPageSource.match(/"url_encoded_fmt_stream_map":\s*"(.*?)"/);
ytVideosEncodedFmts = (ytVideosEncodedFmts) ? ytVideosEncodedFmts[1] : null;
if (ytVideosEncodedFmts) ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, false);
ytVideosAdaptiveFmts = ytPageSource.match(/"adaptive_fmts":\s*"(.*?)"/);
ytVideosAdaptiveFmts = (ytVideosAdaptiveFmts) ? ytVideosAdaptiveFmts[1] : null;
if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, false);
if (ytVideosEncodedFmts) {
ytVideosContent = ytVideosEncodedFmts;
}
if (ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmts = ytVideosAdaptiveFmts.replace(/clen=\d+&/g, '').replace(/&clen=\d+/g, '');
ytVideosAdaptiveFmts = ytVideosAdaptiveFmts.replace(/lmt=\d+&/g, '').replace(/&lmt=\d+/g, '');
if (ytVideosContent) ytVideosContent += ',' + ytVideosAdaptiveFmts;
else ytVideosContent = ytVideosAdaptiveFmts;
}
/* Get Videos */
if (ytVideosContent) {
if (ytVideosContent.match(/&s=/) || ytVideosContent.match(/,s=/) || ytVideosContent.match(/u0026s=/)) {
var ytScriptURL = ytPageSource.match(/"js":\s*"(.*?)"/);
ytScriptURL = (ytScriptURL) ? ytScriptURL[1] : null;
if (ytScriptURL) {
ytScriptURL = 'https:' + cleanMyContent(ytScriptURL, false);
GM_xmlhttpRequest({
method: 'GET',
url: ytScriptURL,
onload: function(response) {
if (response.readyState === 4 && response.status === 200) {
ytScriptSrc = response.responseText;
if (ytScriptSrc) {
ytDecryptFunction();
ytVideos();
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>' + ytVideoList;
modifyMyElement (target, 'div', ytVideoList, false);
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No script!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No script response!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
});
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No script!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
else {
ytVideos();
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>' + ytVideoList;
modifyMyElement (target, 'div', ytVideoList, false);
}
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No videos content!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
else {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No videos!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
});
}
catch(e) {
ytVideoList = ytVideoTitle + ' (' + ytVideoLength + ')<br>' + '<a href="' + url + '">' + url + '</a><br>ERROR: No videos!';
modifyMyElement (target, 'div', ytVideoList, false);
}
}
}
function embedMyLinks (element) {
var elements;
if (element == 'iframe') elements = iframeElements;
else if (element == 'object') elements = objectElements;
else if (element == 'embed') elements = embedElements;
var child, parent, video, param, name;
var foundSite;
var linkID, videoID, videoLink, videoURL;
var myScriptLogo = [];
myScriptLogo[element] = [];
var myScriptMess = [];
myScriptMess[element] = [];
var myLinkWindow = [];
myLinkWindow[element] = [];
for (var e = elements.length - 1; e >= 0; e--) {
foundSite = false;
child = elements[e];
parent = getMyElement (child, 'parent', '');
if (element == 'iframe' || element == 'embed') {
video = getMyElement (child, 'source', '');
}
else if (element == 'object') {
params = getMyElement (child, 'children', 'param');
for (var p = 0; p < params.length; p++) {
name = getMyElement (params[p], 'name', '');
if (name == 'movie' || name == 'src') {
video = getMyElement (params[p], 'value', '');
if (!video) video = getMyElement (params[p], 'source', '');
}
}
}
if (video) {
for (var l = 0; l < linkParsers.length; l++) {
if (video.match(linkParsers[l]['source'])) {
foundSite = true;
linkID = l;
break;
}
}
}
if (foundSite) {
myScriptLogo[element][e] = createMyElement ('div', userscript);
styleMyElement (myScriptLogo[element][e], {margin: '0px auto', padding: '10px', color: '#FFFFFF', fontSize: '20px', textAlign: 'center', textShadow: '#000000 -1px -1px 1px'});
myScriptMess[element][e] = createMyElement ('div', '');
myLinkWindow[element][e] = createMyElement ('div', '');
appendMyElement (myLinkWindow[element][e], myScriptLogo[element][e]);
appendMyElement (myLinkWindow[element][e], myScriptMess[element][e]);
var childStyles = child.getAttribute('style');
if (childStyles) {
childStyles = childStyles.replace('absolute', 'relative');
myLinkWindow[element][e].setAttribute('style', childStyles);
styleMyElement (myLinkWindow[element][e], {backgroundColor: '#F4F4F4'});
}
else styleMyElement (myLinkWindow[element][e], {width: '100%', height: '100%', backgroundColor: '#F4F4F4'});
styleMyElement (parent, {padding: '0px', height: '100%'});
replaceMyElement(parent, myLinkWindow[element][e], child);
videoID = video.match(linkParsers[linkID]['pattern']);
videoID = (videoID) ? videoID[1] : null;
if (videoID) {
videoURL = linkParsers[linkID]['link'] + videoID;
if (!option['secure']) videoURL = videoURL.replace(/^https/, 'http');
styleMyElement (myScriptMess[element][e], {border: '3px solid #F4F4F4', margin: '0px auto', padding: '10px', backgroundColor: '#FFFFFF', color: '#00C000', textAlign: 'center', fontSize: '16px'});
if (videoURL.indexOf('youtube.com') != -1) {
YouTube(videoURL, myScriptMess[element][e]);
}
else {
videoLink = '<a href="' + videoURL + '">' + videoURL + '</a>';
modifyMyElement (myScriptMess[element][e], 'div', videoLink, false);
}
}
else {
styleMyElement (myScriptMess[element][e], {border: '3px solid #F4F4F4', margin: '0px auto', padding: '10px', backgroundColor: '#FFFFFF', color: '#AD0000', textAlign: 'center', fontSize: '16px'});
modifyMyElement (myScriptMess[element][e], 'div', warning, false);
}
}
}
}
// ==========Websites========== //
/* Parsers */
var linkParsers = [
{'source': 'youtube(.com|-nocookie.com)/embed/(videoseries|\\?list)', 'pattern': 'list=(.*?)(&|$)', 'link': 'https://www.youtube.com/playlist?list='},
{'source': 'youtube(.com|-nocookie.com)/embed/', 'pattern': '/embed/(.*?)(\\?|&|$)', 'link': 'https://www.youtube.com/watch?v='},
{'source': 'youtube(.com|-nocookie.com)/v/', 'pattern': '/v/(.*?)(\\?|&|$)', 'link': 'https://www.youtube.com/watch?v='},
{'source': 'dailymotion.com/embed/', 'pattern': '/video/(.*?)$', 'link': 'https://www.dailymotion.com/video/'},
{'source': 'dailymotion.com/swf/(?!video)', 'pattern': '/swf/(.*?)$', 'link': 'https://www.dailymotion.com/video/'},
{'source': 'dailymotion.com/swf/(?=video)', 'pattern': '/video/(.*?)$', 'link': 'https://www.dailymotion.com/video/'},
{'source': 'vimeo.com/video/', 'pattern': '/video/(.*?)(\\?|&|$)', 'link': 'https://vimeo.com/'},
{'source': 'vimeo.com/moogaloop', 'pattern': '/moogaloop.swf\\?clip_id=(.*?)(&|$)', 'link': 'https://vimeo.com/'},
{'source': 'metacafe.com/embed/', 'pattern': '/embed/(.*?)/', 'link': 'https://www.metacafe.com/watch/'},
{'source': 'metacafe.com/fplayer/', 'pattern': '/fplayer/(.*?)/', 'link': 'https://www.metacafe.com/watch/'},
{'source': 'funnyordie.com/embed/', 'pattern': '/embed/(.*?)$', 'link': 'https://www.funnyordie.com/videos/'},
{'source': 'vk.com/video', 'pattern': 'video_ext.php\\?(.*?)$', 'link': 'http://vk.com/video_ext.php?'},
{'source': 'hostname=www.twitch.tv', 'pattern': 'channel=(.*?)(&|$)', 'link': 'http://www.twitch.tv/'}
];
/* IFrame */
var iframeElements = getMyElement (document, 'children', 'iframe');
if (iframeElements.length > 0 ) embedMyLinks ('iframe');
/* Object */
var objectElements = getMyElement (document, 'children', 'object');
if (objectElements.length > 0 ) embedMyLinks ('object');
/* Embed */
var embedElements = getMyElement (document, 'children', 'embed');
if (embedElements.length > 0 ) embedMyLinks ('embed');
})();