优化随机友链

This commit is contained in:
1152958806@qq.com 2023-09-04 17:50:38 +08:00
parent 07cf2303ed
commit 7c083a8a58
4 changed files with 46 additions and 50 deletions

View File

@ -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 += `<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;
}
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;
}
})
},
//禁止图片右键单击

View File

@ -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');
}
});
})
}
//前往黑洞

View File

@ -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");

View File

@ -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 @@
};
</script>
<script data-pjax th:inline="javascript" th:if="${pluginFinder.available('PluginLinks')}">
var groupData = [[${ linkFinder.groupBy() }]]
if (groupData.length > 0) {
GLOBAL_CONFIG.source.links.linksData = groupData.flatMap((item) => {
return item.links
})
}
</script>
</th:block>
</html>