addFriendLinksInFooter: function() { fetch("/zhheo/friendlink.json").then((e=>e.json())).then((e=>{ var t = [] , o = -1; for (const n of e) { const e = n.link_list; for (let n = 0; n < Math.min(e.length, 1); n++) { let n = Math.floor(Math.random() * e.length); for (; n === o && e.length > 1; ) n = Math.floor(Math.random() * e.length); o = n, t.push({ name: e[n].name, link: e[n].link }), e.splice(n, 1) } } t.pop(); var n = ""; for (let e = 0; e < t.length; ++e) { var a = t[e]; n += `<a class='footer-item' href='${a.link}' target="_blank" rel="noopener nofollow">${a.name}</a>` } n += "<a class='footer-item' href='/link/'>更多</a>", document.getElementById("friend-links-in-footer").innerHTML = n } )) }
/** * 随机友链 */ hexo.extend.filter.register('after_render:html', function (data) { const flinks = [] hexo.locals.get('data').link.map(function (list) { list.link_list.map(function (flink) { flinks.push(flink) }) }) data += `<script> function toRandomFlink() { let flinksTo=${JSON.stringify(flinks)} window.open(flinksTo[Math.floor(Math.random() * flinksTo.length)].link) } function RandomFlink() { let flinksRan=${JSON.stringify(flinks)} let e = flinksRan[Math.floor(Math.random() * flinksRan.length)] return e } function getRandomFlink(num) { let flinksGet=${JSON.stringify(flinks)} let randomLinks = []; while (randomLinks.length < num && flinksGet.length > 0) { let index = Math.floor(Math.random() * flinksGet.length); randomLinks.push(flinksGet.splice(index, 1)[0]); } return randomLinks; } </script>` return data })