diff --git a/assets/js/joe.leaving.js b/assets/js/joe.leaving.js index 9387b8a..cccc44e 100644 --- a/assets/js/joe.leaving.js +++ b/assets/js/joe.leaving.js @@ -1,107 +1,136 @@ document.addEventListener('DOMContentLoaded', () => { - const encryption = str => window.btoa(unescape(encodeURIComponent(str))); - const decrypt = str => decodeURIComponent(escape(window.atob(str))); + const encryption = str => window.btoa(unescape(encodeURIComponent(str))); + const decrypt = str => decodeURIComponent(escape(window.atob(str))); - /* 当前页的CID */ - const cid = $('.joe_detail').attr('data-cid'); + /* 当前页的CID */ + const cid = $('.joe_detail').attr('data-cid'); - /* 获取本篇文章百度收录情况 */ - { - $.ajax({ - url: Joe.BASE_API, - type: 'POST', - data: { routeType: 'baidu_record', site: window.location.href }, - success(res) { - if (res.data && res.data === '已收录') { - $('#Joe_Baidu_Record').css('color', '#67C23A'); - $('#Joe_Baidu_Record').html('已收录'); - } else { - /* 如果填写了Token,则自动推送给百度 */ - if (Joe.BAIDU_PUSH) { - $('#Joe_Baidu_Record').html('未收录,推送中...'); - const _timer = setTimeout(function () { - $.ajax({ - url: Joe.BASE_API, - type: 'POST', - data: { - routeType: 'baidu_push', - domain: encodeURI(window.location.hostname), - url: encodeURI(window.location.href) - }, - success(res) { - if (res.error) { - $('#Joe_Baidu_Record').html('推送失败,请检查!'); - } else { - $('#Joe_Baidu_Record').html('推送成功!'); - } - } - }); - clearTimeout(_timer); - }, 1000); - } else { - const url = `https://ziyuan.baidu.com/linksubmit/url?sitename=${encodeURI(window.location.href)}`; - $('#Joe_Baidu_Record').html(`未收录,提交收录`); - } - } - } - }); - } + /* 获取本篇文章百度收录情况 */ + { + $.ajax({ + url: Joe.BASE_API, + type: 'POST', + data: { routeType: 'baidu_record', site: window.location.href }, + success(res) { + if (res.data && res.data === '已收录') { + $('#Joe_Baidu_Record').css('color', '#67C23A'); + $('#Joe_Baidu_Record').html('已收录'); + } else { + /* 如果填写了Token,则自动推送给百度 */ + if (Joe.BAIDU_PUSH) { + $('#Joe_Baidu_Record').html('未收录,推送中...'); + const _timer = setTimeout(function () { + $.ajax({ + url: Joe.BASE_API, + type: 'POST', + data: { + routeType: 'baidu_push', + domain: encodeURI(window.location.hostname), + url: encodeURI(window.location.href) + }, + success(res) { + if (res.error) { + $('#Joe_Baidu_Record').html('推送失败,请检查!'); + } else { + $('#Joe_Baidu_Record').html('推送成功!'); + } + } + }); + clearTimeout(_timer); + }, 1000); + } else { + const url = `https://ziyuan.baidu.com/linksubmit/url?sitename=${encodeURI(window.location.href)}`; + $('#Joe_Baidu_Record').html(`未收录,提交收录`); + } + } + } + }); + } - /* 激活浏览功能 */ - { - let viewsArr = localStorage.getItem(encryption('views')) ? JSON.parse(decrypt(localStorage.getItem(encryption('views')))) : []; - const flag = viewsArr.includes(cid); - if (!flag) { - $.ajax({ - url: Joe.BASE_API, - type: 'POST', - data: { routeType: 'handle_views', cid }, - success(res) { - if (res.code !== 1) return; - $('#Joe_Article_Views').html(`${res.data.views} 阅读`); - viewsArr.push(cid); - const name = encryption('views'); - const val = encryption(JSON.stringify(viewsArr)); - localStorage.setItem(name, val); - } - }); - } - } + /* 激活浏览功能 */ + { + let viewsArr = localStorage.getItem(encryption('views')) ? JSON.parse(decrypt(localStorage.getItem(encryption('views')))) : []; + const flag = viewsArr.includes(cid); + if (!flag) { + $.ajax({ + url: Joe.BASE_API, + type: 'POST', + data: { routeType: 'handle_views', cid }, + success(res) { + if (res.code !== 1) return; + $('#Joe_Article_Views').html(`${res.data.views} 阅读`); + viewsArr.push(cid); + const name = encryption('views'); + const val = encryption(JSON.stringify(viewsArr)); + localStorage.setItem(name, val); + } + }); + } + } - /* 激活随机样式 */ - { - let _index = 100; - const colors = ['#F8D800', '#0396FF', '#EA5455', '#7367F0', '#32CCBC', '#F6416C', '#28C76F', '#9F44D3', '#F55555', '#736EFE', '#E96D71', '#DE4313', '#D939CD', '#4C83FF', '#F072B6', '#C346C2', '#5961F9', '#FD6585', '#465EFB', '#FFC600', '#FA742B', '#5151E5', '#BB4E75', '#FF52E5', '#49C628', '#00EAFF', '#F067B4', '#F067B4', '#ff9a9e', '#00f2fe', '#4facfe', '#f093fb', '#6fa3ef', '#bc99c4', '#46c47c', '#f9bb3c', '#e8583d', '#f68e5f']; - const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; - const maxWidth = $('.joe_detail__leaving-list').width(); - const maxHeight = $('.joe_detail__leaving-list').height(); - const radius1 = ['20px 300px', '20px 400px', '20px 500px', '30px 300px', '30px 400px', '30px 500px', '40px 300px', '40px 400px', '40px 500px']; - const radius2 = ['300px 20px', '400px 20px', '500px 20px', '300px 30px', '400px 30px', '500px 30px', '300px 40px', '400px 40px', '500px 40px']; - $('.joe_detail__leaving-list .item').each((index, item) => { - const zIndex = random(1, 99); - const background = colors[random(0, colors.length - 1)]; - const width = Math.ceil($(item).width()); - const height = Math.ceil($(item).height()); - const top = random(0, maxHeight - height); - const left = random(0, maxWidth - width); - $(item).css({ - display: 'block', - zIndex, - background, - top, - left, - borderTopLeftRadius: radius2[random(0, radius2.length - 1)], - borderTopRightRadius: radius1[random(0, radius1.length - 1)], - borderBottomLeftRadius: radius1[random(0, radius1.length - 1)], - borderBottomRightRadius: radius1[random(0, radius1.length - 1)] - }); - $(item).draggabilly({ containment: true }); - $(item).on('dragStart', e => { - _index++; - $(item).css({ - zIndex: _index, - }); - }); - }); - } + /* 激活随机样式 */ + { + let _index = 100; + const colors = ['#F8D800', '#0396FF', '#EA5455', '#7367F0', '#32CCBC', '#F6416C', '#28C76F', '#9F44D3', '#F55555', '#736EFE', '#E96D71', '#DE4313', '#D939CD', '#4C83FF', '#F072B6', '#C346C2', '#5961F9', '#FD6585', '#465EFB', '#FFC600', '#FA742B', '#5151E5', '#BB4E75', '#FF52E5', '#49C628', '#00EAFF', '#F067B4', '#F067B4', '#ff9a9e', '#00f2fe', '#4facfe', '#f093fb', '#6fa3ef', '#bc99c4', '#46c47c', '#f9bb3c', '#e8583d', '#f68e5f']; + const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; + const maxWidth = $('.joe_detail__leaving-list').width(); + const maxHeight = $('.joe_detail__leaving-list').height(); + const radius1 = ['20px 300px', '20px 400px', '20px 500px', '30px 300px', '30px 400px', '30px 500px', '40px 300px', '40px 400px', '40px 500px']; + const radius2 = ['300px 20px', '400px 20px', '500px 20px', '300px 30px', '400px 30px', '500px 30px', '300px 40px', '400px 40px', '500px 40px']; + $('.joe_detail__leaving-list .item').each((index, item) => { + const zIndex = random(1, 99); + const background = colors[random(0, colors.length - 1)]; + const width = Math.ceil($(item).width()); + const height = Math.ceil($(item).height()); + const top = random(0, maxHeight - height); + const left = random(0, maxWidth - width); + $(item).css({ + display: 'block', + zIndex, + background, + top, + left, + borderTopLeftRadius: radius2[random(0, radius2.length - 1)], + borderTopRightRadius: radius1[random(0, radius1.length - 1)], + borderBottomLeftRadius: radius1[random(0, radius1.length - 1)], + borderBottomRightRadius: radius1[random(0, radius1.length - 1)] + }); + $(item).draggabilly({ containment: true }); + $(item).on('dragStart', e => { + _index++; + $(item).css({ zIndex: _index }); + }); + }); + } + + /* 格式化分页的hash值 */ + { + $('.joe_comment .joe_pagination a').each((index, item) => { + const href = $(item).attr('href'); + if (href && href.includes('#')) { + $(item).attr('href', href.replace('#comments', '?scroll=joe_comment')); + } + }); + } +}); + +/* 写在load事件里,为了解决图片未加载完成,滚动距离获取会不准确的问题 */ +window.addEventListener('load', function () { + /* 判断地址栏是否有锚点链接,有则跳转到对应位置 */ + { + const scroll = new URLSearchParams(location.search).get('scroll'); + if (scroll) { + const height = $('.joe_header').height(); + let elementEL = null; + if ($('#' + scroll).length > 0) { + elementEL = $('#' + scroll); + } else { + elementEL = $('.' + scroll); + } + if (elementEL && elementEL.length > 0) { + const top = elementEL.offset().top - height - 15; + window.scrollTo({ top, behavior: 'smooth' }); + } + } + } }); diff --git a/assets/js/joe.leaving.min.js b/assets/js/joe.leaving.min.js index 812921e..77a98f0 100644 --- a/assets/js/joe.leaving.min.js +++ b/assets/js/joe.leaving.min.js @@ -1 +1 @@ -document.addEventListener("DOMContentLoaded",()=>{const e=e=>window.btoa(unescape(encodeURIComponent(e))),o=e=>decodeURIComponent(escape(window.atob(e))),t=$(".joe_detail").attr("data-cid");$.ajax({url:Joe.BASE_API,type:"POST",data:{routeType:"baidu_record",site:window.location.href},success(e){if(e.data&&"已收录"===e.data)$("#Joe_Baidu_Record").css("color","#67C23A"),$("#Joe_Baidu_Record").html("已收录");else if(Joe.BAIDU_PUSH){$("#Joe_Baidu_Record").html('未收录,推送中...');const e=setTimeout(function(){$.ajax({url:Joe.BASE_API,type:"POST",data:{routeType:"baidu_push",domain:encodeURI(window.location.hostname),url:encodeURI(window.location.href)},success(e){e.error?$("#Joe_Baidu_Record").html('推送失败,请检查!'):$("#Joe_Baidu_Record").html('推送成功!')}}),clearTimeout(e)},1e3)}else{const e=`https://ziyuan.baidu.com/linksubmit/url?sitename=${encodeURI(window.location.href)}`;$("#Joe_Baidu_Record").html(`未收录,提交收录`)}}});{let a=localStorage.getItem(e("views"))?JSON.parse(o(localStorage.getItem(e("views")))):[];const i=a.includes(t);i||$.ajax({url:Joe.BASE_API,type:"POST",data:{routeType:"handle_views",cid:t},success(o){if(1!==o.code)return;$("#Joe_Article_Views").html(`${o.data.views} 阅读`),a.push(t);const i=e("views"),n=e(JSON.stringify(a));localStorage.setItem(i,n)}})}{let e=100;const o=["#F8D800","#0396FF","#EA5455","#7367F0","#32CCBC","#F6416C","#28C76F","#9F44D3","#F55555","#736EFE","#E96D71","#DE4313","#D939CD","#4C83FF","#F072B6","#C346C2","#5961F9","#FD6585","#465EFB","#FFC600","#FA742B","#5151E5","#BB4E75","#FF52E5","#49C628","#00EAFF","#F067B4","#F067B4","#ff9a9e","#00f2fe","#4facfe","#f093fb","#6fa3ef","#bc99c4","#46c47c","#f9bb3c","#e8583d","#f68e5f"],t=(e,o)=>Math.floor(Math.random()*(o-e+1))+e,a=$(".joe_detail__leaving-list").width(),i=$(".joe_detail__leaving-list").height(),n=["20px 300px","20px 400px","20px 500px","30px 300px","30px 400px","30px 500px","40px 300px","40px 400px","40px 500px"],d=["300px 20px","400px 20px","500px 20px","300px 30px","400px 30px","500px 30px","300px 40px","400px 40px","500px 40px"];$(".joe_detail__leaving-list .item").each((l,c)=>{const s=t(1,99),p=o[t(0,o.length-1)],r=Math.ceil($(c).width()),x=Math.ceil($(c).height()),u=t(0,i-x),h=t(0,a-r);$(c).css({display:"block",zIndex:s,background:p,top:u,left:h,borderTopLeftRadius:d[t(0,d.length-1)],borderTopRightRadius:n[t(0,n.length-1)],borderBottomLeftRadius:n[t(0,n.length-1)],borderBottomRightRadius:n[t(0,n.length-1)]}),$(c).draggabilly({containment:!0}),$(c).on("dragStart",o=>{e++,$(c).css({zIndex:e})})})}}); \ No newline at end of file +document.addEventListener("DOMContentLoaded",()=>{const e=e=>window.btoa(unescape(encodeURIComponent(e))),o=e=>decodeURIComponent(escape(window.atob(e))),t=$(".joe_detail").attr("data-cid");$.ajax({url:Joe.BASE_API,type:"POST",data:{routeType:"baidu_record",site:window.location.href},success(e){if(e.data&&"已收录"===e.data)$("#Joe_Baidu_Record").css("color","#67C23A"),$("#Joe_Baidu_Record").html("已收录");else if(Joe.BAIDU_PUSH){$("#Joe_Baidu_Record").html('未收录,推送中...');const e=setTimeout(function(){$.ajax({url:Joe.BASE_API,type:"POST",data:{routeType:"baidu_push",domain:encodeURI(window.location.hostname),url:encodeURI(window.location.href)},success(e){e.error?$("#Joe_Baidu_Record").html('推送失败,请检查!'):$("#Joe_Baidu_Record").html('推送成功!')}}),clearTimeout(e)},1e3)}else{const e=`https://ziyuan.baidu.com/linksubmit/url?sitename=${encodeURI(window.location.href)}`;$("#Joe_Baidu_Record").html(`未收录,提交收录`)}}});{let a=localStorage.getItem(e("views"))?JSON.parse(o(localStorage.getItem(e("views")))):[];const n=a.includes(t);n||$.ajax({url:Joe.BASE_API,type:"POST",data:{routeType:"handle_views",cid:t},success(o){if(1!==o.code)return;$("#Joe_Article_Views").html(`${o.data.views} 阅读`),a.push(t);const n=e("views"),i=e(JSON.stringify(a));localStorage.setItem(n,i)}})}{let e=100;const o=["#F8D800","#0396FF","#EA5455","#7367F0","#32CCBC","#F6416C","#28C76F","#9F44D3","#F55555","#736EFE","#E96D71","#DE4313","#D939CD","#4C83FF","#F072B6","#C346C2","#5961F9","#FD6585","#465EFB","#FFC600","#FA742B","#5151E5","#BB4E75","#FF52E5","#49C628","#00EAFF","#F067B4","#F067B4","#ff9a9e","#00f2fe","#4facfe","#f093fb","#6fa3ef","#bc99c4","#46c47c","#f9bb3c","#e8583d","#f68e5f"],t=(e,o)=>Math.floor(Math.random()*(o-e+1))+e,a=$(".joe_detail__leaving-list").width(),n=$(".joe_detail__leaving-list").height(),i=["20px 300px","20px 400px","20px 500px","30px 300px","30px 400px","30px 500px","40px 300px","40px 400px","40px 500px"],l=["300px 20px","400px 20px","500px 20px","300px 30px","400px 30px","500px 30px","300px 40px","400px 40px","500px 40px"];$(".joe_detail__leaving-list .item").each((c,s)=>{const d=t(1,99),r=o[t(0,o.length-1)],p=Math.ceil($(s).width()),h=Math.ceil($(s).height()),x=t(0,n-h),u=t(0,a-p);$(s).css({display:"block",zIndex:d,background:r,top:x,left:u,borderTopLeftRadius:l[t(0,l.length-1)],borderTopRightRadius:i[t(0,i.length-1)],borderBottomLeftRadius:i[t(0,i.length-1)],borderBottomRightRadius:i[t(0,i.length-1)]}),$(s).draggabilly({containment:!0}),$(s).on("dragStart",o=>{e++,$(s).css({zIndex:e})})})}$(".joe_comment .joe_pagination a").each((e,o)=>{const t=$(o).attr("href");t&&t.includes("#")&&$(o).attr("href",t.replace("#comments","?scroll=joe_comment"))})}),window.addEventListener("load",function(){{const e=new URLSearchParams(location.search).get("scroll");if(e){const o=$(".joe_header").height();let t=null;if(t=$("#"+e).length>0?$("#"+e):$("."+e),t&&t.length>0){const e=t.offset().top-o-15;window.scrollTo({top:e,behavior:"smooth"})}}}}); \ No newline at end of file diff --git a/core/function.php b/core/function.php index c22a75d..e106bf5 100644 --- a/core/function.php +++ b/core/function.php @@ -3,7 +3,7 @@ /* 获取主题当前版本号 */ function _getVersion() { - return "5.5.8"; + return "5.5.9"; }; /* 判断是否是手机 */