-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmkv.js
248 lines (244 loc) · 9.43 KB
/
mkv.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// @ts-check
; (() => {
const SCRIPT_KEY = 'mkv_toolkit'
class ToolkitModule {
constructor() { }
isActive = true
/**
* create DOM
* @param {string} tagName
* @param {string} id
* @param {object} param2
* @returns {Element} dom
*/
createElement(tagName, id, { classList, props, sheets, innerText } = {}) {
const dom = document.createElement(tagName)
if (id) dom.id = id
if (Array.isArray(classList)) {
for (const c of classList) {
dom.classList.add(c)
}
}
if (props) {
for (const p in props) {
dom.setAttribute(p, props[p])
}
}
if (sheets) {
for (const s in sheets) {
dom.style.setProperty(s, sheets[s])
}
}
if (innerText) dom.innerText = innerText
return dom
}
}
class Sheets {
static append(key, sheets) {
const sheet = document.createTextNode(sheets)
const el = document.createElement('style')
el.id = SCRIPT_KEY + '_' + key
el.appendChild(sheet)
document.head.appendChild(el)
}
}
/**
* SearchUI
*/
class SearchUIModule extends ToolkitModule {
constructor() { super() }
get isActive() { return location.href.indexOf('http://www.mtv-ktv.net/v/pan.asp') === 0 || location.href.indexOf('http://www.mtv-ktv.com/v/pan.asp') === 0 }
init(ctx) {
}
async onload(ctx) {
$.getJSON = url => {
const command = `curl '${url}' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: ${location.href}' -H 'User-Agent: ${navigator.userAgent.replace(/\d/, Math.random())}'`
const timeDOM = document.querySelector('.fs--1.mb-1')
timeDOM.id = 'command-curl'
timeDOM.innerText = command
this.toCopyText(command)
throw new Error('已生成 curl 命令')
}
for (let times = 40; times--;) {
const downloadDOM = document.querySelector('.btn.btn-outline-secondary.fs--1')
await Toolkit.delay(300)
if (!downloadDOM) continue
downloadDOM.click()
break
}
for (let times = 40; times--;) {
const textareaFormDOM = document.querySelector('form#register-form')
await Toolkit.delay(300)
if (!textareaFormDOM) continue
this.includeTextarea(textareaFormDOM)
break
}
}
toCopyText(text) {
var tag = document.createElement('input')
tag.setAttribute('id', 'cp_hgz_input')
tag.value = text
document.getElementsByTagName('body')[0].appendChild(tag)
document.getElementById('cp_hgz_input').select()
document.execCommand('copy')
document.getElementById('cp_hgz_input').remove()
}
includeTextarea(textareaFormDOM) {
textareaFormDOM.innerHTML = ''
const textarea = this.createElement('textarea', 'response', { sheets: { width: '100%', height: '100%' } })
const downloadLink = this.createElement('a', 'download-link')
const wgetCommand = this.createElement('textarea', 'wget-command', { sheets: { width: '100%', height: '200px' } })
downloadLink.setAttribute('href', 'javascript:;')
downloadLink.setAttribute('target', '_blank')
downloadLink.innerText = '等待解析下载地址'
textarea.addEventListener('paste', e => {
const responseClipboard = e.clipboardData || window.clipboardData
const response = responseClipboard.getData('Text')
let downloadURL = ''
const res = JSON.parse(response)
downloadURL = res.downurl
console.log(downloadURL, res)
if (downloadURL) {
downloadLink.setAttribute('href', downloadURL)
wgetCommand.value = this.getWgetCommand(downloadURL)
}
})
textareaFormDOM.appendChild(textarea)
textareaFormDOM.appendChild(downloadLink)
textareaFormDOM.appendChild(wgetCommand)
}
getWgetCommand(downloadURL) {
const fileName = document.title.replace(/\.mkv\s.*/, '.mkv')
return `wget -O '${fileName}' '${downloadURL}'`
}
}
/**
* to download url
*/
class ToDownloadPageModule extends ToolkitModule {
constructor() { super() }
get isActive() { return location.href.indexOf('http://www.mtv-ktv.net/v/ctfile.asp') === 0 || location.href.indexOf('http://www.mtv-ktv.com/v/ctfile.asp') === 0 }
sheets = `
.oset > a { display: none; }
.oset > span { cursor: pointer; }
`
init(ctx) {}
async onload(ctx) {
Sheets.append('download', this.sheets)
for (let times = 30; times--;) {
const rows = document.querySelectorAll('.oset')
await Toolkit.delay(300)
if (!rows) continue
this.appendDownloadLink()
break
}
}
appendDownloadLink() {
const rows = document.querySelectorAll('.oset')
if (!rows) return
for (const r of Array.from(rows)) {
const rowDOM = this.createElement('span', undefined, { classList: ['row-link'], innerText: '下载' })
rowDOM.addEventListener('click', async evt => {
const link = evt.target.previousSibling
if (!link) return
let downloadURL = link.getAttribute('data-download-url')
if (!link.getAttribute('data-download-url')) {
downloadURL = await this.toDownloadPage(link.href)
link.setAttribute('data-download-url', downloadURL)
link.setAttribute('href', downloadURL)
}
if (downloadURL) link.click()
})
r.appendChild(rowDOM)
}
}
async toDownloadPage(url) {
const res = await fetch(url, { method: 'GET' })
const rawText = await res.text()
// href="https://mvxzjl.ctfile.com/fs/
const matches = rawText.match(/href\=\"(https:\/\/mvxzjl\.ctfile\.com\/fs\/[\d\-]*)"/)
return matches[1]
}
}
/**
* n456 pan page
*/
class DownloadPanModule extends ToolkitModule {
constructor() { super() }
get isActive() { return location.href.indexOf('https://n459.com/file/') === 0 || location.href.indexOf('https://tv5.us/file') === 0 || location.href.indexOf('https://545c.com/file') === 0 }
init(ctx) {
const songList = this.createElement('div', 'sont-list', {
sheets: {
width: '20px',
height: '95vh',
position: 'fixed',
top: '0',
left: '0',
// 'background-color': 'teal'
}
})
document.body.appendChild(songList)
}
onload(ctx) {
ctx.log('onload')
}
}
class MvxzModule extends ToolkitModule {
constructor() { super() }
get isActive() { return location.href.indexOf('http://mvxz.com/imv.asp') === 0 }
init() {}
async onload(ctx) {
for (let times = 40; times--;) {
const btn = document.querySelector('.button.special.fit.icon.fa-download')
await Toolkit.delay(300)
if (!btn) continue
btn.setAttribute('href', 'javascript:;')
break
}
}
}
/**
* 工具类
*/
class Toolkit {
debug = true
options = {}
users = {}
constructor(options = {}) {
Object.assign(this.options, options)
this.emitHook('init')
}
/**
* 工具集
*/
static modules = []
/**
* 注册工具模块
*/
static use(moduleItem) {
// 禁用未激活的模块
if (!moduleItem.isActive) return
Array.isArray(moduleItem) ? moduleItem.map(item => Toolkit.use(item)) : Toolkit.modules.push(moduleItem)
}
/**
* 触发钩子函数
* @param {string} hook 钩子函数名
*/
emitHook(hook) {
this.log('触发钩子函数: ' + hook, Toolkit.modules.length)
Toolkit.modules.map(module => module[hook] && typeof module[hook] === 'function' && module[hook](this))
}
log(...args) {
console.log('%c[MKV Toolkit] LOG: ', 'color:teal', ...args)
}
static delay(timeout = 200) {
return new Promise(resolve => setTimeout(resolve, timeout))
}
}
Toolkit.use(new SearchUIModule())
Toolkit.use(new ToDownloadPageModule())
Toolkit.use(new DownloadPanModule())
Toolkit.use(new MvxzModule())
window._$MKVToolkit = new Toolkit()
window.addEventListener('DOMContentLoaded', () => window._$MKVToolkit.emitHook('onload'))
})();