This repository was archived by the owner on Feb 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserscript.js
More file actions
143 lines (114 loc) · 3.8 KB
/
Copy pathuserscript.js
File metadata and controls
143 lines (114 loc) · 3.8 KB
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
// ==UserScript==
// @name Voxus.TV to HTML5
// @namespace http://github.com/rafasirotheau/voxustv-2-html5
// @version 0.9.1
// @description Troca o Voxus.TV Player pelo HTML5
// @author Rafael Sirotheau
// @match http://*/*
// @grant none
// @require https://raw.githubusercontent.com/jfriend00/docReady/master/docready.js
// ==/UserScript==
if(self!=top) {
// Não executar script em iframes.
return false;
}
var scriptName = "Voxus.TV to HTML5",
debug = true,
version = "1.0.0";
function debugThis(msg) {
if(!debug)
return false;
console.log('['+scriptName+' v.'+version+'] '+msg);
}
/* Ajax Class */
var AjaxRequest = function() {
this.url = null;
this.ifr = null;
this.xmlhttp = null;
this.doRequest = function(url,ifr,count) {
debugThis(count+'º player: Iniciando requisição Ajax!');
this.url = url;
this.ifr = ifr;
this.xmlhttp=GetXmlHttpObject();
// Verifica se a requisição foi criada sem erros.
if (this.xmlhttp==null) {
alert('Seu navegador não suporta AJAX!');
return false;
}
var requisicao = this.xmlhttp;
requisicao.onreadystatechange=function() {
if(typeof requisicao === 'undefined') {
return false;
}
if (requisicao.readyState==4 && requisicao.status==200) {
var response = requisicao.responseText.replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '');
var thumbSrc = response.split('.png"');
thumbSrc = thumbSrc[0].split('content="');
thumbSrc = thumbSrc[thumbSrc.length-1] + '.png';
var video_name = thumbSrc.split('videos/')[1];
video_name = video_name.split('.')[0];
video_name = video_name.split('_')[0];
video_name = video_name.substr(1);
debugThis(count+'º player: Resposta OK! Substituindo....');
var videoSrc = "http://d37qvuz6ev41ur.cloudfront.net/v_"+video_name+".mp4";
debugThis(count+'º player: Video SRC: '+videoSrc);
ifr.parentNode.innerHTML = '<video width="640" height="360" controls><source src="'+videoSrc+'" type="video/mp4">Seu navegador não suporta videos HTML5.</video>';
debugThis(count+"º player: Substituído com sucesso!");
}
};
requisicao.open("GET",url,true);
requisicao.send();
}
}
function GetXmlHttpObject() {
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
var avoid = [],
ajax_request= [];
docReady(function() {
debugThis("Iniciando script...");
var iframes = document.querySelectorAll('iframe[data-original^="http://www.voxus.tv/player/view"], iframe[src^="http://www.voxus.tv/player/view"]');
if(iframes.length <= 0) {
debugThis("Nenhum player encontrado. Finalizando o script...");
return false;
}
// Remover elementos escondidos - NaoSalvo não é o que chamamos de responsivo. Sendo assim, existem dois elementos de iframe: um para mobile e outro para desktop
var found = 0;
for (var i = iframes.length-1; i >= 0; i--) {
if (iframes[i].offsetWidth > 0 && iframes[i].offsetHeight > 0) {
avoid[i] = false;
found++;
} else {
avoid[i] = true;
}
}
debugThis("Encontrado(s) "+found+" Voxus.TV Player(s)");
var count = 1;
for(i=0;i<iframes.length;i++) {
if(!avoid[i]) {
var curr_iframe = iframes[i];
debugThis(count+"º player: Tentando substituir...");
var src= curr_iframe.getAttribute('data-original') || curr_iframe.getAttribute('src');
var requestUrl = 'http://query.yahooapis.com/v1/public/yql?'+
'q='+encodeURIComponent('select * from html where url="'+src+'" and xpath="*"')+
'&format=xml';
ajax_request[i] = new AjaxRequest;
ajax_request[i].doRequest(requestUrl, curr_iframe, count)
count++;
}
}
});