友链数据缓存
This commit is contained in:
parent
0b390a54b7
commit
99e99cbedc
|
@ -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 += `<a class='footer-item' href='${item.spec.url}' target="_blank" rel="noopener nofollow">${item.spec.displayName}</a>`;
|
||||
}
|
||||
htmlText += `<a class='footer-item' href='${linksUrl}'>更多</a>`
|
||||
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 += `<a class='footer-item' href='${item.spec.url}' target="_blank" rel="noopener nofollow">${item.spec.displayName}</a>`;
|
||||
}
|
||||
htmlText += `<a class='footer-item' href='${linksUrl}'>更多</a>`
|
||||
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();
|
||||
},
|
||||
|
||||
//禁止图片右键单击
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
//前往黑洞
|
||||
|
|
Loading…
Reference in New Issue