halo-theme-dream2.0-plus
Version:
梦之城,童话梦境,动漫类型博客主题。
1 lines • 4.21 kB
JavaScript
(()=>{const r={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)),secureCompressHTML(e,t=!0){if("string"!=typeof e)return"";const r={"<":"<",">":">","&":"&",'"':""","'":"'","/":"/"};let a=e.replace(/[<>&"'\/]/g,e=>r[e]);return t&&["p","br","div","span","a","b","i","strong","em"].forEach(e=>{var t=new RegExp(`<(${e})([^&]*)>`,"gi"),t=(a=a.replace(t,`<${e}$2>`),new RegExp(`<\\/(${e})>`,"gi"));a=a.replace(t,`</${e}>`)}),a.replace(/<!--[\s\S]*?-->/g,"").replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<")},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 r,a,n={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds()};for(r in n)new RegExp(`(${r})`).test(t)&&(a=n[r]+"",t=t.replace(RegExp.$1,1===RegExp.$1.length?a:a.padStart(2,"0")));return t},getUrlParams(){var e=location.search,e=(e="string"!=typeof e?e.toString():e).replace(/^[^\?]*\?/i,"").split(/&/),r={};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),r[t]=e.join("="))}),r},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:a="GET",data:n,headers:o={},timeout:s=1e4,returnRaw:i=!1,contentType:l,resultType:c="json",noErrorTip:g=!1})=>new Promise((t,r)=>{a=a.toUpperCase(),$.ajax({url:e,type:a,headers:{"API-Authorization":DreamConfig.access_key||"dream",...o},async:!0,dataType:c,contentType:l,timeout:s,data:n,success(e){i?t(e):200===e.status?t(e.data||""):r(e)},error(e){e=e&&e.responseJSON?e.responseJSON.title:"请求失败";g||Qmsg.error(e),r(e)}})}),initLikeButton(e,t){t=encrypt("agree-"+t);let r=localStorage.getItem(t);r=r?JSON.parse(decrypt(r)):[],$(e).each(function(){var e=$(this),t=e.attr("data-id");r.includes(t)&&e.removeClass("like")})},initLikeEvent(e,t,o){let s=encrypt("agree-"+t);$("body").on("click",e,function(e){e.stopPropagation();let a=$(this),n=a.attr("data-id"),t=a.attr("data-type");r.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:"Moments"===t?"moments":"Post"===t?"posts":"",name:n})}).then(e=>{var t=(t=localStorage.getItem(s))?JSON.parse(decrypt(t)):[],r=+(a.attr("data-likes")||0)+1,t=(t.push(n),a.removeClass("like"),encrypt(JSON.stringify(t)));localStorage.setItem(s,t),o(a).html(r),Qmsg.success("点赞成功")})})},sleep:(t=250)=>new Promise(e=>setTimeout(e,t)),foldBlock(e){var t,r=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-r+e.height()))},removeClassByPrefix(e,t){var r=e.className.split(" ").filter(function(e){return 0!==e.lastIndexOf(t,0)});e.className=r.join(" ").trim()},animateScroll(e,t,r,a){let n,o=e.getBoundingClientRect(),s=window.scrollY,i=s+o.top-r,l=(i-s)/t,c=s>i?-1:1;n=window.requestAnimationFrame(function e(){(s+=l)*c<i*c?(window.scrollTo(0,s),n=window.requestAnimationFrame(e)):(window.scrollTo(0,i),window.cancelAnimationFrame(n),a&&a())})},djb2Hash(t){let r=5381;for(let e=0;e<t.length;e++)r=33*r^t.charCodeAt(e);return(r>>>0).toString()}};window.Utils=r})();