forked from lin1005q/nodebb-plugin-href2video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (42 loc) · 1.16 KB
/
index.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
'use strict'
;(function(VideoPlayer) {
var regExps = [
{
// local video
from: /<a href="\/(:*.*.(mp4|webm))">.*<\/a>/g,
// prettier-ignore
to: '<video src="/$1" controls="controls" controlsList="nodownload" preload="metadata" style="width: 100%;object-fit: contain;"/>'
},
{
// local audio
from: /<a href="\/(:*.*.(mp3|aac))">.*<\/a>/g,
// prettier-ignore
to: '<audio src="/$1" controls="controls" controlsList="nodownload" preload="metadata"/>'
}
]
VideoPlayer.parse = function(data, callback) {
if (!data || !data.postData || !data.postData.content) {
return callback(null, data)
}
var err = null
try {
for (var i = 0; i < regExps.length; i++) {
data.postData.content = data.postData.content.replace(
regExps[i].from,
regExps[i].to
)
}
} catch (e) {
err = e
}
callback(err, data)
}
/*
VideoPlayer.addScripts = function(scripts, callback) {
//TODO 判断是否支持 HTML5 video 标签
scripts.push('/static/html4media.min.js')
callback(null, scripts)
}
//guess this is not required
*/
})(module.exports)