综合美化模块教程
魔改前必看(我当你们都懂了,太细节的就不写在教程中了🤣🤣🤣)
- 博客魔改有风险,如果博客魔改出问题了又没有备份,可通过此项目查看基础源码进行 回滚: jerryc127/hexo-theme-butterfly、 ccknbc-actions/blog-butterfly。
- 这部分魔改基本上都是大佬们造好的轮子,我按照大佬们的轮子结合自己的喜好进行魔改的,具体见我友人帐第一个栏目大佬们的网站,本处仅做一个总结,如有侵权请联系删除。
- 鉴于每个人的根目录名称都不一样,本帖 博客根目录 一律以
[BlogRoot]
指代。 - 本帖涉及魔改源码的内容,会使用 diff代码块 标识,复制时请 不要忘记删除 前面的
+、-
符号。 - 因为
.pug
和.styl
以及.yml
等对缩进要求较为严格,请尽量 不要使用记事本等无法提供语法高亮的文本编辑器 进行修改。 - 本帖基于
Butterfly主题
进行魔改方案编写,因此请读者优先掌握 Butterfly主题官方文档 的内容后再来进行魔改。 - 魔改会过程常常引入 自定义的css与js文件,方法见 Hexo博客添加自定义css和js文件(太懒了不想自己写)
1.介绍
本教程是在Leonus大佬的基础上做自己的二次开发,加上了很多功能。为什么要单独开一篇文章讲这个教程?因为这个教程可能长期会更新,后面可能会加功能、改动功能之类的;而且这个魔改的耦合程度比较高,代码量也比较大,魔改失败的概率会比较大,我第一次写也没有运行过,只是凭印象写的,所以专门开一篇文章供大家讨论吧。(毕竟我也只是个非科班的,不是专门搞前端这方面的,比我厉害的大佬多了去了🤣)大家有什么好的创意也可以在评论区提出来,或者在这个基础上继续进行二次开发,创造出更有意思的功能!
效果预览
此魔改耦合程度较高,需要完成的前置教程比较多,稍微不小心就会改错,建议一定要备份好自己的代码再来改动,改废了不赔偿!前置教程与知识:星空背景、霓虹灯、页面css参数化、帧率监测、鼠标魔改、按键防抖、自定义字体引入、vue样式弹窗的的引入、开启Pjax、外挂标签、白天黑夜手机电脑不同背景、熟悉Leonus的原教程以及会引入css与js文件、有最基础的html、pug、css、js知识
2.教程正文
- 在
[BlogRoot]\themes\butterfly\layout\includes\header\nav.pug
适当的位置加入如下代码,这是winbox
的入口按钮。我是在导航栏引入的,如果在右边按钮引入请参考leonus的代码,差不多:
1 | + //- 美化设置 |
如果之前按着我的导航栏修改,那就可以直接用了,不用加,贴一份修改好后的 nav.pug
:
1 | nav#nav |
新建
[BlogRoot]\source\js\meihua.js
,这是该模块的主体函数,比较长,主要是分为3部分:加载页面逻辑
、窗口绘制
、窗口内部逻辑
,里面的壁纸可以自己进行替换(记住不要直接用我的),默认背景
、默认字体
需要你自己修改(代码中有xxx
的地方),另外模块内部有什么东西就在winbox.body.innerHTML
里面加就行: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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591// 更新版本需要每个用户都恢复一次默认设置
if (localStorage.getItem("reset_2") == undefined) {
localStorage.setItem("reset_2", "1");
localStorage.removeItem("reset_1");
clearItem();
setTimeout(function () {
new Vue({
data: function () {
this.$notify({
title: "提示🍒",
message: " (。・∀・)ノ゙由于网站部分设置项更新,当前已为您重置所有设置,祝您愉快!",
position: 'top-left',
offset: 50,
showClose: true,
type: "success",
duration: 8000
});
}
})
}, 1500);
}
// 清除localStorage配置项
function clearItem() {
localStorage.removeItem('blogbg');
localStorage.removeItem('universe');
localStorage.removeItem('blur');
localStorage.removeItem('fpson');
localStorage.removeItem('transNum');
localStorage.removeItem('bing');
localStorage.removeItem('blurRad');
localStorage.removeItem('font');
localStorage.removeItem('themeColor');
localStorage.removeItem('rs');
localStorage.removeItem('mouse');
}
// 设置字体
if (localStorage.getItem("font") == undefined) {
localStorage.setItem("font", "xxx");
}
setFont(localStorage.getItem("font"));
function setFont(n) {
localStorage.setItem("font", n)
if (n == "default") {
document.documentElement.style.setProperty('--global-font', '-apple-system');
document.body.style.fontFamily = "-apple-system, Consolas_1, BlinkMacSystemFont, 'Segoe UI' , 'Helvetica Neue' , Lato, Roboto, 'PingFang SC' , 'Microsoft JhengHei' , 'Microsoft YaHei' , sans-serif";
}
else {
document.documentElement.style.setProperty('--global-font', n);
document.body.style.fontFamily = "var(--global-font),-apple-system, IBM Plex Mono ,monosapce,'微软雅黑', sans-serif";
}
try { setFontBorder(); } catch (err) { };
}
// 设置字体选择框边界
function setFontBorder() {
var curFont = localStorage.getItem("font");
var swfId = "swf_" + curFont;
document.getElementById(swfId).style.border = "2px solid var(--theme-color)";
Array.prototype.forEach.call(document.getElementsByClassName("swf"), function (ee) {
if (ee.id != swfId) ee.style.border = "2px solid var(--border-color)";
});
}
// 设置主题色
if (localStorage.getItem("themeColor") == undefined) {
localStorage.setItem("themeColor", "green");
}
setColor(localStorage.getItem("themeColor"));
function setColor(c) {
document.getElementById("themeColor").innerText = `:root{--theme-color:` + map.get(c) + ` !important}`;
localStorage.setItem("themeColor", c);
// 刷新鼠标颜色
CURSOR.refresh();
// 设置一个带有透明度的主题色,用于菜单栏的悬浮颜色
var theme_color = map.get(c);
var trans_theme_color = "rgba" + theme_color.substring(3, theme_color.length - 1) + ", 0.7)";
document.documentElement.style.setProperty("--text-bg-hover", trans_theme_color);
}
// 控制星空背景特效开关
if (localStorage.getItem("universe") == undefined) {
localStorage.setItem("universe", "block");
}
setUniverse2(localStorage.getItem("universe"));
function setUniverse2(c) {
document.getElementById("universe").style.display = c;
localStorage.setItem("universe", c);
}
function setUniverse() {
if (document.getElementById("universeSet").checked) {
setUniverse2("block");
} else {
setUniverse2("none");
}
}
// 帧率监测开关
if (localStorage.getItem("fpson") == undefined) {
localStorage.setItem("fpson", "1");
}
function fpssw() {
if (document.getElementById("fpson").checked) {
localStorage.setItem("fpson", "1");
} else {
localStorage.setItem("fpson", "0");
}
setTimeout(reload, 600);
}
// 刷新窗口
function reload() {
window.location.reload();
}
// 侧边栏开关
if (localStorage.getItem("rs") == undefined) {
localStorage.setItem("rs", "block");
}
if (localStorage.getItem("rs") == "block") {
document.getElementById("rightSide").innerText = `:root{--rightside-display: block}`;
} else {
document.getElementById("rightSide").innerText = `:root{--rightside-display: none}`;
}
function toggleRightside() {
// 先设置localStorage变量
if (document.getElementById("rightSideSet").checked) {
localStorage.setItem("rs", "block");
document.getElementById("rightSide").innerText = `:root{--rightside-display: block}`;
} else {
localStorage.setItem("rs", "none");
document.getElementById("rightSide").innerText = `:root{--rightside-display: none}`;
}
}
// 透明度调节滑块
if (localStorage.getItem("transNum") == undefined) {
localStorage.setItem("transNum", 95);
}
var curTransNum = localStorage.getItem("transNum");
var curTransMini = curTransNum * 0.95;
document.getElementById("transPercent").innerText = `:root{--trans-light: rgba(253, 253, 253, ${curTransNum}%) !important; --trans-dark: rgba(25, 25, 25, ${curTransNum}%) !important} `;
function setTrans() {
var elem = document.getElementById("transSet");
var newTransNum = elem.value;
var target = document.querySelector('.transValue');
target.innerHTML = "透明度 (0%-100%): " + newTransNum + "%";
localStorage.setItem("transNum", newTransNum);
curTransMini = newTransNum * 0.95;
curTransNum = newTransNum; // 更新当前透明度
document.querySelector('#rang_trans').style.width = curTransMini + "%";
document.getElementById("transPercent").innerText = `:root{--trans-light: rgba(253, 253, 253, ${newTransNum}%) !important; --trans-dark: rgba(25, 25, 25, ${newTransNum}%) !important} `;
};
// 模糊度调节滑块
if (localStorage.getItem("blurRad") == undefined) {
localStorage.setItem("blurRad", 20);
}
var curBlur = localStorage.getItem("blurRad"); // 当前模糊半径
var miniBlur = curBlur * 0.95;
document.getElementById("blurNum").innerText = `:root{--blur-num: blur(${curBlur}px) saturate(120%) !important`;
function setBlurNum() {
var elem = document.getElementById("blurSet");
var newBlur = elem.value;
var target = document.querySelector('.blurValue');
target.innerHTML = "模糊半径 (开启模糊生效 0px-100px): " + newBlur + "px";
localStorage.setItem("blurRad", newBlur);
curBlur = newBlur;
miniBlur = curBlur * 0.95;
// var max = elem.getAttribute("max");
document.querySelector('#rang_blur').style.width = miniBlur + "%";
document.getElementById("blurNum").innerText = `:root{--blur-num: blur(${curBlur}px) saturate(120%) !important`;
};
// 模糊效果开关
if (localStorage.getItem("blur") == undefined) {
localStorage.setItem("blur", 0);
}
if (localStorage.getItem("blur") == 0) {
document.getElementById("settingStyle").innerText = `:root{--backdrop-filter: none}`;
} else {
document.getElementById("settingStyle").innerText = `:root{--backdrop-filter: var(--blur-num)}`;
}
function setBlur() {
if (document.getElementById("blur").checked) {
localStorage.setItem("blur", 1);
document.getElementById("settingStyle").innerText = `:root{--backdrop-filter: var(--blur-num)}`;
} else {
localStorage.setItem("blur", 0);
document.getElementById("settingStyle").innerText = `:root{--backdrop-filter: none}`;
}
}
// 切换自定义颜色
var defineColor = localStorage.getItem("blogbg") && localStorage.getItem("blogbg").charAt(0) == '#' ? localStorage.getItem("blogbg") : '#F4D88A';
function changeBgColor() {
changeBg(document.querySelector("#colors").value);
}
// 更换背景(自己的代码)
if (localStorage.getItem("blogbg") != undefined) {
let curBg = localStorage.getItem("blogbg");
document.getElementById("defineBg").innerText = `:root{
--default-bg: ${curBg};
--darkmode-bg: ${curBg};
--mobileday-bg: ${curBg};
--mobilenight-bg: ${curBg};
}`;
changeBg(curBg);
} else {
// 替换你自己的默认背景
document.getElementById("defineBg").innerText = `:root{
--default-bg: url(xxx);
--darkmode-bg:url(xxx);
--mobileday-bg: url(xxx);
--mobilenight-bg: url(xxx);
}`;
}
function changeBg(s) {
let bg = document.getElementById("web_bg");
if (s.charAt(0) == "#") {
bg.style.backgroundColor = s;
bg.style.backgroundImage = "none";
defineColor = s;
} else {
bg.style.backgroundImage = s
defineColor = '#F4D88A';
};
localStorage.setItem("blogbg", s);
localStorage.setItem("bing", "false");
if (document.getElementById("bingSet")) document.getElementById("bingSet").checked = false;
}
// 切换链接对应的背景(加入了链接检验与防抖)
function getPicture() {
debounce(getPicture_, 300);
}
function getPicture_() {
let bg = document.getElementById("web_bg");
checkImgExists(document.getElementById("pic-link").value).then(() => {
// 有效的图片链接
var link = "url(" + document.getElementById("pic-link").value + ")";
bg.style.backgroundImage = link;
localStorage.setItem("blogbg", link);
localStorage.setItem("bing", "false");
if (document.getElementById("bingSet")) document.getElementById("bingSet").checked = false;
// 提示切换成功
new Vue({
data: function () {
this.$notify({
title: "可以啦🍨",
message: "切换自定义背景成功!",
position: 'top-left',
offset: 50,
showClose: true,
type: "success",
duration: 5000
});
}
})
}).catch(() => {
// 无效的图片链接,提示无效
new Vue({
data: function () {
this.$notify({
title: "链接不对🤣",
message: "请输入有效的图片链接!",
position: 'top-left',
offset: 50,
showClose: true,
type: "warning",
duration: 5000
});
}
})
})
}
// 判断图片链接是否可用
function checkImgExists(imgurl) {
return new Promise(function (resolve, reject) {
var ImgObj = new Image();
ImgObj.src = imgurl;
ImgObj.onload = function (res) {
resolve(res);
}
ImgObj.onerror = function (err) {
reject(err);
}
})
}
// 必应每日图片
if (localStorage.getItem("bing") == undefined) {
localStorage.setItem("bing", "false");
}
if (localStorage.getItem("bing") == "true") {
let bg = document.getElementById("web_bg");
// 手机电脑分开
let curUrl = screen.width <= 768 ? "url(https://bing.img.run/m.php)" : "url(https://bing.img.run/1920x1080.php)";
bg.style.backgroundImage = curUrl;
}
function setBing() {
// 打开就设置
if (document.getElementById("bingSet").checked) {
let bg = document.getElementById("web_bg");
// 手机电脑分开
let curUrl = screen.width <= 768 ? "url(https://bing.img.run/m.php)" : "url(https://bing.img.run/1920x1080.php)";
bg.style.backgroundImage = curUrl;
localStorage.setItem("bing", "true");
localStorage.removeItem("blogbg");
} else {
// 关闭就移除并恢复默认壁纸
localStorage.setItem("bing", "false");
setTimeout(reload, 600);
}
}
// 霓虹灯开关
var clk; // 定时器对象
if (localStorage.getItem("light") == undefined) {
localStorage.setItem("light", true);
}
if (localStorage.getItem("light") == "true") {
clearInterval(clk);
clk = setInterval(changeLightColor, 1200);
}
function setLight() {
if (document.getElementById("lightSet").checked) {
clearInterval(clk);
clk = setInterval(changeLightColor, 1200);
localStorage.setItem("light", "true");
} else {
clearInterval(clk);
localStorage.setItem("light", "false");
// 恢复默认
if (document.getElementById("site-name"))
document.getElementById("site-name").style.textShadow = "#1e1e1ee0 1px 1px 1px";
if (document.getElementById("site-title"))
document.getElementById("site-title").style.textShadow = "#1e1e1ee0 1px 1px 1px";
if (document.getElementById("site-subtitle"))
document.getElementById("site-subtitle").style.textShadow = "#1e1e1ee0 1px 1px 1px";
if (document.getElementById("post-info"))
document.getElementById("post-info").style.textShadow = "#1e1e1ee0 1px 1px 1px";
try {
document.getElementsByClassName("author-info__name")[0].style.textShadow = "";
document.getElementsByClassName("author-info__description")[0].style.textShadow = "";
} catch {
}
}
}
// 创建窗口
var winbox = "";
function createWinbox() {
let div = document.createElement("div");
document.body.appendChild(div);
winbox = WinBox({
id: "meihuaBox",
index: 99,
title: "美化设置",
x: "left",
y: "center",
minwidth: "300px",
height: "60%",
background: 'var(--theme-color)',
onmaximize: () => {
div.innerHTML = `<style>body::-webkit-scrollbar {display: none;} div#meihuaBox {width: 100% !important;}</style>`;
},
onrestore: () => {
div.innerHTML = "";
},
});
winResize();
window.addEventListener("resize", winResize);
// 每一类我放了一个演示,直接往下复制粘贴 a标签 就可以,需要注意的是 函数里面的链接 冒号前面需要添加反斜杠\进行转义
winbox.body.innerHTML = `
<div class="settings" style="display: block;">
<div id="article-container" style="padding:12px;">
<br>
<center><p><button onclick="reset()" style="background:linear-gradient(to right, #fc354c, #0abfbc);display:block;width:40%;padding:15px 0;border-radius:30px;color:white;font-size:1.1em;"><i class="fa-solid fa-arrows-rotate"></i> 恢复默认设置</button></p></center>
<h2>一、显示偏好</h2>
<div class="transValue" style="font-weight:bold;padding-left:10px">透明度 (0%-100%): ${curTransNum}%</div>
<div class="range">
<input id="transSet" type="range" min="0" max="100" step="1" value=${curTransNum} oninput="setTrans()">
<p class="rang_width" id="rang_trans" style="width:${curTransMini}%"></p>
</div>
<div class="blurValue" style="font-weight:bold;padding-left:10px">模糊半径 (开启模糊生效 0px-100px): ${curBlur} px</div>
<div class="range">
<input id="blurSet" type="range" min="0" max="100" step="1" value="${curBlur}" oninput="setBlurNum()">
<p class="rang_width" id="rang_blur" style="width:${miniBlur}%"></p>
</div>
<div class="content" style="display:flex">
<div class="content-text" style="font-weight:bold; padding-left:10px"> 星空特效 (夜间模式) </div><input type="checkbox" id="universeSet" onclick="setUniverse()">
<div class="content-text" style="font-weight:bold; padding-left:20px"> 霓虹灯 (夜间模式) </div><input type="checkbox" id="lightSet" onclick="setLight()">
</div>
<div class="content" style="display:flex">
<div class="content-text" style="font-weight:bold; padding-left:10px"> 模糊效果 (消耗性能) </div><input type="checkbox" id="blur" onclick="setBlur()">
<div class="content-text" style="font-weight:bold; padding-left:20px"> 侧边栏 (默认开) </div><input type="checkbox" id="rightSideSet" onclick="toggleRightside()">
</div>
<div class="content" style="display:flex">
<div class="content-text" style="font-weight:bold; padding-left:10px"> 帧率监测 (刷新生效) </div><input type="checkbox" id="fpson" onclick="fpssw()">
<div class="content-text" style="font-weight:bold; padding-left:20px"> 必应每日壁纸 </div><input type="checkbox" id="bingSet" onclick="setBing()">
</div>
<h2>二、字体设置</h2>
{% note warning modern %}非商免字体未经授权只能个人使用。本站为完全非商业、非盈利性质的网站,平时用于个人学习交流,如有侵权请联系站长删除,谢谢! —— 致版权方{% endnote %}
<p id="swfs">
<a class="swf" id="swf_ZhuZiAWan" href="javascript:;" rel="noopener external nofollow" style="font-family:'ZhuZiAWan'!important;color:black" onclick="setFont('ZhuZiAWan')">筑紫A丸标准体2.0</a>
<a class="swf" id="swf_default" href="javascript:;" rel="noopener external nofollow" style="font-family:-apple-system, IBM Plex Mono ,monosapce,'微软雅黑', sans-serif;!important;color:black" onclick="setFont('default')">系统默认</a>
</p>
<h2>三、主题色设置</h2>
<div class="content" style="display:flex"><input type="radio" id="red" name="colors" value=" "
onclick="setColor('red')"><input type="radio" id="orange" name="colors" value=" "
onclick="setColor('orange')"><input type="radio" id="yellow" name="colors" value=" "
onclick="setColor('yellow')"><input type="radio" id="green" name="colors" value=" "
onclick="setColor('green')"><input type="radio" id="blue" name="colors" value=" "
onclick="setColor('blue')"><input type="radio" id="heoblue" name="colors" value=" "
onclick="setColor('heoblue')"><input type="radio" id="darkblue" name="colors" value=" "
onclick="setColor('darkblue')"><input type="radio" id="purple" name="colors" value=" "
onclick="setColor('purple')"><input type="radio" id="pink" name="colors" value=" "
onclick="setColor('pink')" checked="checked"><input type="radio" id="black" name="colors" value=" "
onclick="setColor('black')"><input type="radio" id="blackgray" name="colors" value=" "
onclick="setColor('blackgray')"></div>
<h2>四、背景设置</h2>
<center><button onclick="resetBg()" style="background:var(--theme-color);display:block;width:35%;padding:15px 0;border-radius:30px;color:white;"><i class="fa-solid fa-arrows-rotate"></i> 恢复默认背景</button></center>
<h3>1. 二次元</h3>
{% folding cyan, 查看二次元背景 %}
<div class="bgbox">
<a href="javascript:;" rel="noopener external nofollow" style="background-image:url(https://sourcebucket.s3.ladydaily.com/img/home_bg.webp)" class="imgbox" onclick="changeBg('url(https\://sourcebucket.s3.ladydaily.com/img/home_bg.webp)')"></a>
</div>
{% endfolding %}
<h3>2. 风景</h3>
{% folding cyan, 查看风景背景 %}
<div class="bgbox">
<a href="javascript:;" rel="noopener external nofollow" style="background-image:url(https://sourcebucket.s3.ladydaily.com/img/fj1.webp)" class="imgbox" onclick="changeBg('url(https://sourcebucket.s3.ladydaily.com/img/fj1.webp)')"></a>
</div>
{% endfolding %}
<h3>3. 萌宠</h3>
{% folding cyan, 查看萌宠背景 %}
<div class="bgbox">
<a href="javascript:;" rel="noopener external nofollow" style="background-image:url(https://sourcebucket.s3.ladydaily.com/img/mc1.webp)" class="imgbox" onclick="changeBg('url(https://sourcebucket.s3.ladydaily.com/img/mc1.webp)')"></a>
</div>
{% endfolding %}
<h3>4. 渐变色</h3>
{% folding cyan, 查看渐变色背景 %}
<div class="bgbox">
<a href="javascript:;" rel="noopener external nofollow" class="box" style="background: linear-gradient(to top, #355c7d, #6c5b7b, #c06c84)" onclick="changeBg('linear-gradient(to top, #355c7d, #6c5b7b, #c06c84)')"></a>
</div>
{% endfolding %}
<h3>5. 纯色</h3>
{% folding cyan, 查看纯色背景 %}
<div class="bgbox">
<a href="javascript:;" rel="noopener external nofollow" class="box" style="background: #f7eff5" onclick="changeBg('#f7eff5')"></a>
<input type="color" id="colors" href="javascript:;" rel="noopener external nofollow" class="box" autocomplete="on" value="${defineColor}" oninput="changeBgColor()"></input>
</div>
{% endfolding %}
<h3>6. 适配手机</h3>
{% folding cyan, 查看适配手机的背景 %}
<div class="bgbox">
<a href="javascript:;" rel="noopener external nofollow" style="background-image:url(https://sourcebucket.s3.ladydaily.com/img/mb4.webp)" class="pimgbox" onclick="changeBg('url(https\://sourcebucket.s3.ladydaily.com/img/mb4.webp)')"></a>
{% endfolding %}
<h3>7. 自定义背景</h3>
{% folding cyan, 设置自定义背景 %}
<p><center>
<input type="text" id="pic-link" size="70%" maxlength="1000" placeholder="请输入有效的图片链接,如 https://source.fomal.cc/img/home_bg.webp">
</center></p>
<p><center>
<button type="button" onclick="getPicture()" style="background:var(--theme-color);width:35%;padding: 5px 0px 7px 0px;border-radius:30px;color:white;line-height:2;">🌈切换背景🌈</button>
</center></p>
{% endfolding %}
<br>
<center><div style="font-size:1.2em;color:var(--theme-color);font-weight:bold;">------ ( •̀ ω •́ )y 到底啦 ------</div></center>
<br>
</div>
</div>
`;
// 打开小窗时候初始化
$("#" + localStorage.getItem("themeColor")).attr("checked", true);
if (localStorage.getItem("blur") == 1) {
document.getElementById("blur").checked = true;
} else {
document.getElementById("blur").checked = false;
}
if (localStorage.getItem("universe") == "block") {
document.getElementById("universeSet").checked = true;
} else if (localStorage.getItem("universe") == "none") {
document.getElementById("universeSet").checked = false;
}
if (localStorage.getItem("fpson") == "1") {
document.getElementById("fpson").checked = true;
} else {
document.getElementById("fpson").checked = false;
}
if (localStorage.getItem("rs") == "block") {
document.getElementById("rightSideSet").checked = true;
} else if (localStorage.getItem("rs") == "none") {
document.getElementById("rightSideSet").checked = false;
}
if (localStorage.getItem("bing") == "true") {
document.getElementById("bingSet").checked = true;
} else {
document.getElementById("bingSet").checked = false;
}
if (localStorage.getItem("light") == "true") {
document.getElementById("lightSet").checked = true;
} else {
document.getElementById("lightSet").checked = false;
}
setFontBorder();
}
// 恢复默认背景
function resetBg() {
localStorage.removeItem('blogbg');
reload();
}
// 恢复默认设置并刷新页面
function reset() {
clearItem();
reload();
}
// 适应窗口大小
function winResize() {
try {
var offsetWid = document.documentElement.clientWidth;
if (offsetWid <= 768) {
winbox.resize(offsetWid * 0.95 + "px", "90%").move("center", "center");
} else {
winbox.resize(offsetWid * 0.6 + "px", "70%").move("center", "center");
}
} catch (err) {
// console.log("Pjax毒瘤抽风运行winResize方法🙄🙄🙄");
}
}
// 切换状态,窗口已创建则控制窗口显示和隐藏,没窗口则创建窗口
function toggleWinbox() {
if (document.querySelector("#meihuaBox")) {
winbox.toggleClass("hide");
} else {
createWinbox();
};
}在主题配置文件
_config.butterfly.yml
做如下修改,注意:主体js文件最后才引入,因为要依赖其他js,当然也可以整合在一起:
1 | # 背景由js指定 |
- 在自定义的
custom.css
中加入如下代码,注意部分需要自己修改(字体引入与前面的js文件的逻辑对应,可以1设置多个字体,那你的js的winbox.body.innerHTML
就要写上多个选项),这里的css基本做好了分区,细节的自行研究一下:
1 | /* root伪类指定全局颜色(照抄) */ |
- 要注意的是:现在给了美化模块最高的操作优先级,因此其他的默认设置可以去掉
星空背景的逻辑由js指定,因此 #universe
的 display
属性需要空着:
1 | #universe { |
霓虹灯的计时器也要删除,修改 cursor.js
,删掉启动计时器的部分逻辑:
1 | // 开启计时器 |
同时为了适配主题色,拖尾鼠标的 cursor.js
修改为以下的代码:
1 | var CURSOR; |
- 到了这里你应该就有50%的概率成功了,重启项目试试:
1
hexo cl; hexo s
不行怎么办?评论区留言吧!
3.后记
2022年的最后两天,基本上都在写博客文章,把之前魔改的坑基本上填上了。这篇文章可能也是最后一篇关于博客魔改方面的文章啦,毕竟站长不是搞这方面的,后面去搞Linux驱动开发的东西了,有什么疑问可以到评论区留言哈,祝大家新年快乐!——2022.12.31
综合美化模块教程
https://www.fomal.cc/posts/9ac969bb.html