@@ -121,8 +121,9 @@ function themeConfig($form)
121121<script src=" $ theme_url/js/jquery.min.js"></script>
122122<script src=" $ theme_url/js/bootstrap.min.js"></script>
123123<hr>
124- <p class="active-tab"><strong><svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-project"></use></svg> WebStack 网址导航 Typecho 主题</strong></p>
125- <p class="previous-tab"><strong><svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-chicken"></use></svg> 主题版本号: </strong> $ v_time</p>
124+ <p><strong><svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-project"></use></svg> WebStack 网址导航 Typecho 主题</strong></p>
125+ <p><strong><svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-chicken"></use></svg> 主题版本号: </strong> $ v_time<span class="new_version_span" style="margin-left:25px;"></span></p>
126+ <p><button class="check_update_btn btn">检查更新</button></p>
126127<hr>
127128<ul id="myTab" class="nav nav-tabs">
128129<li class="active"><a href="#home" data-toggle="tab">备份与恢复</a></li>
@@ -154,6 +155,48 @@ function themeConfig($form)
154155<svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-set"></use></svg>
155156<b>提示:主题设置选择后回车可快捷保存</b>
156157<hr>
158+ <script type="text/javascript">
159+ const checkUpdateBtn = document.querySelector('.check_update_btn');
160+ const newVersionSpan = document.querySelector('.new_version_span');
161+ const curVersion = ' $ v_time';
162+ if (checkUpdateBtn && newVersionSpan) {
163+ checkUpdateBtn.addEventListener('click', e => {
164+ e.stopPropagation();
165+ fetch('https://api.github.com/repos/LightAPIs/WebStackTypechoTheme/releases/latest')
166+ .then(res => res.json())
167+ .then(json => {
168+ const tagName = json.tag_name;
169+ if (tagName && tagName.startsWith('v')) {
170+ const tag = tagName.replace('v', '');
171+ const cur = curVersion.split('.');
172+ const next = tag.split('.');
173+ if (cur.length >= 3 && next.length >= 3) {
174+ let isUpdate = false;
175+ for (let i = 2; i >= 0; i--) {
176+ if (cur[i] < next[i]) {
177+ isUpdate = true;
178+ } else if (cur[i] > next[i]) {
179+ isUpdate = false;
180+ }
181+ }
182+ if (isUpdate) {
183+ newVersionSpan.innerHTML = '<a href="https://github.com/LightAPIs/WebStackTypechoTheme/releases/latest" target="_blank">前往下载新板本:' + tag + '</a>';
184+ } else {
185+ newVersionSpan.textContent = '当前已是最新版本。'
186+ }
187+ } else {
188+ newVersionSpan.textContent = '版本号格式不正确!'
189+ }
190+ } else {
191+ newVersionSpan.textContent = '无法查询到版本号!'
192+ }
193+ })
194+ .catch(_e => {
195+ newVersionSpan.textContent = '检查更新出错!'
196+ })
197+ })
198+ }
199+ </script>
157200EOD ;
158201
159202 // 左侧 logo
0 commit comments