友链数据缓存
This commit is contained in:
parent
0b390a54b7
commit
99e99cbedc
|
@ -73,14 +73,19 @@ var heo = {
|
|||
footerRandomFriendsBtn.style.opacity = "0.2";
|
||||
footerRandomFriendsBtn.style.transitionDuration = "0.3s";
|
||||
footerRandomFriendsBtn.style.transform = "rotate(" + 360 * refreshNum++ + "deg)";
|
||||
|
||||
function getLinks(){
|
||||
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);
|
||||
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]
|
||||
|
@ -90,10 +95,19 @@ var heo = {
|
|||
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,14 +367,20 @@ document.addEventListener('scroll', btf.throttle(function () {
|
|||
|
||||
//友链随机传送
|
||||
function travelling() {
|
||||
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 => {
|
||||
var linksData = json.items
|
||||
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){
|
||||
if (linksData.length > 0) {
|
||||
var randomFriendLinks = getArrayItems(linksData, 1);
|
||||
name = randomFriendLinks[0].spec.displayName;
|
||||
link = randomFriendLinks[0].spec.url;
|
||||
|
@ -390,12 +396,20 @@ function travelling() {
|
|||
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