forked from ChrisPei/nodebb-plugin-href2video
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
38 lines (33 loc) · 914 Bytes
/
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
'use strict'
;(function(VideoPlayer) {
var regExps = [
{
// local video
from: /<a href="\/(:*.*.(mp4|ogv|mov|webm))">local-player<\/a>/g,
// prettier-ignore
to: '<video src="/$1" controls preload autobuffer style="max-height: 450px;"/>'
}
]
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/html5media.min.js')
callback(null, scripts)
}
})(module.exports)