新年灯笼
借鉴:tzy 大佬(Fomalhaut 整理)。本站改动:脚本重写成单文件注入,支持 ?text= 自定义文字,移动端缩放与位置也做了适配。
新年灯笼
文件 :[Blogroot]/source/js/denglong.js | 改法 :新建文件,整段写入。灯笼的样式、DOM 和动画都在这一个自执行脚本里,不用再动 CSS。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 (function ( ) { var src = document .currentScript .src ; var text = new URLSearchParams (src.split ('?' )[1 ] || '' ).get ('text' ) || '新年快乐' ; var css = ` .deng-container{position:relative;top:10px;z-index:9999;pointer-events:none;} .deng-box{position:fixed;top:15px;} .deng-box1{left:20px}.deng-box2{left:130px}.deng-box3{right:110px}.deng-box4{right:20px} .deng{position:relative;width:120px;height:90px;background:rgba(216,0,15,.8); border-radius:50%;animation:swing 3s infinite ease-in-out; box-shadow:-5px 5px 50px 4px #fa6c00;} .deng-a{width:100px;height:90px;margin-left:7px;border:2px solid #dc8f03; border-radius:50%;display:flex;justify-content:center;} .deng-b{width:65px;height:83px;border:2px solid #dc8f03;border-radius:60%;} .xian{position:absolute;top:-20px;left:60px;width:2px;height:20px;background:#dc8f03;} .deng-t{font-family:'华文行楷',Arial,sans-serif;font-size:3.2rem;color:#dc8f03; font-weight:700;line-height:85px;text-align:center;} .shui-a{position:relative;width:5px;height:20px;margin:-5px 0 0 59px;background:orange; border-radius:0 0 5px 5px;animation:swing 4s infinite ease-in-out;} .shui-b{position:absolute;top:14px;left:-2px;width:10px;height:10px; background:#dc8f03;border-radius:50%;} .shui-c{position:absolute;top:18px;left:-2px;width:10px;height:35px; background:orange;border-radius:0 0 0 5px;} .deng:before,.deng:after{content:" ";display:block;position:absolute; border-radius:5px;border:1px solid #dc8f03; background:linear-gradient(to right,#dc8f03,orange,#dc8f03,orange,#dc8f03);} .deng:before{top:-7px;left:29px;height:12px;width:60px;z-index:999;} .deng:after{bottom:-7px;left:10px;height:12px;width:60px;margin-left:20px;} @media(max-width:768px){.deng-t{font-size:2.5rem}.deng-box{transform:scale(.5);top:-15px} .deng-box1{left:-22%}.deng-box2{left:0}.deng-box3{right:50px}.deng-box4{right:-10px}} @keyframes swing{0%{transform:rotate(-10deg)}50%{transform:rotate(10deg)}100%{transform:rotate(-10deg)}} ` ; var style = document .createElement ('style' ); style.textContent = css; document .head .appendChild (style); var wrap = document .createElement ('div' ); wrap.className = 'deng-container' ; wrap.innerHTML = Array .from (text).map (function (t, i ) { return '<div class="deng-box deng-box' + (i % 4 + 1 ) + '">' + '<div class="deng"><div class="xian"></div>' + '<div class="deng-a"><div class="deng-b"><div class="deng-t">' + t + '</div></div></div>' + '<div class="shui-a"><div class="shui-c"></div><div class="shui-b"></div></div>' + '</div></div>' ; }).join ('' ); document .body .appendChild (wrap); })();
文件 :[Blogroot]/_config.butterfly.yml | 改法 :在 inject 的 bottom 列表末尾追加下面那一行;inject: 和 bottom: 两个键配置里本来就有,不要重复写。?text= 后面就是灯笼上显示的字。
1 2 3 inject: bottom: - <script defer src="/js/denglong.js?text=新年快乐"></script>
自定义标题
借鉴:Fomalhaut(猕猴桃)。本站改动:换成两段中文提示,切回页面 2 秒后恢复原标题,并用 inject.bottom 本地加载。
自定义标题
文件 :[Blogroot]/source/js/title.js | 改法 :新建文件,整段写入;本站已有同名文件且内容一致,有的话直接用。
1 2 3 4 5 6 7 8 9 10 11 12 13 var OriginTitile = document .title ;var titleTime;document .addEventListener ('visibilitychange' , function ( ) { if (document .hidden ) { document .title = '👀跑哪里去了~' ; clearTimeout (titleTime); } else { document .title = '🐖抓到你啦~' ; titleTime = setTimeout (function ( ) { document .title = OriginTitile ; }, 2000 ); } });
文件 :[Blogroot]/_config.butterfly.yml | 改法 :在 inject 的 bottom 列表末尾追加这一行。
1 2 3 inject: bottom: - <script async src="/js/title.js"></script>
星空背景(仅暗色模式)
借鉴:Fomalhaut(猕猴桃)。本站改动:只保留暗色模式启用,画布尺寸与层级按本站页面结构调整。
星空背景
文件 :[Blogroot]/source/css/universe.css | 改法 :新建文件,整段写入(本站已有同名文件,覆盖前先备份)。这段样式只管画布定位和「亮色模式隐藏」,配色在脚本里。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 #universe { display : block; position : fixed; margin : 0 ; padding : 0 ; border : 0 ; left : 0 ; top : 0 ; width : 100% ; height : 100% ; pointer-events : none; z-index : -1 ; } [data-theme="light" ] #universe { display : none; }
文件 :[Blogroot]/source/js/universe.js | 改法 :新建文件,整段写入(本站同名文件是限 30fps 的增强版,两版选一个)。脚本从 #universe 取画布,画布在下一步的 inject.bottom 里创建。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 (function ( ) { var canvas = document .getElementById ('universe' ); if (!canvas) return ; var ctx = canvas.getContext ('2d' ); var stars = []; var raf = 0 ; function resize ( ) { canvas.width = window .innerWidth ; canvas.height = window .innerHeight ; stars = Array .from ({ length : 160 }, function ( ) { return { x : Math .random () * canvas.width , y : Math .random () * canvas.height , r : Math .random () * 1.2 + 0.3 , s : Math .random () * 0.25 + 0.05 }; }); } function draw ( ) { ctx.clearRect (0 , 0 , canvas.width , canvas.height ); ctx.fillStyle = 'rgba(255,255,255,.8)' ; stars.forEach (function (p ) { ctx.beginPath (); ctx.arc (p.x , p.y , p.r , 0 , Math .PI * 2 ); ctx.fill (); p.y -= p.s ; if (p.y < 0 ) p.y = canvas.height ; }); raf = requestAnimationFrame (draw); } function sync ( ) { var dark = document .documentElement .getAttribute ('data-theme' ) === 'dark' ; cancelAnimationFrame (raf); if (dark && !document .hidden ) draw (); else ctx.clearRect (0 , 0 , canvas.width , canvas.height ); } resize (); window .addEventListener ('resize' , function ( ) { resize (); sync (); }); document .addEventListener ('visibilitychange' , sync); new MutationObserver (sync).observe (document .documentElement , { attributes : true , attributeFilter : ['data-theme' ] }); sync (); })();
文件 :[Blogroot]/_config.butterfly.yml | 改法 :inject.head 末尾追加 <link> 那一条,inject.bottom 末尾追加 <canvas> 和 <script> 两条。顺序不能反:画布必须先于脚本出现,否则脚本取不到 #universe。
1 2 3 4 5 6 inject: head: - <link rel="stylesheet" href="/css/universe.css" media="only x" onload="this.onload=null;this.media='all'"> bottom: - <canvas id="universe"></canvas> - <script defer src="/js/universe.js"></script>
猫猫挂件
借鉴:tzy 大佬(Fomalhaut 整理)。本站改动:样式按本站层级重写,移动端默认隐藏。
猫猫挂件
文件 :[Blogroot]/source/css/cat.css | 改法 :新建文件,整段写入。本站已改用 fomal/cursor.js,没有这个文件;按本篇做就新建。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .neko { position : fixed; right : 20px ; bottom : 0 ; width : 70px ; height : 100px ; background-repeat : no-repeat; background-position : bottom; background-size : contain; z-index : 100 ; cursor : pointer; pointer-events : auto; transition : transform .25s ease; } .neko :hover { transform : scale (1.08 ); }@media screen and (max-width : 768px ) { .neko { display : none !important ; } }
文件 :[Blogroot]/source/js/cat.js | 改法 :新建文件,整段写入(本站同名文件是另一套实现且已停止注入,照本篇覆盖即可)。脚本依赖 jQuery,注入顺序见下一步。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (function ($ ) { if (document .body .clientWidth <= 992 ) return ; if ($('.neko' ).length ) return ; var neko = $('<div class="neko" id="neko1" title="喵~"></div>' ); neko.css ('background-image' , 'url(/img/cat.png)' ); $('body' ).append (neko); $(window ).on ('scroll' , function ( ) { neko.css ('display' , $(window ).scrollTop () > 10 ? 'block' : 'none' ); }); neko.on ('mouseover' , function ( ) { neko.css ('background-image' , 'url(/img/cat-hover.png)' ); }).on ('mouseout' , function ( ) { neko.css ('background-image' , 'url(/img/cat.png)' ); }); $(window ).on ('pjax:complete' , function ( ) { if (!$('.neko' ).length ) $('body' ).append (neko); }); })(jQuery);
把猫猫图片放到 [Blogroot]\source\img\cat.png、[Blogroot]\source\img\cat-hover.png。
文件 :[Blogroot]/_config.butterfly.yml | 改法 :inject.head 末尾追加 CSS 那一条,inject.bottom 末尾追加 jQuery 和 cat.js 两条。jQuery 必须排在 cat.js 前面;cat.js 带 data-pjax,切页后才会重新执行。
1 2 3 4 5 6 inject: head: - <link rel="stylesheet" href="/css/cat.css" media="only x" onload="this.onload=null;this.media='all'"> bottom: - <script defer src="/js/jquery.min.js"></script> - <script defer data-pjax src="/js/cat.js"></script>
jquery.min.js 用官方 jQuery 压缩版放入 [Blogroot]\source\js\。
自定义鼠标样式
借鉴:Fomalhaut(猕猴桃)。本站改动:脚本按本站交互重写,触屏设备直接跳过,不再加载额外光标资源。
自定义鼠标样式
文件 :[Blogroot]/source/js/cursor.js | 改法 :新建文件,整段写入(本站同名文件是「猫猫 + 右键菜单」三合一版,覆盖前先备份)。脚本只负责跟随和状态类,外观在下一步的 custom.css 里。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 (function ( ) { if (window .matchMedia ('(pointer: coarse)' ).matches ) return ; var dot = document .createElement ('div' ); dot.id = 'cursor' ; document .body .appendChild (dot); var x = 0 , y = 0 , raf = 0 ; document .addEventListener ('mousemove' , function (e ) { x = e.clientX ; y = e.clientY ; if (raf) return ; raf = requestAnimationFrame (function ( ) { dot.style .left = x + 'px' ; dot.style .top = y + 'px' ; raf = 0 ; }); }); document .addEventListener ('mouseover' , function (e ) { dot.classList .toggle ('hover' , !!e.target .closest ('a, button, .site-page' )); }); document .addEventListener ('mousedown' , function ( ) { dot.classList .add ('active' ); }); document .addEventListener ('mouseup' , function ( ) { dot.classList .remove ('active' ); }); document .addEventListener ('mouseleave' , function ( ) { dot.classList .add ('hidden' ); }); document .addEventListener ('mouseenter' , function ( ) { dot.classList .remove ('hidden' ); }); })();
文件 :[Blogroot]/source/css/custom.css | 改法 :追加到文件末尾。custom.css 已经由 inject.head 引入,加规则就生效;改完把引用上的 ?v= 版本号升一位。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #cursor { position : fixed; top : 0 ; left : 0 ; margin : -8px 0 0 -8px ; width : 16px ; height : 16px ; background : rgb (57 ,197 ,187 ); border-radius : 8px ; opacity : .25 ; z-index : 10086 ; pointer-events : none; transition : .2s ease-in-out; transition-property : background, opacity, transform; } #cursor .hidden { opacity : 0 ; }#cursor .hover { opacity : .1 ; transform : scale (2.5 ); }#cursor .active { opacity : .5 ; transform : scale (.5 ); }@media (pointer : coarse) { #cursor { display : none; } }
文件 :[Blogroot]/_config.butterfly.yml | 改法 :在 inject 的 bottom 列表末尾追加这一行。
1 2 3 inject: bottom: - <script defer src="/js/cursor.js"></script>
右键菜单
借鉴:Fomalhaut(猕猴桃)。本站改动:Pug 注入位置按 5.7.2 调整,菜单项与本站现有功能对齐。
右键菜单
文件 :[Blogroot]/themes/butterfly/layout/includes/rightmenu.pug | 改法 :新建文件,整段写入。本站 5.7.2 主题里已有同名文件(菜单项更多),这是主题目录、升级主题会被覆盖,改前先备份。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #rightMenu.js-pjax .rightMenu-group.rightMenu-small a.rightMenu-item(href="javascript:window.history.back();") i.fa.fa-arrow-left a.rightMenu-item(href="javascript:window.history.forward();") i.fa.fa-arrow-right a.rightMenu-item(href="javascript:window.location.reload();") i.fa.fa-refresh a.rightMenu-item(href="javascript:window.scrollTo(0,0);") i.fa.fa-arrow-up .rightMenu-group.rightMenu-line.hide#menu-text a.rightMenu-item(href="javascript:rmf.copySelect();") i.fa.fa-copy span='复制' a.rightMenu-item(href="javascript:window.open('https://www.baidu.com/s?wd='+window.getSelection().toString());") i.fa.fa-search span='百度搜索' a.rightMenu-item(href="javascript:rmf.copyWordsLink();") i.fa.fa-link span='复制本文地址'
文件 :[Blogroot]/source/js/rightmenu.js | 改法 :新建文件,整段写入(本站同名文件更长,带遮罩和更多菜单项,整段覆盖不影响其它模块)。脚本按 id="rightMenu" 取节点,要和上一步的 Pug 对上。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 var rmf = {};var rightMenu = document .getElementById ('rightMenu' );var mouseMode = false ;rmf.showRightMenu = function (show, y, x ) { if (!rightMenu) return ; rightMenu.style .display = show ? 'block' : 'none' ; if (show) { rightMenu.style .top = y + 'px' ; rightMenu.style .left = x + 'px' ; } }; rmf.copySelect = function ( ) { var text = window .getSelection ().toString (); if (text) navigator.clipboard .writeText (text); }; rmf.copyWordsLink = function ( ) { navigator.clipboard .writeText (window .location .href ); }; function changeMouseMode ( ) { mouseMode = !mouseMode; document .body .classList .toggle ('mouse-mode' , mouseMode); } document .addEventListener ('contextmenu' , function (e ) { e.preventDefault (); rmf.showRightMenu (true , e.clientY , e.clientX ); }); document .addEventListener ('click' , function ( ) { rmf.showRightMenu (false ); });
文件 :[Blogroot]/themes/butterfly/layout/includes/layout.pug | 改法 :在 include ./rightside.pug 之后插入 !=partial('includes/rightmenu',{}, {cache:true}) 一行;本站第 82 行已有这一行,确认存在就不用改。下面整段是插入后的上下文,只加一行,别整段粘贴。
1 2 3 include ./rightside.pug !=partial('includes/rightmenu',{}, {cache:true}) include ./additional-js.pug
文件 :[Blogroot]/source/css/custom.css | 改法 :追加到文件末尾。菜单默认 display: none,由 rightmenu.js 在右键时改成 block。
1 2 3 4 5 6 7 8 9 10 11 12 #rightMenu { display : none; position : fixed; z-index : 10087 ; padding : 6px ; border-radius : 8px ; background : rgba (255 ,255 ,255 ,.95 ); box-shadow : 0 4px 16px rgba (0 ,0 ,0 ,.18 ); } [data-theme="dark" ] #rightMenu { background : rgba (30 ,35 ,45 ,.95 ); }#rightMenu .rightMenu-item { display : block; padding : 6px 12px ; cursor : pointer; }.rightMenu-line .hide { display : none; }
文件 :[Blogroot]/_config.butterfly.yml | 改法 :在 inject 的 bottom 列表末尾追加这一行。
1 2 3 inject: bottom: - <script async type="text/javascript" src="/js/rightmenu.js"></script>
禁止打开开发者工具
借鉴:tzy 大佬(Fomalhaut 整理)。本站改动:Pug 插入位置按 5.7.2 调整,脚本保留原提示逻辑。
禁止 F12
文件 :[Blogroot]/themes/butterfly/layout/includes/layout.pug | 改法 :在 html(...) 那一行下面、head 之前插入 //-魔改禁F12开始 到 //-魔改禁F12结束 之间的两个 script. 块;本站第 9 行起已有同样内容,有就不用再加。整段代码只是展示插入位置,doctype、html、head 都是原有行。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 doctype html html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside) //-魔改禁F12开始 script. ((function() {var callbacks = [],timeLimit = 50,open = false;setInterval(loop, 500);return {addListener: function(fn) {callbacks.push(fn);},cancleListenr: function(fn) {callbacks = callbacks.filter(function(v) {return v !== fn;});}} function loop() {var startTime = new Date();debugger;if (new Date() - startTime > timeLimit) {if (!open) {callbacks.forEach(function(fn) {fn.call(null);});}open = true;window.stop();alert('你真坏,请关闭控制台!');document.body.innerHTML = "";} else {open = false;}}})()).addListener(function() {window.location.reload();}); script. function toDevtools(){ let num = 0; let devtools = new Date(); devtools.toString = function() { num++; if (num > 1) { alert('你真坏,请关闭控制台!'); window.location.href = "about:blank"; blast(); } } console.log('', devtools); } toDevtools(); //-魔改禁F12结束 head
文件 :[Blogroot]/source/js/f12.js | 改法 :新建文件,整段写入(本站同名文件只有这一段、逻辑一致,可以直接用)。
1 2 3 4 5 6 7 8 9 document .onkeydown = function (e ) { if (123 == e.keyCode || (e.ctrlKey && e.shiftKey && (74 === e.keyCode || 73 === e.keyCode || 67 === e.keyCode )) || (e.ctrlKey && 85 === e.keyCode )) { e.keyCode = 0 ; e.returnValue = false ; return false ; } };
文件 :[Blogroot]/_config.butterfly.yml | 改法 :在 inject 的 bottom 列表末尾追加这一行;本站这一行目前是注释状态,要恢复就取消前面的 #。
1 2 3 inject: bottom: - <script async src="/js/f12.js"></script>
帧率检测
借鉴:LYX(Fomalhaut 整理)。本站改动:显示样式与阈值按本站低性能模式调整,低于 35 帧才触发降级。
帧率检测
文件 :[Blogroot]/source/js/fps.js | 改法 :新建文件,整段写入(本站同名文件带「流畅 / 卡顿」文字和开关,覆盖前先备份)。脚本要等 #fps 节点存在才工作,那个 span 在后面的 inject.head 里。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 (function ( ) { var box = document .getElementById ('fps' ); if (!box) return ; var frames = 0 , last = performance.now (), lowStart = 0 , shown = -1 ; function tick (now ) { frames++; if (now - last >= 1000 ) { var fps = Math .round (frames * 1000 / (now - last)); if (fps !== shown) { box.textContent = 'FPS ' + fps; shown = fps; } if (fps < 35 ) { if (!lowStart) lowStart = now; if (now - lowStart >= 2000 ) document .documentElement .classList .add ('low-perf' ); } else { lowStart = 0 ; document .documentElement .classList .remove ('low-perf' ); } frames = 0 ; last = now; } requestAnimationFrame (tick); } requestAnimationFrame (tick); })();
文件 :[Blogroot]/source/css/custom.css | 改法 :追加到文件末尾。第二段 html.low-perf 是给低性能模式用的,帧率恢复后脚本会把这个类摘掉。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #fps { position : fixed; right : 12px ; bottom : 12px ; z-index : 10088 ; padding : 2px 8px ; border-radius : 10px ; font-size : 12px ; background : rgba (0 ,0 ,0 ,.35 ); color : #fff ; pointer-events : none; } html .low-perf .parallax > use { animation : none !important ; -webkit-animation : none !important ; }
文件 :[Blogroot]/_config.butterfly.yml | 改法 :inject.head 末尾追加 <span id="fps"> 那一条,inject.bottom 末尾追加 <script> 那一条。这个 span 放 head 里不影响渲染,脚本靠 getElementById('fps') 找它。
1 2 3 4 5 inject: head: - <span id="fps" media="only x" onload="this.onload=null;this.media='all'"></span> bottom: - <script async src="/js/fps.js"></script>
控制台字符画
借鉴:安知鱼(Fomalhaut 整理)。本站改动:改成可直接替换站点名与网名的占位模板,颜色跟随本站主题色。
控制台字符画
文件 :[Blogroot]/source/js/console.js | 改法 :新建文件,整段写入,再把 <建站日期>、<站点名>、<你的网名> 三处占位换成自己的内容(本站同名文件是另一版,带农历信息,覆盖前先备份)。
1 2 3 4 5 6 7 8 (function ( ) { var start = new Date ('<建站日期>' ); var days = Math .floor ((Date .now () - start) / 86400000 ); var style = 'color:#5ea6e5;font-size:14px;font-weight:bold;' ; console .log ('%c<站点名>' , style); console .log ('%c小站已经苟活 ' + days + ' 天啦' , style); console .log ('%c© <你的网名>' , style); })();
文件 :[Blogroot]/_config.butterfly.yml | 改法 :在 inject 的 bottom 列表末尾追加这一行。
1 2 3 inject: bottom: - <script async src="/js/console.js"></script>
顶部渐变加载条
借鉴:Fomalhaut(猕猴桃)。本站改动:pace.js 改为本地加载,进度条配色与本站主题色同步。
顶部渐变加载条
把 pace.js 官方压缩版放到 [Blogroot]\source\js\pace.min.js。
文件 :[Blogroot]/source/css/progress_bar.css | 改法 :新建文件,整段写入(本站已有同名文件,就是这套进度条样式)。文件名要和下一步 preloader.pace_css_url 里的路径一致。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 .pace { pointer-events : none; user-select: none; z-index : 2000 ; position : fixed; margin : auto; top : 10px ; left : 0 ; right : 0 ; height : 8px ; border-radius : 8px ; width : 4rem ; background : #eaecf2 ; overflow : hidden; } .pace .pace-progress { box-sizing : border-box; transform : translate3d (0 ,0 ,0 ); max-width : 200px ; position : absolute; z-index : 2000 ; display : block; top : 0 ; right : 100% ; height : 100% ; width : 100% ; background : linear-gradient (-45deg , #ee7752 , #e73c7e , #23a6d5 , #23d5ab ); animation : gradient 1.5s ease infinite; background-size : 200% ; } .pace .pace-inactive { opacity : 0 ; transition : .3s ; top : -8px ; }@keyframes gradient { 0% { background-position : 0% 50% ; } 50% { background-position : 100% 50% ; } 100% { background-position : 0% 50% ; } }
文件 :[Blogroot]/themes/butterfly/layout/includes/loading/index.pug | 改法 :整段替换该文件;5.7.2 原版就是这个结构,本站没改过,等于核对一遍 source 的三条分支都在。主题目录的文件改动会被主题升级覆盖,改前备份。
1 2 3 4 5 6 7 8 if theme.preloader.enable if theme.preloader.source === 1 include ./fullpage-loading.pug else if theme.preloader.source === 2 include ./pace.pug else include ./fullpage-loading.pug include ./pace.pug
文件 :[Blogroot]/_config.butterfly.yml | 改法 :改顶层 preloader: 下的 enable、source、pace_css_url 三个值,键要顶格写。source: 3 表示全屏 loading 和顶部进度条一起启用;本站当前是 2,只开顶部进度条。
1 2 3 4 preloader: enable: true source: 3 pace_css_url: /css/progress_bar.css
文件 :[Blogroot]/_config.butterfly.yml | 改法 :在 inject 的 bottom 列表末尾追加这一行。pace.js 自己会生成进度条 DOM,这里只负责把脚本加载进来,少了这行页面不会出现进度条。
1 2 3 inject: bottom: - <script async src="/js/pace.min.js"></script>
改完怎么验证与部署 十节都改完后,先在本地走一遍再上传:
生成 :在博客根目录执行 hexo generate(简写 hexo g)。最后一行出现 Generated 才算过,有 Pug 或 YAML 报错先解决,layout.pug、rightmenu.pug 写错会直接编译失败。
本地预览 :执行 hexo server(简写 hexo s),打开 http://localhost:4000,逐个确认灯笼、标题切换、星空、猫猫、鼠标样式、右键菜单、F12 拦截、帧率、控制台字符画、顶部进度条是否都生效。
强制刷新或清缓存 :改过 CSS / JS 后按 Ctrl + F5;还不生效就 F12 → Application → Storage 清掉 Cache Storage。启用了 Service Worker 时先在 Application → Service Workers 里 Unregister 或勾 Update on reload,否则看到的一直是缓存里的旧文件。
F12 查 404 :Console 看有没有 Uncaught,Network 按状态码排序,确认 /js/denglong.js、/css/universe.css、/css/progress_bar.css 这些新路径返回 200。404 多半是目录写错(source/js 和 source/css 别混)或文件名大小写不一致。
部署 :把生成的 public/ 按原来的方式传上去——Nginx 把站点根目录指向 public/、GitHub Pages 推 public/、Vercel 重新部署,或执行 hexo deploy。上传后关掉缓存再访问线上地址,确认和本地一致。
版本号别忘了同步:_config.butterfly.yml 里 /css/custom.css?v=...、/js/xxx.js?v=... 的 ?v= 改一次升一次,否则浏览器或 CDN 会继续用旧缓存,出现「明明改了却没生效」。