From 7c083a8a58802682ffc2e10dbe6398556c130802 Mon Sep 17 00:00:00 2001 From: "1152958806@qq.com" <17683872107czx> Date: Mon, 4 Sep 2023 17:50:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=9A=8F=E6=9C=BA=E5=8F=8B?= =?UTF-8?q?=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/assets/js/heo.js | 26 ++++++++------ templates/assets/zhheo/blogex.js | 54 ++++++++++++++++------------- templates/assets/zhheo/rightmenu.js | 2 +- templates/modules/head.html | 14 -------- 4 files changed, 46 insertions(+), 50 deletions(-) diff --git a/templates/assets/js/heo.js b/templates/assets/js/heo.js index 47711224..813fd679 100644 --- a/templates/assets/js/heo.js +++ b/templates/assets/js/heo.js @@ -67,19 +67,23 @@ var heo = { // 页脚友链 addFriendLinksInFooter: function () { + const fetchUrl = "/apis/api.plugin.halo.run/v1alpha1/plugins/PluginLinks/links?keyword=&sort=priority,asc" const linksUrl = GLOBAL_CONFIG.source.links.linksUrl - const links = GLOBAL_CONFIG.source.links.linksData const num = GLOBAL_CONFIG.source.links.linksNum - var randomFriendLinks = getArrayItems(links, num); - var htmlText = ''; - for (let i = 0; i < randomFriendLinks.length; ++i) { - var item = randomFriendLinks[i] - htmlText += `${item.spec.displayName}`; - } - htmlText += `更多` - if(document.getElementById("friend-links-in-footer")){ - document.getElementById("friend-links-in-footer").innerHTML = htmlText; - } + fetch(fetchUrl) + .then(res => res.json()) + .then(json => { + var randomFriendLinks = getArrayItems(json.items, num); + var htmlText = ''; + for (let i = 0; i < randomFriendLinks.length; ++i) { + var item = randomFriendLinks[i] + htmlText += `${item.spec.displayName}`; + } + htmlText += `更多` + if(document.getElementById("friend-links-in-footer")){ + document.getElementById("friend-links-in-footer").innerHTML = htmlText; + } + }) }, //禁止图片右键单击 diff --git a/templates/assets/zhheo/blogex.js b/templates/assets/zhheo/blogex.js index 84b67314..78aea839 100644 --- a/templates/assets/zhheo/blogex.js +++ b/templates/assets/zhheo/blogex.js @@ -390,32 +390,38 @@ document.addEventListener('scroll', btf.throttle(function () { heo.initThemeColor() }, 200)) +//友链随机传送 //友链随机传送 function travelling() { - const links = GLOBAL_CONFIG.source.links.linksData - var name = '' - var link = '' - if(links.length>0){ - var randomFriendLinks = getArrayItems(links, 1); - name = randomFriendLinks[0].spec.displayName; - link = randomFriendLinks[0].spec.url; - } - var msg = "点击前往按钮进入随机一个友链,不保证跳转网站的安全性和可用性。本次随机到的是本站友链:「" + name + "」"; - const style = document.createElement('style'); - document.head.appendChild(style); - const styleSheet = style.sheet; - styleSheet.insertRule(`:root{--heo-snackbar-time: 8000ms!important}`, styleSheet.cssRules.length); - Snackbar.show({ - text: msg, - duration: 8000, - pos: 'top-center', - actionText: '前往', - onActionClick: function (element) { - //Set opacity of element to 0 to close Snackbar - $(element).css('opacity', 0); - window.open(link, '_blank'); - } - }); + const links = "/apis/api.plugin.halo.run/v1alpha1/plugins/PluginLinks/links?keyword=&sort=priority,asc" + fetch(links) + .then(res => res.json()) + .then(json => { + var linksData = json.items + var name = '' + var link = '' + if(linksData.length>0){ + var randomFriendLinks = getArrayItems(linksData, 1); + name = randomFriendLinks[0].spec.displayName; + link = randomFriendLinks[0].spec.url; + } + var msg = "点击前往按钮进入随机一个友链,不保证跳转网站的安全性和可用性。本次随机到的是本站友链:「" + name + "」"; + const style = document.createElement('style'); + document.head.appendChild(style); + const styleSheet = style.sheet; + styleSheet.insertRule(`:root{--heo-snackbar-time: 8000ms!important}`, styleSheet.cssRules.length); + Snackbar.show({ + text: msg, + duration: 8000, + pos: 'top-center', + actionText: '前往', + onActionClick: function (element) { + //Set opacity of element to 0 to close Snackbar + $(element).css('opacity', 0); + window.open(link, '_blank'); + } + }); + }) } //前往黑洞 diff --git a/templates/assets/zhheo/rightmenu.js b/templates/assets/zhheo/rightmenu.js index 6db6121d..a04a6784 100644 --- a/templates/assets/zhheo/rightmenu.js +++ b/templates/assets/zhheo/rightmenu.js @@ -406,7 +406,7 @@ function addRightMenuClickEvent() { }); $('#menu-copylink').on('click', rm.copyLink); $('#menu-downloadimg').on('click', function () { - heo.downloadImage(domImgSrc, 'kunkunyu'); + heo.downloadImage(domImgSrc, 'hao'); }); $('#menu-newwindowimg').on('click', function () { window.open(domImgSrc, "_blank"); diff --git a/templates/modules/head.html b/templates/modules/head.html index 1dad265f..4255a81a 100644 --- a/templates/modules/head.html +++ b/templates/modules/head.html @@ -199,7 +199,6 @@ source: { links: { linksUrl: [[${ theme.config.link.linksUrl }]], - linksData: [], linksNum: [[${theme.config.footer.footer_group.num}]], }, jQuery: 'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js', @@ -280,22 +279,9 @@ }; - - - - - -