-
Notifications
You must be signed in to change notification settings - Fork 0
/
VEED.io_Sub_downloader.js
108 lines (96 loc) · 3.83 KB
/
VEED.io_Sub_downloader.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
// ==UserScript==
// @name VEED.io Sub downloader
// @namespace https://github.com/erfanva/
// @version 0.21
// @description Free download autogenerated VEED.io subtitles
// @author erfanva
// @match https://www.veed.io/*
// @grant none
// @updateURL https://github.com/erfanva/Tools/raw/master/VEED.io_Sub_downloader.js
// ==/UserScript==
(function () {
'use strict';
const autoDownload = true;
// save file from console;
(function (console) {
console.save = function (data, filename) {
if (!data) {
console.error('Console.save: No data')
return;
}
if (!filename) filename = 'console.json'
if (typeof data === "object") {
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], { type: 'text/json' }),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)
let interval1, interval2
function extract(container) {
console.log('extract')
return new Promise((resolve, reject) => {
container.scroll(0, 0)
// let subs = {}
let haveIndex = {}
let subStr = ''
let count2 = 0
interval2 = setInterval(() => {
if (count2++ > 6000 || container.scrollTop + container.clientHeight >= container.scrollHeight) {
clearInterval(interval2)
// resolve(subs)
resolve(subStr)
}
const subsTemp = container.querySelectorAll('div[data-testid]')
subsTemp.forEach(temp => {
try {
const index = temp.getAttribute('data-testid').split('subtitle-row-')[1]
const times = temp.querySelectorAll('input[data-testid]')
let from = times[0].value.replace('.', ',') + '00'
if (from.split(':').length < 3) {
from = '00:' + from
}
let to = times[1].value.replace('.', ',') + '00'
if (to.split(':').length < 3) {
to = '00:' + to
}
const text = temp.querySelector('textarea').value
// subs[index] = { from, to, text }
if (!haveIndex[index]) {
subStr += `${index}\n`
subStr += `${from} --> ${to}\n`
subStr += `${text}\n\n`
}
haveIndex[index] = true
}
catch (e) {
}
})
container.scroll(0, container.scrollTop + container.clientHeight)
}, 100)
})
}
console.log('start')
interval1 = setInterval(() => {
if (autoDownload) {
var btn = document.querySelector('button[data-testid="@editor/subtitles-option/automatic"]') ||
document.querySelector('div.edit-controls button');
if (btn) {
btn.click()
}
}
let container = document.querySelector('div.subtitle-rows-list')
if (container) {
clearInterval(interval1)
extract(container).then((subs) => {
console.save(subs, 'sub.srt')
})
}
}, 1000)
})();