-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.js
175 lines (161 loc) · 6.59 KB
/
source.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
//convert ###%20 to current timestamp or to time in HH:MM:SS format if Starttime is provided
javascript:(function () {
var currentTime = new Date();
function calculateTime(now,starttimestamp) {
var time = parseInt(now, 10) - parseInt(starttimestamp, 10),
date, hours, minutes, seconds, returntime = '';
console.log(time + ' ' + now + ' ' + starttimestamp);
hours = Math.floor(time / 3600);
minutes = Math.floor((time - (hours * 3600)) / 60);
seconds = time - (hours * 3600) - (minutes * 60);
returntime += (hours < 10) ? '0' + hours + ':' : hours + ':';
returntime += (minutes < 10) ? '0' + minutes + ':' : minutes + ':';
returntime += (seconds < 10) ? '0' + seconds : seconds;
return returntime;
}
function insertHMS() {
var padlines = padeditor.ace.exportText().split('\n'),
timestamp = Math.round(new Date().getTime() / 1000),
timearray = [],
i = 0, starttimestamp;
for (i = 0; i < padlines.length; i++) {
if (padlines[i].indexOf('Starttime:') === 0) {
timearray[0] = padlines[i].replace('Starttime:','');
timearray[1] = timearray[0].split(' ')[0].split('.');
timearray[2] = timearray[0].split(' ')[1].split(':');
timearray[3] = new Date(timearray[1][2], (timearray[1][1] - 1), timearray[1][0], timearray[2][0], timearray[2][1], timearray[2][2], 0);
starttimestamp = Math.round(timearray[3].getTime() / 1000);
}
if (padlines[i].indexOf('###%20') === 0) {
if(typeof starttimestamp === 'number') {
padeditor.ace.replaceRange([i, 0], [i, 3], '' + calculateTime(timestamp, starttimestamp));
} else {
padeditor.ace.replaceRange([i, 0], [i, 3], '' + timestamp);
}
}
}
window.setTimeout(insertHMS, 750);
}
insertHMS();
})();
//change Timestamps to HH:MM:SS
javascript:(function () {
function calculateTime(starttime, now) {
var time = parseInt(now, 10) - parseInt(starttime, 10),
date, hours, minutes, seconds, returntime = '';
hours = Math.floor(time / 3600);
minutes = Math.floor((time - (hours * 3600)) / 60);
seconds = time - (hours * 3600) - (minutes * 60);
returntime += (hours < 10) ? '0' + hours + ':' : hours + ':';
returntime += (minutes < 10) ? '0' + minutes + ':' : minutes + ':';
returntime += (seconds < 10) ? '0' + seconds : seconds;
return returntime;
}
var padlines = padeditor.ace.exportText().split('\n'),
i = 0,
starttime = false,
timestamp, newtime;
for (i = 0; i < padlines.length; i++) {
if (starttime === false) {
if (padlines[i].substr(10, 1) === ' ') {
if (isNaN(parseInt(padlines[i].substr(0, 10), 10)) === false) {
starttime = prompt('Enter your Start-Timestamp', padlines[i].substr(0, 10));
}
}
} else {
if (padlines[i].substr(10, 1) === ' ') {
timestamp = padlines[i].substr(0, 10);
if (isNaN(parseInt(timestamp, 10)) === false) {
newtime = calculateTime(starttime, timestamp);
padeditor.ace.replaceRange([i, 0], [i, 10], '' + newtime);
console.log('timestamp: ' + timestamp + ' time: ' + newtime);
}
}
}
}
})();
//export Pad to chapter file
javascript:(function () {
var padcontent = padeditor.ace.exportText();
function post_to_url(path, params) {
var form = cpWindow.document.createElement('form'),
hiddenField;
form.setAttribute('method', 'post');
form.setAttribute('action', path);
for (var key in params) {
if (params.hasOwnProperty(key)) {
hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'hidden');
hiddenField.setAttribute('name', key);
hiddenField.setAttribute('value', params[key]);
form.appendChild(hiddenField);
}
}
cpWindow.document.body.appendChild(form);
form.submit();
}
cpWindow = window.open('about:blank');
post_to_url('http://cdn.simon.waldherr.eu/projects/osf-parser-suite/api/', {
'amazon': 'shownot.es-21',
'thomann': '93439',
'fullmode': 1,
'pad': padcontent,
'download': 1,
'exportmode': 'chapter'
});
})();
//export Pad to anycast-full style HTML
javascript:(function () {
var padcontent = padeditor.ace.exportText();
function post_to_url(path, params) {
var form = cpWindow.document.createElement('form'),
hiddenField;
form.setAttribute('method', 'post');
form.setAttribute('action', path);
for (var key in params) {
if (params.hasOwnProperty(key)) {
hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'hidden');
hiddenField.setAttribute('name', key);
hiddenField.setAttribute('value', params[key]);
form.appendChild(hiddenField);
}
}
cpWindow.document.body.appendChild(form);
form.submit();
}
cpWindow = window.open('about:blank');
post_to_url('http://cdn.simon.waldherr.eu/projects/osf-parser-suite/api/', {
'amazon': 'shownot.es-21',
'thomann': '93439',
'fullmode': 1,
'pad': padcontent,
'download': 1,
'exportmode': 'anycast-full'
});
})();
//open Pad in Parser
javascript:(function () {
var padcontent = padeditor.ace.exportText();
function post_to_url(path, params) {
var form = cpWindow.document.createElement('form'),
hiddenField;
form.setAttribute('method', 'post');
form.setAttribute('action', path);
for (var key in params) {
if (params.hasOwnProperty(key)) {
hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'hidden');
hiddenField.setAttribute('name', key);
hiddenField.setAttribute('value', params[key]);
form.appendChild(hiddenField);
}
}
cpWindow.document.body.appendChild(form);
form.submit();
}
cpWindow = window.open('about:blank');
post_to_url('http://tools.shownot.es/parser/', {
'padcontent': padcontent
});
})();