-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuckoo.min.js
16 lines (15 loc) · 10.6 KB
/
cuckoo.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* .______ __ __ ___ ______
* | _ \ | | | | / \ / __ \
* | |_) | | |__| | / ^ \ | | | |
* | _ < | __ | / /_\ \ | | | |
* | |_) | | | | | / _____ \ | `--' |
* |______/ |__| |__| /__/ \__\ \______/
*
* JavaScript
*
* @author Bhao
* @link https://dwd.moe/
* @date U
*/
var $=mdui.$;var color=$(".mdui-text-color-theme").css("color");$('head').append("<style>html { --color: "+color+"; }</style>");$('head').append("<style>.is-active-link::before{ background-color:"+color+" }#nprogress .bar{ background-color:"+color+"!important }.article-page h2::before {color: "+color+";}.article-page h3, .article-page h4, .article-page h5, .article-page h6 {border-left: 4px solid "+color+" !important;}#sticky{color:"+color+"}</style>");getCookie=function(name){var name=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i].trim();if(c.indexOf(name)==0)return c.substring(name.length,c.length)};return false};var acf='bili';setCookie=function(name,value,days,path){if(days===false){document.cookie=name+'='+value+';path='+path+';'}else{var exp=new Date();exp.setTime(exp.getTime()+days*24*60*60*1000);document.cookie=name+'='+value+';expires='+exp.toGMTString()+';path='+path+';'}};var po='#cuck';lightContent=function(msg){setTimeout(function(){$('#brightness i').html('brightness_5');$('body').removeClass('mdui-theme-layout-dark');mdui.snackbar({message:msg,position:'right-bottom',timeout:1000})},300)};var msg='\u8bf7\u52ff\u5220\u9664\u002f\u4fee\u6539\u7248\u6743\uff0c\u8bf7\u5c0a\u91cd\u72ec\u7acb\u5f00\u53d1\u8005\u52b3\u52a8\u6210\u679c';var ck='oo-';darkContent=function(msg){setTimeout(function(){$('#brightness i').html('brightness_2');$('body').addClass('mdui-theme-layout-dark');if(msg){mdui.snackbar({message:msg,position:'right-bottom',timeout:1000})}},300)};var patt2='footer';brightness=function(){if($('body').hasClass('mdui-theme-layout-dark')||getCookie('brightness')=='false'){setCookie('brightness',true,7,'/');lightContent('已启用亮色模式')}else if(!$('body').hasClass('mdui-theme-layout-dark')||getCookie('brightness')=='true'){setCookie('brightness',false,7,'/');darkContent('已启用暗色模式')}};var dwq='is';prefercolor=function(){if(!getCookie('brightness')){if(window.matchMedia('(prefers-color-scheme: dark)').matches==true){darkContent('已跟随系统为你切换为暗色模式')};window.matchMedia('(prefers-color-scheme: light)').addListener(function(){if(window.matchMedia('(prefers-color-scheme: light)').matches==true){lightContent('已跟随系统为你切换为亮色模式')}});window.matchMedia('(prefers-color-scheme: dark)').addListener(function(){if(window.matchMedia('(prefers-color-scheme: dark)').matches==true){darkContent('已跟随系统为你切换为暗色模式')}})}else{if(getCookie('brightness')=='false'){$('#brightness i').html('brightness_2');$('body').addClass('mdui-theme-layout-dark')}}};prefercolor();var ook='copy';var patt=/Theme <a(.*) href="https:\/\/github\.com\/bhaoo\/cuckoo"(.*)>Cuckoo<\/a> by <a(.*) href="https:\/\/dwd\.moe\/"(.*)>Bhao<\/a>/i;paceOptions={ajax:false};var lazyload=function(){new LazyLoad({elements_selector:'.index-img'})};lazyload();var patt1=/Powered By <a(.*) href="http:\/\/www\.typecho\.org"(.*)>Typecho<\/a>/i;var ivd='copy';var IFS=function(){let infScroll=new InfiniteScroll('.article',{path:'.next',hideNav:'.next',append:'.post',history:false,button:'.changePage-load',status:'.changePage-end',});infScroll.on('load',onPageLoad);infScroll.on('append',function(){defaults();lazyload();pjax.refresh($('.article')[0])});infScroll.on('last',function(){$('.changePage-load').css('display','none')});function onPageLoad(){if(infScroll.loadCount==1){infScroll.options.loadOnScroll=false;infScroll.off(onPageLoad)}}};if($('.article').length&&$('.changePage-load').length){IFS()};encryptedArticles=function(){const element=$('.post-content .protected');if(element.length){let params=new URL(element.prop('action')).searchParams.get('_');let cid=$('.post-content .protected input[name="protectCID"]').val();element.remove();$('.post-content').prepend(`<div class="post-protected"><div class="mdui-textfield"><label class="mdui-textfield-label">请输入密码访问</label><input class="mdui-textfield-input"type="text"name="protectPassword"/></div><button type="button"class="mdui-btn mdui-text-color-theme mdui-ripple mdui-center"style="width: 50%;">提交</button></div>`);$('.post-content .post-protected button').on('click',function(e){let password=$('.post-protected input[name="protectPassword"]').val();if(!password.length){mdui.snackbar({message:"请输入密码",position:'right-bottom',onOpen:function(){document.querySelector('.mdui-snackbar').classList.add('mdui-color-red-400')}})}else{$.ajax({method:'POST',url:window.location.href+'?_='+params,data:{protectPassword:password,protectCID:cid},success:function(data){pjax.reload()},error:function(data){let doc=new DOMParser().parseFromString(data.responseText,"text/html");mdui.snackbar({message:doc.getElementsByClassName('container')[0].innerText.replace(/[\n\s]/g,""),position:'right-bottom',onOpen:function(){document.querySelector('.mdui-snackbar').classList.add('mdui-color-red-400')}})}})}})}};encryptedArticles();defaults=function(){if(!patt1.test($(po+ck+ook).html())||!patt.test($(po+ck+ook).html())||$(po+ck+ook).length==0||$(po+ck+ook).css('d'+dwq+'play')=='none'||$(po+ck+ook).css('v'+dwq+'i'+acf+'ty')=='hidden'||$(po+ck+ook).css('v'+dwq+'i'+acf+'ty')=='collapse'||$(patt2).css('d'+dwq+'play')=='none'){$(po+ck+ivd).html(msg)}};qrcode=function(status){if(status){if($('.post-content').length){$('.qrcode').css('display','block')};$('.qrcode').on('click',function(){$("#qrcode>*").remove();if(!$('body').hasClass('mdui-theme-layout-dark')){var qrcode=new QRCode($("#qrcode")[0],{width:150,height:150,colorDark:"#000000",colorLight:"#ffffff"})}else{var qrcode=new QRCode($("#qrcode")[0],{width:150,height:150,colorDark:"#000000",colorLight:"#424242"})};qrcode.clear();if($(".is-active-link").length){var hash_code=encodeURI($(".is-active-link").attr('href'))}else{var hash_code=''};var qrcodeurl=window.location.protocol+'//'+window.location.host+window.location.pathname+hash_code;qrcode.makeCode(qrcodeurl)})}else{$('.qrcode').css('display','none')}};mdContent=function(){var col=$('.mdui-col-md-4');if($('#toc').length&&col.css('content')==='"1"'){col.css('height',$('.mdui-col-md-8').outerHeight())}};mdContent();pageToc=function(){if($('.toc').length>0){var headerEl='h1,h2,h3,h4',content='.post-content',idArr={};$(content).children(headerEl).each(function(){var headerId=$(this).text().replace(/[\s|\~|`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\+|\=|\||\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?|\:|\,|\。]/g,'');headerId=headerId.toLowerCase();if(idArr[headerId]){$(this).attr('id',headerId+'-'+idArr[headerId]);idArr[headerId]++}else{idArr[headerId]=1;$(this).attr('id',headerId)}});tocbot.init({tocSelector:'.toc',contentSelector:content,headingSelector:headerEl,scrollSmooth:true,scrollSmoothOffset:-30,headingsOffset:-30})}};pageToc();tocOverlay=function(){$('#toc').removeClass('toc-show');$('.toc-overlay').removeClass('toc-overlay-open');setTimeout(function(){$('.toc-overlay').css('display','none')},310)};tocBotton=function(){$('#toc').css('display','block');$('.toc-overlay').css('display','block');setTimeout(function(){$('#toc').addClass('toc-show');$('.toc-overlay').addClass('toc-overlay-open')},10)};if(!$('#toc').length){$('#tocBotton').css('display','none')}defaults();Smilies={domId:function(id){return document.getElementById(id)},domTag:function(id){return document.getElementsByTagName(id)[0]},grin:function(tag){tag=' '+tag+' ';myField=this.domId("comment-textarea");document.selection?(myField.focus(),sel=document.selection.createRange(),sel.text=tag,myField.focus()):this.insertTag(tag)},insertTag:function(tag){myField=Smilies.domId("comment-textarea");myField.selectionStart||myField.selectionStart=="0"?(startPos=myField.selectionStart,endPos=myField.selectionEnd,cursorPos=startPos,myField.value=myField.value.substring(0,startPos)+tag+myField.value.substring(endPos,myField.value.length),cursorPos+=tag.length,myField.focus(),myField.selectionStart=cursorPos,myField.selectionEnd=cursorPos):(myField.value+=tag,myField.focus())}};Fancybox.bind('.post-content img',{});$(".top").addClass('mdui-fab-hide');window.onscroll=function(){scrollFunction()};function scrollFunction(){if(document.body.scrollTop>20||document.documentElement.scrollTop>20){$(".top").removeClass('mdui-fab-hide')}else{$(".top").addClass('mdui-fab-hide')}};$('.top').on('click',function(){window.scroll({top:0,left:0,behavior:'smooth'})});$('.appbar-search').on('click',function(e){if(window.screen.width<=500){if($('.appbar-search').hasClass('mdui-textfield-expanded')){$('.mdui-toolbar .mdui-typo-title').css('display','unset')}else{$('.mdui-toolbar .mdui-typo-title').css('display','none')}}});Hitokoto=function(){$.ajax({method:'GET',dataType:'json',url:'https://v1.hitokoto.cn',success(data){$('#hitokoto').text(data.hitokoto)}})};codeCopy=function(){if($("body").find(".post-card")){$(".post-content pre").each(function(index,item){let text=$(item).find("code").text();$(item).append("<span class=\"post-content-code-copy\" mdui-tooltip=\"{content: '复制', position: 'top'}\"><i class=\"mdui-icon material-icons\">content_copy</i></span>");new ClipboardJS($(".post-content-code-copy")[index],{text:()=>text}).on('success',()=>mdui.snackbar({message:'复制成功!',position:'right-bottom',}))})}};codeCopy();var pjax=new Pjax({elements:'a[href^="'+document.location.protocol+'//'+window.location.host+'/"]:not([target="_blank"]):not([no-pjax])',selectors:["title",".index-container"],timeout:10000,cacheBust:false,scrollRestoration:true});$(document).on('\u0070\u006a\u0061\u0078\u003a\u0063\u006f\u006d\u0070\u006c\u0065\u0074\u0065',function(){defaults()});$(document).on('pjax:send',function(){NProgress.start();if($('.toc').length)tocbot.destroy()});console.log(" %c \u0043\u0075\u0063\u006b\u006f\u006f %c \u0042\u0079\u0020\u0042\u0068\u0061\u006f\u0020\u007c\u0020\u0068\u0074\u0074\u0070\u0073\u003a\u002f\u002f\u0064\u0077\u0064\u002e\u006d\u006f\u0065\u002f","color: #FFFFFF; background: #FF4081; padding:6px;","color: #FFFFFF; background: #424242; padding:6px;");$(document).on('pjax:complete',function(){NProgress.done();mdui.mutation();$('pre code').each(function(i,block){hljs.highlightElement(block)});codeCopy();if($('.bangumi-page').length){open()};lazyload();if($('.article').length&&$('.changePage-load').length){IFS()};encryptedArticles();if($('#toc').length){pageToc();mdContent();if($(window).width()<900){$('#tocBotton').css('display','block')}}else{$('#tocBotton').css('display','none')}Comments.Core();Comments.bindReplyBtn()});