forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '64d31b001934efdcaf8edbf4e87c97e7354bfd35' as 'YoduBGM'
- Loading branch information
Showing
5 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
/** | ||
* 一款简洁BGM播放器,需要您的主题支持pjax或者instantclick才能保证页面切换依旧播放 | ||
* | ||
* @package YoduBGM | ||
* @author Jrotty | ||
* @version 1.5.0 | ||
* @link http://qqdie.com/archives/typecho-yodubgm.html | ||
*/ | ||
class YoduBGM_Plugin implements Typecho_Plugin_Interface | ||
{ | ||
public static function activate() | ||
{ | ||
Typecho_Plugin::factory('Widget_Archive')->header = array('YoduBGM_Plugin', 'header'); | ||
Typecho_Plugin::factory('Widget_Archive')->footer = array('YoduBGM_Plugin', 'footer'); | ||
} | ||
/* 禁用插件方法 */ | ||
public static function deactivate(){} | ||
public static function config(Typecho_Widget_Helper_Form $form){ | ||
$bof = new Typecho_Widget_Helper_Form_Element_Radio( | ||
'bof', array('0'=> '不自动播放', '1'=> '自动播放'), 0, '播放设置', | ||
'自动播放顾名思义,就是页面打开后音乐就会自动播放'); | ||
$form->addInput($bof); | ||
|
||
$sxj = new Typecho_Widget_Helper_Form_Element_Radio( | ||
'sxj', array('0'=> '隐藏', '1'=> '不隐藏'), 0, '手机端是/否隐藏', | ||
''); | ||
$form->addInput($sxj); | ||
$musicList = new Typecho_Widget_Helper_Form_Element_Textarea('musicList', NULL, | ||
'',_t('歌曲列表'), _t(' | ||
<div style=" | ||
background: #fff; | ||
padding: 10px; | ||
margin-top: -0.5em; | ||
">填写格式<p><b>直链方式:</b><br>填写{mp3:"http:xxxx"}多首每个歌曲之间用英文,隔开,单首歌曲的话末尾则不用加逗号。</p> | ||
<p><b>调用网易云:</b><br>书写网易云歌曲id即可,多首歌曲的话请在两首歌曲id之间加换行,单首歌曲直接写id就行,千万别多加回车换行</p> | ||
<p><b>注意:</b><br>这两种填写方式不能混合输入,要么只用直链方式,要么只用网易云方式</p> | ||
<p><b>感谢:</b>https://api.imjad.cn/cloudmusic.md</p> | ||
</div> | ||
')); | ||
$form->addInput($musicList); | ||
} | ||
|
||
public static function personalConfig(Typecho_Widget_Helper_Form $form){} | ||
public static function header(){ | ||
$cssUrl = Helper::options()->pluginUrl . '/YoduBGM/css/player.css'; | ||
echo '<link rel="stylesheet" href="' . $cssUrl . '">'; | ||
if(Typecho_Widget::widget('Widget_Options')->Plugin('YoduBGM')->sxj=='0'){ | ||
echo '<style>@media only screen and (max-width:766px){.ymusic{display:none}}</style>'. "\n"; | ||
} | ||
} | ||
|
||
public static function footer(){ | ||
$options = Typecho_Widget::widget('Widget_Options')->plugin('YoduBGM'); $musicList = $options->musicList; | ||
if(empty($musicList)){ | ||
$musicList = "761323"; | ||
} | ||
|
||
if(strpos($musicList,'{mp3')===false){ | ||
$musicList = str_replace(PHP_EOL, '&br=128000&raw=ture"},{mp3:"//api.imjad.cn/cloudmusic/?type=song&id=', $musicList); | ||
$musicList = '{mp3:"//api.imjad.cn/cloudmusic/?type=song&id='.$musicList.'&br=128000&raw=ture"}'; | ||
$musicList = str_replace(array("\r\n", "\r", "\n", " "), "", $musicList); | ||
} | ||
if(strpos($musicList,',')===false){ | ||
|
||
echo ' | ||
<bgm> | ||
<a class="ymusic" onclick="playbtu();" target="_blank"><i id="ydmc"></i></a> | ||
</bgm> | ||
'; | ||
}else{ | ||
|
||
echo ' | ||
<bgm> | ||
<a class="ymusic" onclick="playbtu();" target="_blank"><i id="ydmc"></i></a><a class="ymusic" onclick="next();" id="ydnext" target="_blank"><i class="iconfont icon-you"></i></a> | ||
</bgm> | ||
'; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
echo '<script data-no-instant> | ||
var yaudio = new Audio(); | ||
yaudio.controls = true; | ||
var musicArr=[ | ||
'.$musicList.' | ||
]; | ||
/*首次随机播放*/ | ||
var a=parseInt(Math.random()*musicArr.length); | ||
var sj=musicArr[a]; | ||
yaudio.src=sj.mp3; | ||
'; | ||
if(Typecho_Widget::widget('Widget_Options')->Plugin('YoduBGM')->bof=='1'){ | ||
echo 'yaudio.play();</script>'. "\n"; | ||
}else{ echo '</script>'. "\n"; | ||
} | ||
echo '<script src="'.Helper::options()->pluginUrl . '/YoduBGM/js/player.js" data-no-instant></script><script src="'.Helper::options()->pluginUrl . '/YoduBGM/js/prbug.js"></script>' . "\n"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
这个是typecho博客插件 | ||
|
||
## 插件特色 | ||
1,这是一款简洁BGM播放器,需要您的主题支持pjax或者instantclick才能保证页面切换依旧播放 | ||
|
||
2,支持多首歌曲,且默认随机播放 | ||
|
||
3,可设置是否自动播放(部分手机浏览器不支持) | ||
|
||
4,支持网易云音乐调用(不保证api永远有效) | ||
|
||
5,当你按照格式只填写一首歌曲时,插件会默认隐藏掉切歌按钮,只保留播放按钮,使其更加简洁 | ||
|
||
6,插件使用了原生js,所以无需加载jq等js框架 | ||
|
||
7,整个插件所需要加载的文件不到5kb,可谓是非常小巧了 | ||
|
||
## 使用方法 | ||
下载压缩包, 解压,得到名为YoduBGM的文件夹,如果不是请将文件夹重命名为YoduBGM ,之后上传到你博客中的 /usr/plugins 目录,在后台启用即可 | ||
|
||
插件后台配置歌曲格式: | ||
|
||
{mp3:"http:xxxx"} ,**多个歌曲之间用英文,隔开**。 | ||
|
||
## 添加网易云音乐 | ||
直接填写单个歌曲id即可,**多个id之间用回车隔开** | ||
|
||
## 感谢 | ||
api提供:https://api.imjad.cn/cloudmusic.md | ||
|
||
## 1.5.0升级内容 | ||
1,字体图标文件全部写入了css里,解决特殊情况下的字体跨域问题 | ||
|
||
2,复活网易云调用功能 | ||
|
||
3,加了了歌曲数量判断,大于一首歌曲时,切歌按钮才会出来,使其更加简洁人性化 | ||
|
||
4,js梳理优化,缩减代码,解决部分bug | ||
|
||
|
||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function playbtu(){ | ||
var oyd = document.getElementById('ydmc'); | ||
if (yaudio.paused) { | ||
yaudio.play(); | ||
oyd.className = 'iconfont icon-music'; | ||
} else { | ||
yaudio.pause(); | ||
oyd.className = 'iconfont icon-bofang'; | ||
} | ||
} | ||
function next() { | ||
var oyd=document.getElementById('ydmc'); | ||
if (a == musicArr.length - 1) { | ||
a = 0 | ||
} else { | ||
a = a + 1 | ||
} | ||
var sj = musicArr[a]; | ||
yaudio.src = sj.mp3; | ||
yaudio.play();var autopause=0; | ||
oyd.className = 'iconfont icon-music'; | ||
} | ||
|
||
yaudio.addEventListener('ended', | ||
function() { | ||
next(); | ||
}, | ||
false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var ody=document.getElementById('ydmc'); | ||
if (yaudio.paused) { | ||
ody.className = 'iconfont icon-bofang'; | ||
} else { | ||
ody.className = 'iconfont icon-music'; | ||
} |