fix(like): 修复瞬间无法点赞问题,#103

This commit is contained in:
nineya 2024-01-24 14:35:54 +08:00
parent 2d38a7734c
commit 755821a2f3
4 changed files with 5 additions and 5 deletions

View File

@ -22,12 +22,12 @@ const journalContext = {
description: desc.length > 220 ? desc.substring(0, 220) + '...' :desc 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 journalContextInitial = true
}, },
/* 点赞 */ /* 点赞 */
initLike() { initLike() {
Utils.initLikeButton('.journal .like', 'Moment') Utils.initLikeButton('.journal .like', 'moments')
}, },
/* 折叠日志区域 */ /* 折叠日志区域 */
foldJournals() { foldJournals() {

View File

@ -180,7 +180,7 @@ const Utils = {
returnRaw: true, returnRaw: true,
resultType: 'text', resultType: 'text',
data: JSON.stringify({ data: JSON.stringify({
group: 'content.halo.run', group: type === 'moments' ? 'moment.halo.run' : 'content.halo.run',
plural: type, plural: type,
name: id name: id
}) })

View File

@ -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:220<n.length?n.substring(0,220)+"...":n})}),Utils.initLikeEvent(".journal .like","Moment",n=>n.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('<div class="expand-done"><i class="ri-arrow-up-double-line"></i></div>'):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()})})(); (()=>{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:220<n.length?n.substring(0,220)+"...":n})}),Utils.initLikeEvent(".journal .like","moments",n=>n.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('<div class="expand-done"><i class="ri-arrow-up-double-line"></i></div>'):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()})})();

View File

@ -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<i*l?(window.scrollTo(0,n),o=window.requestAnimationFrame(e)):(window.scrollTo(0,i),window.cancelAnimationFrame(o),r&&r())})}};window.Utils=a})(); (()=>{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<i*l?(window.scrollTo(0,n),o=window.requestAnimationFrame(e)):(window.scrollTo(0,i),window.cancelAnimationFrame(o),r&&r())})}};window.Utils=a})();