-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
automix.html
181 lines (147 loc) · 5.09 KB
/
automix.html
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
<html lang="en">
<head>
<title>Auto Mixer</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<style>
body{
padding:0;
margin:0;
background-color: #0000;
display:none;
}
iframe {
border:0;
margin:0;
padding:0;
display:block;
margin:0px;
width:100%;
}
input{
width:400px;
padding:5px;
margin:5px;
}
button{
padding:5px;
margin:5px;
}
</style>
</head>
<body id="body">
<input placeholder="Enter an VDO.Ninja View URL here" id="viewlink" />
<input placeholder="Enter the chat overlay link here" id="chatlink" />
<button id="startButton" onclick="loadIframes();">Start</button>
<button id="getLinkButton" onclick="getLink();">Create Link for OBS</button><br />
<a id="linkOut"></a>
<script>
(function(w) {
w.URLSearchParams = w.URLSearchParams || function(searchString) {
var self = this;
searchString = searchString.replace("??", "?");
self.searchString = searchString;
self.get = function(name) {
var results = new RegExp('[\?&]' name '=([^&#]*)').exec(self.searchString);
if (results == null) {
return null;
} else {
return decodeURI(results[1]) || 0;
}
};
};
})(window);
var urlEdited = window.location.search.replace(/\?\?/g, "?");
urlEdited = urlEdited.replace(/\?/g, "&");
urlEdited = urlEdited.replace(/\&/, "?");
if (urlEdited !== window.location.search){
window.history.pushState({path: urlEdited.toString()}, '', urlEdited.toString());
}
var urlParams = new URLSearchParams(urlEdited);
var counter = 0;
if (urlParams.has('vdo')) {
document.getElementById("viewlink").value = decodeURIComponent(urlParams.get('vdo'));
document.getElementById("viewlink").style.display = "none";
counter =1;
} else {
document.getElementById("body").style.display = "block";
}
if (urlParams.has('chat')) {
document.getElementById("chatlink").value = decodeURIComponent(urlParams.get('chat'));
document.getElementById("chatlink").style.display = "none";
counter =1;
} else {
document.getElementById("body").style.display = "block";
}
function loadIframes(){ // this is pretty important if you want to avoid camera permission popup problems. You can also call it automatically via: <body onload=>loadIframe();"> , but don't call it before the page loads.
var iframe = document.createElement("iframe");
var iframesrc = document.getElementById("viewlink").value;
var iframe2 = document.createElement("iframe");
var iframesrc2 = document.getElementById("chatlink").value;
document.getElementById("body").innerHTML = "";
document.getElementById("body").style.display = "block";
iframe.allow = "autoplay;camera;microphone;fullscreen;picture-in-picture;display-capture;";
if (iframesrc==""){
iframesrc="https://vdo.ninja";
}
if (iframesrc.startsWith("http://")){
//
} else if (!iframesrc.startsWith("https://")){
iframesrc = "https://" iframesrc;
}
if (iframesrc.includes("?")){
iframesrc ='&';
} else {
iframesrc ='?';
}
iframesrc ="transparent";
iframe.src = iframesrc;
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.transform = "height 2s linear";
document.getElementById("body").appendChild(iframe);
iframe2.allow = "autoplay;camera;microphone;fullscreen;picture-in-picture;display-capture;";
if (iframesrc2==""){
iframesrc2="./";
}
iframe2.style.width = "100%";
iframe2.style.height = "0%";
iframe2.style.transform = "height 2s linear";
iframe2.src = iframesrc2;
document.getElementById("body").appendChild(iframe2);
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message";
eventer(messageEvent, function (e) {
if (e.source != iframe2.contentWindow){return} // reject messages send from other iframes
if ("resizeWindow" in e.data){
if ("width" in e.data.resizeWindow){
iframe2.style.width = e.data.resizeWindow.width;
iframe.style.width = "calc(100% - " e.data.resizeWindow.width ")";
}
if ("height" in e.data.resizeWindow){
iframe2.style.height = e.data.resizeWindow.height;
iframe.style.height = "calc(100% - " e.data.resizeWindow.height ")";
}
}
});
}
if (counter==2){
loadIframes();
}
function getLink(){
var iframesrc = document.getElementById("viewlink").value;
var iframesrc2 = document.getElementById("chatlink").value;
var outputLink = window.location "";
if (outputLink.includes("?")){
outputLink ="&";
} else {
outputLink ="?";
}
outputLink = "vdo=" encodeURIComponent(iframesrc) "&chat=" encodeURIComponent(iframesrc2);
document.getElementById("linkOut").innerHTML = outputLink;
document.getElementById("linkOut").href = outputLink;
}
</script>
</body>
</html>