[杂项]handsome启用随机图片,将首页头图与文章头图设为一致
201 字
1 分钟
[杂项]handsome启用随机图片,将首页头图与文章头图设为一致
![[杂项]handsome启用随机图片,将首页头图与文章头图设为一致](/_astro/rehtt-legacy-04.4Iy-f1N1_Z1a0orM.webp)
0x00
handsome启用随机图片时,头图会被随机更换,但不能达到首页和文章头图一致
0x01 思路
通过JS在首页刷新完后获取对应文章的随机头图地址,再将头图地址放在文章的地址后面p_i里
加载文章时通过p_i将首页头图显示出来



0x02 代码
适用于/archives/{cid}/永久链接
随机头图存放地址/usr/themes/handsome/usr/img/sj/
可根据自己实际情况更改
将代码放进自定义js和PJAX中
if (window.location.pathname === "/") { var img =document.getElementsByClassName("item-thumb lazy"); var a=document.getElementsByClassName("index-post-img") for (var i = 0; i < a.length; i++) { var yurl = a[i].getElementsByTagName("a")[0].getAttribute("href"); url=img[i].style.backgroundImage.split("\"")[1].split("/")[9].split(".")[0] a[i].getElementsByTagName("a")[0].setAttribute("href",yurl+"?p_i="+url); }}else if (GetQueryString("p_i")!==null) { document.getElementsByClassName("item-thumb lazy")[0].style.backgroundImage="url(\"/usr/themes/handsome/usr/img/sj/"+GetQueryString("p_i")+".jpg\")"
}function GetQueryString(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if(r!=null)return unescape(r[2]); return null;}支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!
[杂项]handsome启用随机图片,将首页头图与文章头图设为一致
https://rehtt.com/posts/206/相关文章智能推荐
1
[杂项]handsome主题美化
杂项2020-02-12
2
[杂项]修复handsome透明模式bug
杂项2019-10-25
3
[杂项]handsome主题提示php函数损坏或主题文件缺失
杂项2019-10-24
4
[杂项]去除handsome主题的时光机头图的蒙层
杂项2019-10-24
5
【NFC】恢复被写入cpu卡SAK的CUID魔术卡
杂项2026-05-10
随机文章随机推荐















加载更多…