Skip to content

Commit

Permalink
add theme, hotkey, screenshot options, adapt to 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
dixyes committed Aug 23, 2016
1 parent 54e4dc8 commit 312b7ee
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 57 deletions.
46 changes: 42 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

借鉴项目:https://github.com/grzhan/hexo-tag-aplayer

这个项目的两个维护者一个只会卖萌,一个又很忙(这是豆子)
这个项目的两个维护者一个只会卖萌,一个又沉迷屁股(这是豆子)

所以有什么bug很长时间没解决的,请谅解

Expand All @@ -34,13 +34,18 @@ Embed DPlayer([https://github.com/DIYgod/DPlayer](https://github.com/DIYgod/DPla

key can be

'autoplay': will play automatic or not
'loop': will loop or not
'url': video source url
'autoplay': autoplay video, not supported by mobile browsers
'theme': theme color, default: #b7daff
'loop': loop play music, default: true
'lang': language, `zh` for Chinese, `en` for English, default: Navigator language
'screenshot': enable screenshot function, default: false, NOTICE: if set it to true, video and video poster must enable Cross-Origin
'hotkey': binding hot key, including left right and Space, default: true
'url': Required, video url
'pic': video cover picture
'api': DPlayer danmaku backend url
'id': see https://github.com/DIYgod/DPlayer
'token': see https://github.com/DIYgod/DPlayer
'maxinum': maximum quantity of danmaku

for example:

Expand All @@ -50,6 +55,39 @@ for example:

You can modify variables `scriptDir`(default: "/assets/js/" ) and `styleDir`(default: "/assets/css/") in `index.js` according to your blog's directory structure.

## Issue

If any issue occurs, tell me via issue, use a hexo raw tag like below to use dplayer:

{% raw %}
<div id="player1" class="dplayer"></div>
<script src="dist/DPlayer.min.js"></script><!-- use your path -->
<script>
var option = {
element: document.getElementById('player1'), // Optional, player element
autoplay: false, // Optional, autoplay video, not supported by mobile browsers
theme: '#FADFA3', // Optional, theme color, default: #b7daff
loop: true, // Optional, loop play music, default: true
lang: 'zh', // Optional, language, `zh` for Chinese, `en` for English, default: Navigator language
screenshot: true, // Optional, enable screenshot function, default: false, NOTICE: if set it to true, video and video poster must enable Cross-Origin
hotkey: true, // Optional, binding hot key, including left right and Space, default: true
video: { // Required, video info
url: '若能绽放光芒.mp4', // Required, video url
pic: '若能绽放光芒.png' // Optional, music picture
},
danmaku: { // Optional, showing danmaku, ignore this option to hide danmaku
id: '9E2E3368B56CDBB4', // Required, danmaku id, NOTICE: it must be unique, can not use these in your new player: `https://dplayer.daoapp.io/list`
api: 'https://dplayer.daoapp.io/', // Required, danmaku api
token: 'tokendemo', // Optional, danmaku token for api
maximum: 1000 // Optional, maximum quantity of danmaku
}
}
var dp = new DPlayer(option);
</script>
{% endraw %}

see [DPlayer](https://github.com/DIYgod/DPlayer) for usage detail

## Todo

- [x] Publish it to the [hexo plugin list](https://hexo.io/plugins) and npm
Expand Down
134 changes: 83 additions & 51 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
* Syntax:
* {% dplayer key=value ... %}
*/
'use strict'
var fs = require('hexo-fs'),
util = require('hexo-util'),
path = require('path'),
counter = 0,
srcDir = path.dirname(require.resolve('dplayer')),
scriptDir = 'assets/js/',
scriptDir = 'assets/js/', //change this and below to change js and css dir
styleDir = 'assets/css/',
dplayerScript = 'DPlayer.min.js',
dplayerStyle = 'DPlayer.min.css',
Expand Down Expand Up @@ -53,57 +54,88 @@ hexo.extend.filter.register('after_post_render', function(data) {

// {% dplayer key=value ... %}
hexo.extend.tag.register('dplayer', function(args) {
var url = 'null', api = 'null', loop = false, autoplay = false, theme = "null", pic="null", did="null", token="null";
id = 'dplayer' + (counter++);
raw = '<div id="'+ id + '" class="dplayer" style="margin-bottom: 20px;"></div>';
for (var i = 0; i < args.length; ++i) {
arg=args[i];
if(arg.split('=').length<2)
continue;
switch(arg.split('=')[0]){
case 'autoplay':
if(arg.split('=')[1]=='true'||arg.split('=')[1]=='yes'||arg.split('=')[1]=='1')
autoplay = true;
break;
case 'loop':
if(arg.split('=')[1]=='true'||arg.split('=')[1]=='yes'||arg.split('=')[1]=='1')
loop = true;
break;
case 'url':
url = arg.slice(arg.indexOf("=")+1);
break;
case 'pic':
pic = arg.slice(arg.indexOf("=")+1);
break;
case 'api':
api = arg.slice(arg.indexOf("=")+1);
break;
case 'id':
did = arg.slice(arg.indexOf("=")+1);
break;
case 'token':
token = arg.slice(arg.indexOf("=")+1);
break;
}
var url=undefined, api=undefined, loop=undefined, autoplay=undefined, theme=undefined, pic=undefined, did=undefined, token=undefined, screenshot=undefined, lang=undefined, maxinum=undefined, hotkey=undefined;
var id = 'dplayer' + (counter++),
raw = '<div id="'+ id + '" class="dplayer" style="margin-bottom: 20px;"></div>';
for (var i = 0; i < args.length; ++i) {
var arg=args[i];
if(arg.split('=').length<2)
continue;
switch(arg.split('=')[0]){
case 'autoplay':
if(arg.split('=')[1]=='true'||arg.split('=')[1]=='yes'||arg.split('=')[1]=='1')
autoplay = true;
else
autoplay = false;
break;
case 'theme':
theme = arg.slice(arg.indexOf("=")+1);
break;
case 'loop':
if(arg.split('=')[1]=='true'||arg.split('=')[1]=='yes'||arg.split('=')[1]=='1')
loop = true;
else
loop = false;
break;
case 'lang':
lang = arg.slice(arg.indexOf("=")+1);
break;
case 'screenshot':
if(arg.split('=')[1]=='true'||arg.split('=')[1]=='yes'||arg.split('=')[1]=='1')
screenshot = true;
else
screenshot = false;
break;
case 'hotkey':
if(arg.split('=')[1]=='true'||arg.split('=')[1]=='yes'||arg.split('=')[1]=='1')
hotkey = true;
else
hotkey = false;
break;
case 'url':
url = arg.slice(arg.indexOf("=")+1);
break;
case 'pic':
pic = arg.slice(arg.indexOf("=")+1);
break;
case 'api':
api = arg.slice(arg.indexOf("=")+1);
break;
case 'id':
did = arg.slice(arg.indexOf("=")+1);
break;
case 'token':
token = arg.slice(arg.indexOf("=")+1);
break;
case 'maxinum':
maxinum = arg.slice(arg.indexOf("=")+1);
break;
}
}

raw +=
'<script>var '+ id + ' = new DPlayer({'+
'element: document.getElementById("'+ id +'"),' +
'autoplay: ' + (autoplay ? 'true' : 'false') + ',' +
'loop: ' + (loop ? 'true' : 'false') +
(theme == 'null' ? '': ',theme: "' + theme + '"') +
',video : {' +
'url: "'+ url + '"' +
(pic == 'null' ? '': ',pic: "'+ pic + '"') +
'}' +
(api == 'null' ? ' ':
',danmaku : {' +
'api: "'+ api + '"' +
(did == 'null' ? '': ',id: "'+ did + '"') +
(token == 'null' ? '': ',token: "'+ token + '"') +
'}') +
'});' +
id + '.init();</script>';
if(url != undefined)
raw += '<script>var '+ id + ' = new DPlayer('+
JSON.stringify({
element: "document.getElementById('')",
autoplay: autoplay,
theme: theme,
loop: loop,
lang: ((lang == 'zh' | lang == 'en') ? lang : undefined),
screenshot: screenshot,
hotkey: hotkey,
video: {
url: url,
pic: pic
},
danmaku: (api == undefined ? undefined :{
api: api,
id: did,
token: token,
maxinum: maxinum
})
}).replace("\"document.getElementById('')\"",'document.getElementById("'+ id +'")') +
');</script>';
else
raw += '<p>no url specified, no dplayer _(:3」∠)_</p>';
return raw;
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-tag-dplayer",
"version": "0.0.4",
"version": "0.1.0",
"description": "Embed dplayer in Hexo posts/pages",
"main": "index.js",
"scripts": {
Expand All @@ -25,7 +25,7 @@
},
"homepage": "https://github.com/NextMoe/hexo-tag-dplayer#readme",
"dependencies": {
"dplayer": "^1.0.4",
"dplayer": "^1.0.6",
"hexo-fs": "^0.1.3",
"hexo-util": "^0.1.7"
}
Expand Down

0 comments on commit 312b7ee

Please sign in to comment.