Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dixyes committed Oct 21, 2017
1 parent b40f834 commit 49713da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ for example:

{% dplayer "url=http://devtest.qiniudn.com/若能绽放光芒.mp4" "addition=https://dplayer.daoapp.io/bilibili?aid=4157142" "api=http://dplayer.daoapp.io" "pic=http://devtest.qiniudn.com/若能绽放光芒.png" "id=9E2E3368B56CDBB4" "loop=yes" "theme=#FADFA3" "autoplay=false" "token=tokendemo" %}
{% dplayer "url=http://devtest.qiniudn.com/若能绽放光芒.mp4" "addition=https://dplayer.daoapp.io/bilibili?aid=4157142" "api=http://dplayer.donot.help/dplayerpy" "pic=http://devtest.qiniudn.com/若能绽放光芒.png" "id=2622668" "loop=yes" "theme=#FADFA3" "autoplay=false" "width=233px" %}
{% dplayer 'url=some.mp4' "id=someid" "api=https://api.prprpr.me/dplayer/" "addition=/some.json" 'code=player.on("loadstart",function(){console.log("loadstart")})' "autostart" %}
{% dplayer 'url=some.mp4' "id=someid" "api=https://api.prprpr.me/dplayer/" "addition=/some.json" 'code=player.on("loadstart",function(){console.log("loadstart")})' "autoplay" %}

## Customization

Expand Down
29 changes: 16 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,21 @@ hexo.extend.filter.register('after_render:html', (str, data) => {
// {% dplayer key=value ... %}
hexo.extend.tag.register('dplayer', (args) => {

const conf = (hexo.config['hexo-tag-dplayer'] || {})['default'] || {};
const def = conf['default'] || {};
//console.log(def)

var id = 'dplayer' + (counter++), opt = {};

for (var i in args) {
var k = args[i].split('=')[0],
v = args[i].slice(args[i].indexOf('=')+1);
v = args[i].split("=").length < 2 ? "true" : args[i].slice(args[i].indexOf('=')+1);
if (['autoplay', 'loop', 'screenshot', 'hotkey', 'mutex', 'dmunlimited'].indexOf(k) >= 0){
// bool
v = v.toLowerCase();
opt[k] = ['true', 'yes', '1', 'y', 'on', true].indexOf(v) >= 0;
opt[k] = ['true', 'yes', '1', 'y', 'on', ''].indexOf(v) >= 0;
} else if (['preload', 'theme', 'lang', 'logo', 'url', 'pic', 'thumbnails', 'vidtype', 'suburl', 'subtype', 'subbottom', 'subcolor', 'subcolor', 'id', 'api', 'token', 'addition', 'dmuser', 'width', 'height', 'code'].indexOf(k) >= 0){
// string
opt[k] = v;
opt[k] = v.toString();
} else if (['volume', 'maximum'].indexOf(k) >= 0){
// number
opt[k] = Number(v) || undefined;
Expand All @@ -110,9 +111,9 @@ hexo.extend.tag.register('dplayer', (args) => {
}
}

const width = opt.width || conf.width,
height = opt.height || conf.height;
var url = opt.url || conf.url;
const width = opt.width || def.width,
height = opt.height || def.height;
var url = opt.url || def.url;
var raw = '<div id="'+ id + '" class="dplayer" style="margin-bottom: 20px;'+(width ?' width:'+width+';':'')+(height?' height:'+height+';':'')+'"></div>';
if(url != undefined){
if (hexo.config['post_asset_folder'] == true ){
Expand Down Expand Up @@ -163,23 +164,25 @@ hexo.extend.tag.register('dplayer', (args) => {
icons: 'icons',
contextmenu: 'menu',
},(k,v)=>{
//console.log("k",k,"v",v,"?",opt[k],"?a", conf[k])
//console.log("k",k,"v",v,"?",opt[k],"?a", def[k])
if (typeof v === 'string') {
if (v !== "document.getElementById('')"){
return opt[v] || conf[v];
return opt[v] || def[v];
} else {
return v;
}
} else if (k === "subtitle" && !(opt.suburl || conf.suburl)) {
} else if (k === "subtitle" && !(opt.suburl || def.suburl)) {
return undefined;
} else if (k === "danmaku" && !(opt.api || conf.api)) {
} else if (k === "danmaku" && !(opt.api || def.api)) {
return undefined;
} else if (k === "addition" && !(opt.addition || def.addition)) {
return undefined;
} else {
return v;
}
}).replace("\"document.getElementById('')\"",'document.getElementById("'+ id +'")') +
');' + (opt.code || conf.code || '') + '</script>';
//console.log(opt.code,conf.code,(opt.code || conf.code || ''))
');' + (opt.code || def.code || '') + '</script>';
//console.log(opt.code,def.code,(opt.code || def.code || ''))
}
else{
raw += '<p>no url specified, no dplayer _(:3」∠)_</p>';
Expand Down

0 comments on commit 49713da

Please sign in to comment.