-
Notifications
You must be signed in to change notification settings - Fork 0
/
YouTube.htm
119 lines (108 loc) · 4.54 KB
/
YouTube.htm
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
<html>
<head>
<style type="text/css">
INPUT { display: none !important; }
</style>
</head>
<body>
<input type="text" name="extractName" id="extractName" class=".hidden" />
<input type="hidden" value="zzzYT-IDzzz" id="videoid" class=".hidden" />
<input type="hidden" id="imposeboundries" class=".hidden" />
<input type="text" value="0:00:00" id="resumevideoat" onfocus="this.select();" ondblclick="resetAt('resume');" onchange="this.value = convertDuration2HHMMSS(convertHHMMSS2Duration(this.value));" />
<input type="text" value="0:00:00" id="startvideoat" onfocus="this.select();" onchange="this.value = convertDuration2HHMMSS(convertHHMMSS2Duration(this.value)); document.getElementById('imposeboundries').value = 0; updateBorder(this);" ondblclick="resetAt('start');" />
<input type="text" value="0:00:00" id="stopvideoat" onfocus="this.select();" onchange="this.value = convertDuration2HHMMSS(convertHHMMSS2Duration(this.value)); document.getElementById('imposeboundries').value = 0; updateBorder(this);" ondblclick="resetAt('stop');" />
<div class="ctrlGrp">
<textarea id="log" style="width: 100%"></textarea>
</div>
<script type="text/javascript">
// define a new console
var console=(function(oldCons){
var oLog = document.getElementById("log");
return {
log: function(text){
//oldCons.log(text);
oLog.innerHTML += '[LOG] ' + text + '\n';
},
info: function (text) {
//oldCons.info(text);
// Your code
oLog.innerHTML += '[INFO] ' + text + '\n';
},
warn: function (text) {
//oldCons.warn(text);
// Your code
oLog.innerHTML += '[WARN] ' + text + '\n';
//alert( '[WARN] ' + text + '\n')
},
error: function (text) {
//oldCons.error(text);
// Your code
oLog.innerHTML += '[ERROR] ' + text + '\n';
}
};
}(window.console));
//Then redefine the old console
window.console = console;
var buildUrlString = function () {
var urlString = "",
oTs = new Date(),
sTs = [
oTs.getFullYear(),
oTs.getMonth(),
oTs.getDate(),
oTs.getHours(),
oTs.getMinutes(),
oTs.getSeconds(),
oTs.getMilliseconds()
].join("");
urlString += "videoid=" + document.getElementById("videoid").value + "&";
urlString += "resume=" + document.getElementById("resumevideoat").value + "&";
urlString += "start=" + document.getElementById("startvideoat").value + "&";
urlString += "stop=" + document.getElementById("stopvideoat").value + "&";
urlString += "ts=" + sTs;
return urlString;
},
sProtocol = 'microsoft-edge',
sBaseUrl = "http://localhost:8000/yt_new.htm?",
sBaseHeaderUrl = "http://localhost:8000/yt_header.htm?",
sUrlString = buildUrlString();
/*
* Select one of the following default behaviours
* A) Open in SM window (memory leak)
* B) Open in new IE11 window every time
* [unfinished] C) Open in Edge window
*/
/*
* A.
*/
//document.location.href = sBaseUrl + sUrlString;
/*
* B.
*/
// var vId = document.getElementById("videoid").value;
// if(vId.length == 5){
// document.location.href = "http://localhost:3000/dist/elements/" + vId + ".html?" + sUrlString
// } else {
// document.location.href = "http://localhost:3000/index.html?" + sUrlString
// }
var vId = document.getElementById("videoid").value;
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:3000/templateUrl/' + vId);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
document.location.href = xhr.responseText + '?' + sUrlString;
}
else if (xhr.readyState === 4 && xhr.status !== 200) {
//console.error('Request failed with status: ' + xhr.status);
// TODO direct to default SM youtube template
document.location.href = "https://youtube.supermemo.org/?" + sUrlString;
}
};
xhr.send();
/*
* C.
will use window.open(sProtocol + ':' + sBaseUrl + sUrlString;
*/
</script>
</body>
</html>