Jony/assets/js/joe.global.min.js
2021-03-14 19:20:25 +08:00

1 line
12 KiB
JavaScript

document.addEventListener("DOMContentLoaded",()=>{const changeURLArg=(url,arg,arg_val)=>{let pattern=arg+"=([^&]*)",replaceText=arg+"="+arg_val;if(url.match(pattern)){let tmp="/("+arg+"=)([^&]*)/gi";return url.replace(eval(tmp),replaceText)}return url.match("[?]")?url+"&"+replaceText:url+"?"+replaceText};localStorage.getItem("data-night")?($(".joe_action_item.mode .icon-1").addClass("active"),$(".joe_action_item.mode .icon-2").removeClass("active")):($("html").removeAttr("data-night"),$(".joe_action_item.mode .icon-1").removeClass("active"),$(".joe_action_item.mode .icon-2").addClass("active")),$(".joe_action_item.mode").on("click",()=>{localStorage.getItem("data-night")?($(".joe_action_item.mode .icon-1").removeClass("active"),$(".joe_action_item.mode .icon-2").addClass("active"),$("html").removeAttr("data-night"),localStorage.removeItem("data-night")):($(".joe_action_item.mode .icon-1").addClass("active"),$(".joe_action_item.mode .icon-2").removeClass("active"),$("html").attr("data-night","night"),localStorage.setItem("data-night","night"))}),Joe.IS_MOBILE||"off"===Joe.DYNAMIC_BACKGROUND||!Joe.DYNAMIC_BACKGROUND||Joe.WALLPAPER_BACKGROUND_PC||$.getScript(`/usr/themes/Joe/assets/backdrop/${Joe.DYNAMIC_BACKGROUND}`),$(".joe_header__above-search .input").on("click",t=>{t.stopPropagation(),$(".joe_header__above-search .result").addClass("active")}),$(document).on("click",function(){$(".joe_header__above-search .result").removeClass("active")}),$(document).on("scroll",function(){$(".joe_header__above-search .result").removeClass("active")}),$(".joe_dropdown").each(function(t,e){const o=$(this).find(".joe_dropdown__menu"),a=$(e).attr("trigger")||"click",n=$(e).attr("placement")||$(this).height()||0;o.css("top",n),"hover"===a?$(this).hover(()=>$(this).addClass("active"),()=>$(this).removeClass("active")):($(this).on("click",function(t){$(this).toggleClass("active"),$(document).one("click",()=>$(this).removeClass("active")),t.stopPropagation()}),o.on("click",t=>t.stopPropagation()))});{const t=()=>(document.documentElement.scrollTop||document.body.scrollTop)>300?$(".joe_action_item.scroll").addClass("active"):$(".joe_action_item.scroll").removeClass("active");t(),$(window).on("scroll",()=>t()),$(".joe_action_item.scroll").on("click",()=>window.scrollTo({top:0,behavior:"smooth"}))}if(0!==$(".joe_aside__item.timelife").length){let t=[{title:"今日已经过去",endTitle:"小时",num:0,percent:"0%"},{title:"这周已经过去",endTitle:"天",num:0,percent:"0%"},{title:"本月已经过去",endTitle:"天",num:0,percent:"0%"},{title:"今年已经过去",endTitle:"个月",num:0,percent:"0%"}];{let e=+new Date,o=new Date((new Date).toLocaleDateString()).getTime(),a=(e-o)/1e3/60/60,n=a/24*100;t[0].num=parseInt(a),t[0].percent=parseInt(n)+"%"}{let e={0:7,1:1,2:2,3:3,4:4,5:5,6:6},o=e[(new Date).getDay()],a=o/7*100;t[1].num=parseInt(o),t[1].percent=parseInt(a)+"%"}{let e=(new Date).getFullYear(),o=(new Date).getDate(),a=(new Date).getMonth()+1,n=new Date(e,a,0).getDate(),i=o/n*100;t[2].num=o,t[2].percent=parseInt(i)+"%"}{let e=(new Date).getMonth()+1,o=e/12*100;t[3].num=e,t[3].percent=parseInt(o)+"%"}let e="";t.forEach((t,o)=>{e+=`\n\t\t\t\t\t\t<div class="item">\n\t\t\t\t\t\t\t<div class="title">\n\t\t\t\t\t\t\t\t${t.title}\n\t\t\t\t\t\t\t\t<span class="text">${t.num}</span>\n\t\t\t\t\t\t\t\t${t.endTitle}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div class="progress">\n\t\t\t\t\t\t\t\t<div class="progress-bar">\n\t\t\t\t\t\t\t\t\t<div class="progress-bar-inner progress-bar-inner-${o}" style="width: ${t.percent}"></div>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t<div class="progress-percentage">${t.percent}</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>`}),$(".joe_aside__item.timelife .joe_aside__item-contain").html(e)}if(0!==$(".joe_aside__item.weather").length){const t=$(".joe_aside__item.weather").attr("data-key"),e=$(".joe_aside__item.weather").attr("data-style"),o={1:"FFFFFF",2:"4A4A4A",3:"FFFFFF"};window.WIDGET={CONFIG:{layout:2,width:"220",height:"270",background:e,dataColor:o[e],language:"zh",key:t}},$.getScript("https://apip.weatherdt.com/standard/static/js/weather-standard.js?v=2.0")}0!==$(".joe_aside__item.ranking").length&&$.ajax({url:Joe.BASE_API,type:"POST",data:{routeType:"aside_ranking"},success(t){$(".joe_aside__item.ranking .joe_aside__item-title .text").html(t.title);let e="";1===t.code?t.data.forEach((t,o)=>{e+=`\n\t\t\t\t\t\t\t\t\t<li class="item">\n\t\t\t\t\t\t\t\t\t\t<span class="sort">${o+1}</span>\n\t\t\t\t\t\t\t\t\t\t<a class="link" href="${t.url}" title="${t.title}" target="_blank" rel="noopener noreferrer nofollow">${t.title}</a>\n\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t`}):e+='<li class="error">数据抓取异常!</li>',$(".joe_aside__item.ranking .joe_aside__item-contain").html(e)}}),$(".joe_aside__item:last-child").css("top",$(".joe_header").height()+15),"off"!==Joe.LIVE2D&&Joe.LIVE2D&&$.getScript("https://cdn.jsdelivr.net/npm/live2d-widget@3.1.4/lib/L2Dwidget.min.js",()=>{L2Dwidget.init({model:{jsonPath:Joe.LIVE2D,scale:1},mobile:{show:!1},display:{position:"right",width:160,height:200,hOffset:70,vOffset:0}})});{const t=()=>{let t=$(window).scrollTop(),e=$(document).height(),o=$(window).height(),a=parseInt(t/(e-o)*100);a<=0&&(a=0),a>=100&&(a=100),$(".joe_header__below-progress").css("width",a+"%")};t(),$(window).on("scroll",()=>t())}$(".joe_comment__respond-type .item").on("click",function(){$(this).addClass("active").siblings().removeClass("active"),"draw"===$(this).attr("data-type")?($(".joe_comment__respond-form .body .draw").show().siblings().hide(),$("#joe_comment_draw").prop("width",$(".joe_comment__respond-form .body").width()),$(".joe_comment__respond-form").attr("data-type","draw")):($(".joe_comment__respond-form .body .text").show().siblings().hide(),$(".joe_comment__respond-form").attr("data-type","text"))}),0!==$("#joe_comment_draw").length&&(window.sketchpad=new Sketchpad({element:"#joe_comment_draw",height:300,penSize:5,color:"303133"}),$(".joe_comment__respond-form .body .draw .icon-undo").on("click",()=>window.sketchpad.undo()),$(".joe_comment__respond-form .body .draw .icon-animate").on("click",()=>window.sketchpad.animate(10)),$(".joe_comment__respond-form .body .draw .line li").on("click",function(){window.sketchpad.penSize=$(this).attr("data-line"),$(this).addClass("active").siblings().removeClass("active")}),$(".joe_comment__respond-form .body .draw .color li").on("click",function(){window.sketchpad.color=$(this).attr("data-color"),$(this).addClass("active").siblings().removeClass("active")}));{const t=$(".joe_comment__respond");$(".joe_comment__reply").on("click",function(){const e=$(this).attr("data-coid"),o=$("#"+$(this).attr("data-id"));t.find(".joe_comment__respond-form").attr("data-coid",e),o.append(t),$(".joe_comment__respond-type .item[data-type='text']").click(),$(".joe_comment__cancle").show(),window.scrollTo({top:o.offset().top-$(".joe_header").height()-15,behavior:"smooth"})}),$(".joe_comment__cancle").on("click",function(){t.find(".joe_comment__respond-form").removeAttr("data-coid"),$(".joe_comment__cancle").hide(),$(".joe_comment__title").after(t),$(".joe_comment__respond-type .item[data-type='text']").click(),window.scrollTo({top:$(".joe_comment").offset().top-$(".joe_header").height()-15,behavior:"smooth"})})}{let t=!1;$(".joe_comment__respond-form").on("submit",function(e){e.preventDefault();const o=$(".joe_comment__respond-form").attr("action")+"?time="+ +new Date,a=$(".joe_comment__respond-form").attr("data-type"),n=$(".joe_comment__respond-form").attr("data-coid"),i=$(".joe_comment__respond-form .head input[name='author']").val(),s=$(".joe_comment__respond-form .head input[name='mail']").val();let r=$(".joe_comment__respond-form .body textarea[name='text']").val();if(""===i.trim())return Qmsg.info("请输入昵称!");if(!/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(s))return Qmsg.info("请输入正确的邮箱!");if("text"===a&&""===r.trim())return Qmsg.info("请输入评论内容!");if("draw"===a){const t=$("#joe_comment_draw")[0].toDataURL("image/webp",.1);r="{!{"+t+"}!} "}t||(t=!0,$(".joe_comment__respond-form .foot .submit button").html("发送中..."),$.ajax({url:o,type:"POST",data:{author:i,mail:s,text:r,parent:n},datatype:"text",success(e){let o=[],a="";o=$(e).contents(),Array.from(o).forEach(t=>{"container"===t.parentNode.className&&(a=t)}),/Joe/.test(e)?window.location.href=changeURLArg(location.href,"scroll","joe_comment"):(Qmsg.warning(a.textContent.trim()||""),t=!1,$(".joe_comment__respond-form .foot .submit button").html("发表评论"))}}))})}if(Joe.DOCUMENT_TITLE){const t=document.title;document.addEventListener("visibilitychange",()=>{"hidden"===document.visibilityState?document.title=Joe.DOCUMENT_TITLE:document.title=t})}$(".joe_header__above-slideicon").on("click",function(){$(".joe_header__searchout").removeClass("active"),$(".joe_header__slideout").hasClass("active")?($("body").css("overflow",""),$(".joe_header__mask").removeClass("active slideout"),$(".joe_header__slideout").removeClass("active")):($("body").css("overflow","hidden"),$(".joe_header__mask").addClass("active slideout"),$(".joe_header__slideout").addClass("active"))}),$(".joe_header__above-searchicon").on("click",function(){$(".joe_header__slideout").removeClass("active"),$(".joe_header__searchout").hasClass("active")?($("body").css("overflow",""),$(".joe_header__mask").removeClass("active slideout"),$(".joe_header__searchout").removeClass("active")):($("body").css("overflow","hidden"),$(".joe_header__mask").addClass("active"),$(".joe_header__searchout").addClass("active"))}),$(".joe_header__mask").on("click",function(){$("body").css("overflow",""),$(".joe_header__mask").removeClass("active slideout"),$(".joe_header__searchout").removeClass("active"),$(".joe_header__slideout").removeClass("active")}),$(".joe_header__slideout-menu .current").parents(".panel-body").show().siblings(".panel").addClass("in"),$(".joe_header__slideout-menu .panel").on("click",function(){const t=$(this).parent().parent();t.find(".panel").not($(this)).removeClass("in"),t.find(".panel-body").not($(this).siblings(".panel-body")).stop().hide("fast"),$(this).toggleClass("in").siblings(".panel-body").stop().toggle("fast")});{const t=()=>{const t=new Date(Joe.BIRTHDAY),e=+new Date,o=e-t.getTime();let a=o/864e5,n=Math.floor(a),i=24*(a-n),s=Math.floor(i),r=60*(i-s),c=Math.floor(r),d=60*(r-c),l=Math.floor(d);a=String(n).padStart(2,0),i=String(s).padStart(2,0),r=String(c).padStart(2,0),d=String(l).padStart(2,0),$(".joe_run__day").html(a),$(".joe_run__hour").html(i),$(".joe_run__minute").html(r),$(".joe_run__second").html(d)};Joe.BIRTHDAY&&/(\d{4})\/(\d{1,2})\/(\d{1,2}) (\d{1,2})\:(\d{1,2})\:(\d{1,2})/.test(Joe.BIRTHDAY)&&(t(),setInterval(t,1e3))}$(".joe_owo__contain").length>0&&$(".joe_owo__target").length>0&&$.ajax({url:"/usr/themes/Joe/assets/json/joe.owo.json",success(t){let e="",o="";for(let a in t)e+=`<div class="item" data-index="${t[a].index}">${a}</div>`,o+=`\n <ul class="scroll" data-index="${t[a].index}">\n ${t[a].container.map(t=>`<li class="item" data-text="${t.data}">${t.icon}</li>`).join("")} \n </ul>\n `;$(".joe_owo__contain").html(`\n <div class="seat">OωO</div>\n <div class="box">\n ${o}\n <div class="bar">${e}</div>\n </div>\n `),$(document).on("click",function(){$(".joe_owo__contain .box").stop().slideUp("fast")}),$(".joe_owo__contain .seat").on("click",function(t){t.stopPropagation(),$(this).siblings(".box").stop().slideToggle("fast")}),$(".joe_owo__contain .box .bar .item").on("click",function(t){t.stopPropagation(),$(this).addClass("active").siblings().removeClass("active");const e='.joe_owo__contain .box .scroll[data-index="'+$(this).attr("data-index")+'"]';$(e).show().siblings(".scroll").hide()}),$(".joe_owo__contain .scroll .item").on("click",function(){const t=$(this).attr("data-text");$(".joe_owo__target").insertContent(t)}),$(".joe_owo__contain .box .bar .item").first().click()}});{let t=Joe.MOTTO;t||(t="有钱终成眷属,没钱亲眼目睹"),t.includes("http")?$.ajax({url:t,dataType:"text",success:t=>$(".joe_motto").html(t)}):$(".joe_motto").html(t)}});