summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBigCoke233 <hi@guhub.cn>2020-04-15 12:00:52 +0800
committerBigCoke233 <hi@guhub.cn>2020-04-15 12:00:52 +0800
commitae0351105cebf8a3787d8ebb454a25f80dbe0e6d (patch)
tree2c3095a61f5a4f36605724fad6de2736107b4950
parent01b8ec4b5b509a5355b4dd3ca3b914f029e5ee77 (diff)
:angel: Add: 自动检测更新
-rw-r--r--assets/css/setting.miracles.css4
-rw-r--r--assets/js/update.miracles.js41
-rw-r--r--index.php4
-rwxr-xr-xlibs/Options.php10
4 files changed, 54 insertions, 5 deletions
diff --git a/assets/css/setting.miracles.css b/assets/css/setting.miracles.css
index e89430d..7d293d6 100644
--- a/assets/css/setting.miracles.css
+++ b/assets/css/setting.miracles.css
@@ -75,6 +75,10 @@ hr {
font-size: 1.06em
}
+.waiting {
+ color: rgb(230,230,230)
+}
+
@-webkit-keyframes slideDown {
0%{
bottom: -100px;
diff --git a/assets/js/update.miracles.js b/assets/js/update.miracles.js
new file mode 100644
index 0000000..da7e21e
--- /dev/null
+++ b/assets/js/update.miracles.js
@@ -0,0 +1,41 @@
+(function($){
+ var api = "https://api.github.com/repos/BigCoke233/miracles/releases";
+ $.ajax({
+ url: api,
+ type: "GET",
+ dataType: "json",
+ success:function(data){
+ var latest = data[0]['tag_name'];
+ var assets_url = data[0]['assets_url'];
+
+ if(version==latest){
+ $("#miracles-update").html(",你已经是最新版了!");
+ }
+ else if(version<latest){
+ $("#miracles-update").html(",有可下载的新版本("+latest+")");
+ $.ajax({
+ url: assets_url,
+ type: "GET",
+ dataType: "json",
+ success:function(assets_data){
+ var downlink = assets_data[0]['browser_download_url'];
+ $("#miracles-update").append(',<a href="'+downlink+'" class="miracles-update-down">点击下载最新版</a>。');
+ }
+ });
+ }
+ else if(version>latest){
+ $("#miracles-update").html(",看起来你是在使用开发版。");
+ }
+ else {
+ $("#miracles-update").html(",哇哦,你个 BigHack,居然召唤了根本不可能的错误。");
+ }
+ console.log("Miracles 最新发行版:"+latest);
+ $("#miracles-update").removeClass("waiting");
+ },
+ error:function(){
+ $("#miracles-update").html("最新版本获取失败,刷新试试?");
+ $("#miracles-update").removeClass("waiting").css('color', 'red');
+
+ }
+ });
+})(jQuery); \ No newline at end of file
diff --git a/index.php b/index.php
index c146ddb..6b72be4 100644
--- a/index.php
+++ b/index.php
@@ -1,11 +1,11 @@
<?php
/**
* Born to be the Miracles. 生为奇迹
- * 作者:<a href="https://guhub.cn">Eltrac</a> | 帮助文档:<a href="https://www.notion.so/eltrac/c7c631e21b3345caa2a09bd2fb5dd4b2">GitHub Wiki</a>
+ * 作者:<a href="https://guhub.cn">Eltrac</a> | 帮助文档:<a href="https://www.notion.so/eltrac/c7c631e21b3345caa2a09bd2fb5dd4b2">Wiki</a>
*
* @package Miracles
* @author Eltrac
- * @version 1.5.1
+ * @version 1.5.2
* @link https://guhub.cn
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
diff --git a/libs/Options.php b/libs/Options.php
index 8e7efc3..b8e1b07 100755
--- a/libs/Options.php
+++ b/libs/Options.php
@@ -48,10 +48,14 @@ function themeConfig($form) {
*/
$ver = themeVersion();
$themeDir = "/usr/themes/Miracles/";
- echo '<link rel="stylesheet" href="'.$themeDir.'assets/css/setting.miracles.css"><link href="https://fonts.googleapis.com/css?family=Noto+Sans+SC:300|Noto+Serif+SC:300&display=swap" rel="stylesheet">';
+ echo '<link rel="stylesheet" href="'.$themeDir.'assets/css/setting.miracles.css">
+ <link href="https://fonts.googleapis.com/css?family=Noto+Sans+SC:300|Noto+Serif+SC:300&display=swap" rel="stylesheet">
+ <script>var version = "'. $ver .'";</script>
+ <script src="'.$themeDir.'assets/js/jquery.js"></script>
+ <script src="'.$themeDir.'assets/js/update.miracles.js"></script>';
echo '<div class="miracles-pannel">
<h1>Miracles 主题设置面板</h1>
- <p>欢迎使用 Miracles 主题,目前版本是:'. $ver .'<br>
+ <p>欢迎使用 Miracles 主题,目前版本是:'. $ver .'<span id="miracles-update" class="waiting">,正在获取最新版本号......</span><br>
作者博客:<a href="https://guhub.cn">Eltrac\'s</a> |
帮助文档:<a href="https://www.notion.so/thememiracles/c7c631e21b3345caa2a09bd2fb5dd4b2">WIKI</a> |
问题反馈:<a href="https://github.com/BigCoke233/miracles/issues">issues</a></p>
@@ -152,7 +156,7 @@ function themeConfig($form) {
$form->addInput($bodyFonts);
$randomBanner = new Typecho_Widget_Helper_Form_Element_Textarea('randomBanner', NULL, NULL, _t('随机文章缩略图'), _t('文章没有独立设置头图时调用,写入图片链接,用半角逗号分割'));
$form->addInput($randomBanner);
-
+
//LoadingImage
$LoadingOptions = [
'block' => "交错方块",