From 99e99cbedca9fadea70ece8f18fa0c032dcb0693 Mon Sep 17 00:00:00 2001
From: "1152958806@qq.com" <17683872107czx>
Date: Wed, 27 Sep 2023 13:44:45 +0800
Subject: [PATCH] =?UTF-8?q?=E5=8F=8B=E9=93=BE=E6=95=B0=E6=8D=AE=E7=BC=93?=
=?UTF-8?q?=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
templates/assets/js/heo.js | 56 +++++++++++++++----------
templates/assets/zhheo/blogex.js | 70 +++++++++++++++++++-------------
2 files changed, 77 insertions(+), 49 deletions(-)
diff --git a/templates/assets/js/heo.js b/templates/assets/js/heo.js
index 8e0cb55e..f158b700 100644
--- a/templates/assets/js/heo.js
+++ b/templates/assets/js/heo.js
@@ -73,27 +73,41 @@ var heo = {
footerRandomFriendsBtn.style.opacity = "0.2";
footerRandomFriendsBtn.style.transitionDuration = "0.3s";
footerRandomFriendsBtn.style.transform = "rotate(" + 360 * refreshNum++ + "deg)";
-
- const fetchUrl = "/apis/api.plugin.halo.run/v1alpha1/plugins/PluginLinks/links?keyword=&sort=priority,asc"
- const linksUrl = GLOBAL_CONFIG.source.links.linksUrl
- const num = GLOBAL_CONFIG.source.links.linksNum
- 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 += ``;
- }
- htmlText += ``
- if(document.getElementById("friend-links-in-footer")){
- document.getElementById("friend-links-in-footer").innerHTML = htmlText;
- }
- })
- setTimeout(()=>{
- footerRandomFriendsBtn.style.opacity = "1";
- }, 300)
+ function getLinks(){
+ const fetchUrl = "/apis/api.plugin.halo.run/v1alpha1/plugins/PluginLinks/links?keyword=&sort=priority,asc"
+ fetch(fetchUrl)
+ .then(res => res.json())
+ .then(json => {
+ saveToLocal.set('links-data', JSON.stringify(json.items), 10 / (60 * 24))
+ renderer(json.items);
+ })
+ }
+ function renderer(data){
+ const linksUrl = GLOBAL_CONFIG.source.links.linksUrl
+ const num = GLOBAL_CONFIG.source.links.linksNum
+ var randomFriendLinks = getArrayItems(data, num);
+ var htmlText = '';
+ for (let i = 0; i < randomFriendLinks.length; ++i) {
+ var item = randomFriendLinks[i]
+ htmlText += ``;
+ }
+ htmlText += ``
+ if(document.getElementById("friend-links-in-footer")){
+ document.getElementById("friend-links-in-footer").innerHTML = htmlText;
+ }
+ }
+ function friendLinksInFooterInit(){
+ const data = saveToLocal.get('links-data')
+ if (data) {
+ renderer(JSON.parse(data))
+ } else {
+ getLinks()
+ }
+ setTimeout(()=>{
+ footerRandomFriendsBtn.style.opacity = "1";
+ }, 300)
+ }
+ friendLinksInFooterInit();
},
//禁止图片右键单击
diff --git a/templates/assets/zhheo/blogex.js b/templates/assets/zhheo/blogex.js
index 9c25a5a0..7ca7790d 100644
--- a/templates/assets/zhheo/blogex.js
+++ b/templates/assets/zhheo/blogex.js
@@ -367,35 +367,49 @@ document.addEventListener('scroll', btf.throttle(function () {
//友链随机传送
function travelling() {
- 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;
+ function getLinks() {
+ const links = "/apis/api.plugin.halo.run/v1alpha1/plugins/PluginLinks/links?keyword=&sort=priority,asc"
+ fetch(links)
+ .then(res => res.json())
+ .then(json => {
+ saveToLocal.set('links-data', JSON.stringify(json.items), 10 / (60 * 24))
+ renderer(json.items);
+ })
+ }
+ function renderer(data){
+ var linksData = data
+ 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) {
+ $(element).css('opacity', 0);
+ window.open(link, '_blank');
}
- 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');
- }
- });
- })
+ });
+ }
+ function init(){
+ const data = saveToLocal.get('links-data')
+ if (data) {
+ renderer(JSON.parse(data))
+ } else {
+ getLinks()
+ }
+ }
+ init()
}
//前往黑洞