From 755821a2f3bb7cc7d8f8dac1864859df570d966d Mon Sep 17 00:00:00 2001 From: nineya <361654768@qq.com> Date: Wed, 24 Jan 2024 14:35:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(like):=20=E4=BF=AE=E5=A4=8D=E7=9E=AC?= =?UTF-8?q?=E9=97=B4=E6=97=A0=E6=B3=95=E7=82=B9=E8=B5=9E=E9=97=AE=E9=A2=98?= =?UTF-8?q?,#103?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/journals.js | 4 ++-- src/js/utils.js | 2 +- templates/assets/js/journals.min.js | 2 +- templates/assets/js/utils.min.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/journals.js b/src/js/journals.js index 545c6eb..06bb34e 100644 --- a/src/js/journals.js +++ b/src/js/journals.js @@ -22,12 +22,12 @@ const journalContext = { description: desc.length > 220 ? desc.substring(0, 220) + '...' :desc }) }) - Utils.initLikeEvent('.journal .like', 'Moment', ($elem) => $elem.next()) + Utils.initLikeEvent('.journal .like', 'moments', ($elem) => $elem.find('em')) journalContextInitial = true }, /* 点赞 */ initLike() { - Utils.initLikeButton('.journal .like', 'Moment') + Utils.initLikeButton('.journal .like', 'moments') }, /* 折叠日志区域 */ foldJournals() { diff --git a/src/js/utils.js b/src/js/utils.js index e7660e1..a66fe90 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -180,7 +180,7 @@ const Utils = { returnRaw: true, resultType: 'text', data: JSON.stringify({ - group: 'content.halo.run', + group: type === 'moments' ? 'moment.halo.run' : 'content.halo.run', plural: type, name: id }) diff --git a/templates/assets/js/journals.min.js b/templates/assets/js/journals.min.js index 906f413..ef5a253 100644 --- a/templates/assets/js/journals.min.js +++ b/templates/assets/js/journals.min.js @@ -1 +1 @@ -(()=>{let e=!1;const i={initEvent(){var n;e||((n=$("body")).on("click",".journal .comment",function(){$(this).parent().parent().siblings(".journal-comment").stop().slideToggle(200)}),n.on("click",".journal-content>.expand-done",function(){Utils.foldBlock($(this).parent())}),n.on("click",".journal-operation-item>.share",function(){var n=$(this).parents(".journal"),e="动态: "+n.find(".journal-date>em").text(),n=n.children(".journal-content").children(".main-content").text();DShare.sharePoster({image:DreamConfig.journals_share_image,title:e,description:220n.next()),e=!0)},initLike(){Utils.initLikeButton(".journal .like","Moment")},foldJournals(){$(".journal .journal-content").each(function(){var n=$(this);this.scrollHeight>=DreamConfig.journals_fold_height?n.append('
'):n.removeClass("fold")})}};window.journalPjax=function(e){0!==$(".card.journal").length&&Object.keys(i).forEach(n=>window.pjaxSerialNumber===e&&i[n]())},window.pjaxSerialNumber||i.initEvent(),window.pjaxSerialNumber||i.initLike(),document.addEventListener("DOMContentLoaded",function(){window.pjaxSerialNumber||i.foldJournals()})})(); \ No newline at end of file +(()=>{let e=!1;const i={initEvent(){var n;e||((n=$("body")).on("click",".journal .comment",function(){$(this).parent().parent().siblings(".journal-comment").stop().slideToggle(200)}),n.on("click",".journal-content>.expand-done",function(){Utils.foldBlock($(this).parent())}),n.on("click",".journal-operation-item>.share",function(){var n=$(this).parents(".journal"),e="动态: "+n.find(".journal-date>em").text(),n=n.children(".journal-content").children(".main-content").text();DShare.sharePoster({image:DreamConfig.journals_share_image,title:e,description:220n.find("em")),e=!0)},initLike(){Utils.initLikeButton(".journal .like","moments")},foldJournals(){$(".journal .journal-content").each(function(){var n=$(this);this.scrollHeight>=DreamConfig.journals_fold_height?n.append('
'):n.removeClass("fold")})}};window.journalPjax=function(e){0!==$(".card.journal").length&&Object.keys(i).forEach(n=>window.pjaxSerialNumber===e&&i[n]())},window.pjaxSerialNumber||i.initEvent(),window.pjaxSerialNumber||i.initLike(),document.addEventListener("DOMContentLoaded",function(){window.pjaxSerialNumber||i.foldJournals()})})(); \ No newline at end of file diff --git a/templates/assets/js/utils.min.js b/templates/assets/js/utils.min.js index d6a6d10..c7bce76 100644 --- a/templates/assets/js/utils.min.js +++ b/templates/assets/js/utils.min.js @@ -1 +1 @@ -(()=>{const a={isMobile:()=>!!(navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i)),cachedScript:(e,t)=>$.ajax(jQuery.extend({url:e,type:"get",dataType:"script",cache:!0,success:t},$.isPlainObject(e)&&e)),formatDate(e,t="yyyy-MM-dd"){e=new Date(e),/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));var a,r,o={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds()};for(a in o)new RegExp(`(${a})`).test(t)&&(r=o[a]+"",t=t.replace(RegExp.$1,1===RegExp.$1.length?r:r.padStart(2,"0")));return t},getUrlParams(){var e=location.search,e=(e="string"!=typeof e?e.toString():e).replace(/^[^\?]*\?/i,"").split(/&/),a={};return e.length<1||Array.isArray(e)&&e.forEach(function(e){if(!e)return!1;var t,e=e.split(/=/);2<=e.length&&(t=e.splice(0,1),a[t]=e.join("="))}),a},randomColor(e){var t=["#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"];return t[e%t.length]},request:({url:e="",method:r="GET",data:o,headers:s={},timeout:n=1e4,returnRaw:i=!1,contentType:c,resultType:l="json"})=>new Promise((t,a)=>{r=r.toUpperCase(),$.ajax({url:e,type:r,headers:{"API-Authorization":DreamConfig.access_key||"dream",...s},async:!0,dataType:l,contentType:c,timeout:n,data:o,success(e){i?t(e):200===e.status?t(e.data||""):a(e)},error(e){e=e&&e.responseJSON?e.responseJSON.title:"请求失败";Qmsg.error(e),a(e)}})}),initLikeButton(e,t){t=encrypt("agree-"+t);let a=localStorage.getItem(t);a=a?JSON.parse(decrypt(a)):[],$(e).each(function(){var e=$(this),t=e.attr("data-id");a.includes(t)&&e.removeClass("like")})},initLikeEvent(e,t,s){let n=encrypt("agree-"+t);$("body").on("click",e,function(e){e.stopPropagation();let r=$(this),o=r.attr("data-id");a.request({url:"/apis/api.halo.run/v1alpha1/trackers/upvote",method:"POST",contentType:"application/json;charset=UTF-8",returnRaw:!0,resultType:"text",data:JSON.stringify({group:"content.halo.run",plural:t,name:o})}).then(e=>{var t=(t=localStorage.getItem(n))?JSON.parse(decrypt(t)):[],a=+(r.attr("data-likes")||0)+1,t=(t.push(o),r.removeClass("like"),encrypt(JSON.stringify(t)));localStorage.setItem(n,t),s(r).html(a),Qmsg.success("点赞成功")})})},baiduPush(){var e=document.createElement("script"),t=window.location.protocol.split(":")[0],t=(e.src="https"===t?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js",$(`script[src="${e.src}"]`).remove(),document.getElementsByTagName("script")[0]);t.parentNode.insertBefore(e,t)},toutiaoPush(){var e=document.createElement("script"),t=(e.src="https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?0fbcfbb1ed642c21419d5be02d56ade7d6ee5372ca221d12ba35df110760b2a830632485602430134f60bc55ca391050b680e2741bf7233a8f1da9902314a3fa",e.id="ttzz",$(`script[src="${e.src}"]`).remove(),document.getElementsByTagName("script")[0]);t.parentNode.insertBefore(e,t)},sleep:(t=250)=>new Promise(e=>setTimeout(e,t)),foldBlock(e){var t,a=e.height();e.is(".fold")?e.removeClass("fold").addClass("unfold"):(t=document.documentElement.scrollTop||document.body.scrollTop||window.pageYOffset,e.addClass("fold").removeClass("unfold"),$("body,html").scrollTop(t-a+e.height()))},removeClassByPrefix(e,t){var a=e.className.split(" ").filter(function(e){return 0!==e.lastIndexOf(t,0)});e.className=a.join(" ").trim()},animateScroll(e,t,a,r){let o,s=e.getBoundingClientRect(),n=window.scrollY,i=n+s.top-a,c=(i-n)/t,l=n>i?-1:1;o=window.requestAnimationFrame(function e(){(n+=c)*l{const a={isMobile:()=>!!(navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i)),cachedScript:(e,t)=>$.ajax(jQuery.extend({url:e,type:"get",dataType:"script",cache:!0,success:t},$.isPlainObject(e)&&e)),formatDate(e,t="yyyy-MM-dd"){e=new Date(e),/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));var a,r,o={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds()};for(a in o)new RegExp(`(${a})`).test(t)&&(r=o[a]+"",t=t.replace(RegExp.$1,1===RegExp.$1.length?r:r.padStart(2,"0")));return t},getUrlParams(){var e=location.search,e=(e="string"!=typeof e?e.toString():e).replace(/^[^\?]*\?/i,"").split(/&/),a={};return e.length<1||Array.isArray(e)&&e.forEach(function(e){if(!e)return!1;var t,e=e.split(/=/);2<=e.length&&(t=e.splice(0,1),a[t]=e.join("="))}),a},randomColor(e){var t=["#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"];return t[e%t.length]},request:({url:e="",method:r="GET",data:o,headers:s={},timeout:n=1e4,returnRaw:i=!1,contentType:c,resultType:l="json"})=>new Promise((t,a)=>{r=r.toUpperCase(),$.ajax({url:e,type:r,headers:{"API-Authorization":DreamConfig.access_key||"dream",...s},async:!0,dataType:l,contentType:c,timeout:n,data:o,success(e){i?t(e):200===e.status?t(e.data||""):a(e)},error(e){e=e&&e.responseJSON?e.responseJSON.title:"请求失败";Qmsg.error(e),a(e)}})}),initLikeButton(e,t){t=encrypt("agree-"+t);let a=localStorage.getItem(t);a=a?JSON.parse(decrypt(a)):[],$(e).each(function(){var e=$(this),t=e.attr("data-id");a.includes(t)&&e.removeClass("like")})},initLikeEvent(e,t,s){let n=encrypt("agree-"+t);$("body").on("click",e,function(e){e.stopPropagation();let r=$(this),o=r.attr("data-id");a.request({url:"/apis/api.halo.run/v1alpha1/trackers/upvote",method:"POST",contentType:"application/json;charset=UTF-8",returnRaw:!0,resultType:"text",data:JSON.stringify({group:"moments"===t?"moment.halo.run":"content.halo.run",plural:t,name:o})}).then(e=>{var t=(t=localStorage.getItem(n))?JSON.parse(decrypt(t)):[],a=+(r.attr("data-likes")||0)+1,t=(t.push(o),r.removeClass("like"),encrypt(JSON.stringify(t)));localStorage.setItem(n,t),s(r).html(a),Qmsg.success("点赞成功")})})},baiduPush(){var e=document.createElement("script"),t=window.location.protocol.split(":")[0],t=(e.src="https"===t?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js",$(`script[src="${e.src}"]`).remove(),document.getElementsByTagName("script")[0]);t.parentNode.insertBefore(e,t)},toutiaoPush(){var e=document.createElement("script"),t=(e.src="https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?0fbcfbb1ed642c21419d5be02d56ade7d6ee5372ca221d12ba35df110760b2a830632485602430134f60bc55ca391050b680e2741bf7233a8f1da9902314a3fa",e.id="ttzz",$(`script[src="${e.src}"]`).remove(),document.getElementsByTagName("script")[0]);t.parentNode.insertBefore(e,t)},sleep:(t=250)=>new Promise(e=>setTimeout(e,t)),foldBlock(e){var t,a=e.height();e.is(".fold")?e.removeClass("fold").addClass("unfold"):(t=document.documentElement.scrollTop||document.body.scrollTop||window.pageYOffset,e.addClass("fold").removeClass("unfold"),$("body,html").scrollTop(t-a+e.height()))},removeClassByPrefix(e,t){var a=e.className.split(" ").filter(function(e){return 0!==e.lastIndexOf(t,0)});e.className=a.join(" ").trim()},animateScroll(e,t,a,r){let o,s=e.getBoundingClientRect(),n=window.scrollY,i=n+s.top-a,c=(i-n)/t,l=n>i?-1:1;o=window.requestAnimationFrame(function e(){(n+=c)*l