本教程适用于Volantis主题

『言』

该教程理论上支持所有Hexo主题

照搬该教程可实现音乐通知、音乐自动播放通知、复制内容通知

其他通知可根据原理自行添加哦~

添加Message.js

为了控制弹窗的弹出与收回,需要添加一个js控制其行为 Message.js

有两种方法添加该js

  1. themes/volantis/source/js目录中新建一个文件名为Message.js的文件,在其中写入下方代码。
  2. themes/volantis/source/js/app.js文件末尾直接添加该js代码。
为了保持目录干净,我推荐第二种方法哦~
点击查看Message.js代码
1
2
// Message.js
$.extend({message:function(e){var n={title:"",message:" 操作成功",time:"3000",type:"success",showClose:!0,autoClose:!0,onClose:function(){}};"string"==typeof e&&(n.message=e),"object"==typeof e&&(n=$.extend({},n,e));var i,o,s,t=n.showClose?'<div class="c-message--close">×</div>':"",a=""!==n.title?'<h2 class="c-message__title">'+n.title+"</h2>":"",c='<div class="c-message animated animated-lento slideInRight"><i class=" c-message--icon c-message--'+n.type+'"></i><div class="el-notification__group">'+a+'<div class="el-notification__content">'+n.message+"</div>"+t+"</div></div>",m=$("body"),d=$(c);o=function(){d.addClass("slideOutRight"),d.one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){s()})},s=function(){d.remove(),n.onClose(n),clearTimeout(i)},$(".c-message").remove(),m.append(d),d.one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){d.removeClass("messageFadeInDown")}),m.one("click",".c-message--close",function(e){o()}),n.autoClose&&(i=setTimeout(function(){o()},n.time))}});

添加弹窗css样式

  1. themes/volantis/source/css目录中新建一个文件夹,文件夹名为:_xxxxxx。例如:_colsrch
  2. themes/volantis/source/_colsrch目录中新建一个文件,文件名为:message.styl
  3. themes/volantis/source/style.styl文件末尾中用import包含刚新建的文件夹,示例:@import ‘_colsrch/*’
  4. 将下方代码复制至message.styl文件中
点击查看message.styl代码
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
$pointer = url("https://cdn.jsdelivr.net/gh/inkss/common@master/cursor/pointer.png")

.animated
-webkit-animation-duration 1s
animation-duration 1s
-webkit-animation-fill-mode none
animation-fill-mode none
&.infinite
-webkit-animation-iteration-count infinite
animation-iteration-count infinite
&.hinge
-webkit-animation-duration 2s
animation-duration 2s

.animated.bounceIn,
.animated.bounceOut
-webkit-animation-duration .75s
animation-duration .75s

.animated.flipOutX,
.animated.flipOutY
-webkit-animation-duration .75s
animation-duration .75s

.slideInDown
-webkit-animation-name slideInDown
animation-name slideInDown

.slideInLeft
-webkit-animation-name slideInLeft
animation-name slideInLeft

.slideInRight
-webkit-animation-name slideInRight
animation-name slideInRight

.slideInUp
-webkit-animation-name slideInUp
animation-name slideInUp

.slideOutDown
-webkit-animation-name slideOutDown
animation-name slideOutDown

.slideOutLeft
-webkit-animation-name slideOutLeft
animation-name slideOutLeft

.slideOutRight
-webkit-animation-name slideOutRight
animation-name slideOutRight

.slideOutUp
-webkit-animation-name slideOutUp
animation-name slideOutUp

.c-message
top 16px
z-index 2000
width 300px
padding 14px 26px 14px 13px
box-sizing border-box
position fixed
right 16px
background-color #fff
transition opacity .3s, transform .3s, right .3s, top .4s
overflow hidden
box-shadow 0 2px 12px 0 rgba(0, 0, 0, .1)
border-radius 8px
border 1px solid #ebeef5
a
border-bottom 1px solid rgba(131, 145, 165, .8)
color inherit
text-decoration none
cursor $pointer,pointer !important
word-break break-all
&:hover
border-bottom 1px solid #5c6775
&.messageFadeInDown
-webkit-animation-duration .6s
animation-duration .6s
-webkit-animation-fill-mode both
animation-fill-mode both
-webkit-animation-name messageFadeInDown
animation-name messageFadeInDown
&.messageFadeOutUp
-webkit-animation-duration .6s
animation-duration .6s
-webkit-animation-fill-mode both
animation-fill-mode both
-webkit-animation-name messageFadeOutUp
animation-name messageFadeOutUp

.c-message__title
font-weight 400
font-size 15px
color #1f2d3d
margin 0

.c-message--icon
position absolute
color #fff
height 25px
width 25px
font-size 25px

.el-notification__content
font-size 13px
line-height 21px
margin 10px 0 0
color #8391a5
text-align justify

.el-notification__group
margin-left 35px

.c-message--close
position absolute
right 10px
color #999
text-decoration none
cursor $pointer,pointer
font-size 25px
top 0
line-height 34px
display block
height 20px
font-weight 100
&:hover
color #666

.c-message--success
background: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNTE2NDE5MDE4MjQ0IiBjbGFzcz0iaWNvbiIgc3R5bGU9IiIgdmlld0JveD0iMCAwIDEwMjUgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjE3OTAiIHhtbG5zOnh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MTIgMCAyMjkuMjMyIDIyOS4yMzIgMCA1MTIgMGMyODIuNzY4IDAgNTEyIDIyOS4yMzIgNTEyIDUxMkMxMDI0IDc5NC43NjggNzk0Ljc2OCAxMDI0IDUxMiAxMDI0ek01NjAgMjQwYzAtMjYuNTEyLTIxLjQ4OC00OC00OC00OHMtNDggMjEuNDg4LTQ4IDQ4bDAgMzUyYzAgMjYuNTEyIDIxLjQ4OCA0OCA0OCA0OHM0OC0yMS40ODggNDgtNDhMNTYwIDI0MHpNNTEyIDczNmMtMjYuNTEyIDAtNDggMjEuNDg4LTQ4IDQ4czIxLjQ4OCA0OCA0OCA0OCA0OC0yMS40ODggNDgtNDhTNTM4LjUxMiA3MzYgNTEyIDczNnoiIHAtaWQ9IjcxOTgiIGZpbGw9IiNlNmEyM2MiPjwvcGF0aD48L3N2Zz4=") no-repeat 0 50%


@-webkit-keyframes slideInDown
0%
-webkit-transform: translate3d(0, -100%, 0)
transform: translate3d(0, -100%, 0)
visibility: visible
100%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)

@keyframes slideInDown
0%
-webkit-transform: translate3d(0, -100%, 0)
transform: translate3d(0, -100%, 0);
visibility: visible
100%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)

@-webkit-keyframes slideInLeft
0%
-webkit-transform: translate3d(-100%, 0, 0)
transform: translate3d(-100%, 0, 0);
visibility: visible
100%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)

@keyframes slideInLeft
0%
-webkit-transform: translate3d(-100%, 0, 0)
transform: translate3d(-100%, 0, 0);
visibility: visible
100%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)

@-webkit-keyframes slideInRight
0%
-webkit-transform: translate3d(100%, 0, 0)
transform: translate3d(100%, 0, 0);
visibility: visible
100%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)

@keyframes slideInRight
0%
-webkit-transform: translate3d(100%, 0, 0)
transform: translate3d(100%, 0, 0);
visibility: visible
100%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)

@-webkit-keyframes slideInUp
0%
-webkit-transform: translate3d(0, 100%, 0)
transform: translate3d(0, 100%, 0);
visibility: visible
100%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)

@keyframes slideInUp
0%
-webkit-transform: translate3d(0, 100%, 0)
transform: translate3d(0, 100%, 0);
visibility: visible
100%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)

@-webkit-keyframes slideOutDown
0%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)
100%
visibility: hidden;
-webkit-transform: translate3d(0, 100%, 0)
transform: translate3d(0, 100%, 0)

@keyframes slideOutDown
0%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)
100%
visibility: hidden;
-webkit-transform: translate3d(0, 100%, 0)
transform: translate3d(0, 100%, 0)

@-webkit-keyframes slideOutLeft
0%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)
100%
visibility: hidden;
-webkit-transform: translate3d(-100%, 0, 0)
transform: translate3d(-100%, 0, 0)

@keyframes slideOutLeft
0%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)
100%
visibility: hidden;
-webkit-transform: translate3d(-100%, 0, 0)
transform: translate3d(-100%, 0, 0)

@-webkit-keyframes slideOutRight
0%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)
100%
visibility: hidden;
-webkit-transform: translate3d(100%, 0, 0)
transform: translate3d(100%, 0, 0)

@keyframes slideOutRight
0%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)
100%
visibility: hidden;
-webkit-transform: translate3d(100%, 0, 0)
transform: translate3d(120%, 0, 0)

@-webkit-keyframes slideOutUp
0%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)
100%
visibility: hidden;
-webkit-transform: translate3d(0, -100%, 0)
transform: translate3d(0, -100%, 0)


@keyframes slideOutUp
0%
-webkit-transform: translate3d(0, 0, 0)
transform: translate3d(0, 0, 0)
100%
visibility: hidden;
-webkit-transform: translate3d(0, -100%, 0)
transform: translate3d(0, -100%, 0)

@keyframes messageFadeInDown
0%
-webkit-transform: translate3d(0, -100%, 0)
transform: translate3d(0, -100%, 0)
100%
-webkit-transform: none;
transform: none

@keyframes messageFadeOutUp
0%
opacity: 1
100%
opacity: 0;
-webkit-transform: translateY(-100%)
transform: translateY(-100%)

添加音乐通知

修改aplayer

删除themes/volantis/layout/third-party/aplayer/layout.ejs文件中的autoplay='<%- aplayer.autoplay %>'

themes/volantis/layout/third-party/aplayer/script.ejs文件中的第4行下方添加APlayerController.autoPlay = '<%= theme.plugins.aplayer.autoplay %>';

修改aplayer.js

打开themes/volantis/source/js/aplayer.js文件,将下方代码替换掉原aplayer.js代码

点击查看aplayer.js代码
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
//Cookie.js
function setCookie(e,n,i,o,t,r){if("undefined"!=typeof is_remember)return!1;var u=new Date;u.setTime(u.getTime());var c=new Date(u.getTime()+i);document.cookie=e+"="+escape(n)+(i?"; expires="+c.toGMTString():"")+(o?"; path="+o:"")+(t?"; domain="+t:"")+(r?"; secure":"")}function getCookie(e){var n=document.cookie,i=e+"=",o=n.indexOf("; "+i);if(-1==o){if(0!=(o=n.indexOf(i)))return null}else o+=2;var t=document.cookie.indexOf(";",o);return-1==t&&(t=n.length),unescape(n.substring(o+i.length,t))}function deleteCookie(e,n,i){getCookie(e)&&(document.cookie=e+"="+(n?"; path="+n:"")+(i?"; domain="+i:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT")}


// 检查 Aplayer 对象状态
function checkAPlayer() {
if (APlayerController.player == undefined) {
setAPlayerObject();
} else {
if (APlayerController.observer == undefined) {
setAPlayerObserver();
}
}
}

// 设置全局播放器所对应的 aplyer 对象
function setAPlayerObject() {
if (APlayerController.id == undefined) return;
document.querySelectorAll('meting-js').forEach((item, index) => {
if (item.meta.id == APlayerController.id) {
if (document.querySelectorAll('meting-js')[index].aplayer != undefined) {
APlayerController.player = document.querySelectorAll('meting-js')[index].aplayer;
setAPlayerObserver();
}
}
})
}

// 事件监听
function setAPlayerObserver() {
try {
APlayerController.player.on('play', function (e) {
updateAPlayerControllerStatus();
var index = document.querySelector('meting-js').aplayer.list.index;
var title = document.querySelector('meting-js').aplayer.list.audios[index].title;
var artist = document.querySelector('meting-js').aplayer.list.audios[index].artist;
$.message({title: '音乐通知',message: '正在播放:' + title + ' - ' + artist,type: 'success'});
});
APlayerController.player.on('pause', function (e) {
updateAPlayerControllerStatus();
var index = document.querySelector('meting-js').aplayer.list.index;
var title = document.querySelector('meting-js').aplayer.list.audios[index].title;
var artist = document.querySelector('meting-js').aplayer.list.audios[index].artist;
$.message({title: '音乐通知',message: '暂停播放:' + title + ' - ' + artist,type: 'success'});
});
APlayerController.player.on('volumechange', function (e) {
onUpdateAPlayerVolume();
});
APlayerController.player.on('loadstart', function (e) {
// 跳到下一曲时更新标题
updateTitle();
});
APlayerController.player.on('error', function (e) { // 音乐加载失败
var index = document.querySelector('meting-js').aplayer.list.index;
var title = document.querySelector('meting-js').aplayer.list.audios[index].title;
$.message({title: "音乐通知",message: "歌曲:" + title + "加载失败~",type: 'warning'});
});

// 监听音量手势
APlayerController.volumeBarWrap = document.getElementsByClassName('nav volume')[0].children[0];
APlayerController.volumeBar = APlayerController.volumeBarWrap.children[0]

function updateAPlayerVolume(e) {
let percentage = ((e.clientX || e.changedTouches[0].clientX) - APlayerController.volumeBar.getBoundingClientRect().left) / APlayerController.volumeBar.clientWidth;
percentage = Math.max(percentage, 0);
percentage = Math.min(percentage, 1);
APlayerController.player.volume(percentage);
}
const thumbMove = (e) => {
updateAPlayerVolume(e);
};
const thumbUp = (e) => {
APlayerController.volumeBarWrap.classList.remove('aplayer-volume-bar-wrap-active');
document.removeEventListener('mouseup', thumbUp);
document.removeEventListener('mousemove', thumbMove);
updateAPlayerVolume(e);
};

APlayerController.volumeBarWrap.addEventListener('mousedown', () => {
APlayerController.volumeBarWrap.classList.add('aplayer-volume-bar-wrap-active');
document.addEventListener('mousemove', thumbMove);
document.addEventListener('mouseup', thumbUp);
});


// 设置完监听就立即更新一次
updateAPlayerControllerStatus();
onUpdateAPlayerVolume();
APlayerController.observer = true;
console.log('APlayerController ready!');
} catch (error) {
delete APlayerController.observer;
}
}

// 更新控制器状态
function updateAPlayerControllerStatus() {
try {
if (APlayerController.player.audio.paused) {
document.getElementsByClassName('nav toggle')[0].children[0].classList.add("fa-play");
document.getElementsByClassName('nav toggle')[0].children[0].classList.remove("fa-pause");
} else {
document.getElementsByClassName('nav toggle')[0].children[0].classList.remove("fa-play");
document.getElementsByClassName('nav toggle')[0].children[0].classList.add("fa-pause");
}
} catch (error) {
console.log(error);
}
}

function onUpdateAPlayerVolume() {
try {
APlayerController.volumeBar.children[0].style.width = APlayerController.player.audio.volume * 100 + '%'
} catch (error) {
console.log(error);
}
}

// 播放/暂停
function aplayerToggle() {
checkAPlayer();
try {
APlayerController.player.toggle();
} catch (error) {
console.log(error);
}
}

// 上一曲
function aplayerBackward() {
checkAPlayer();
try {
APlayerController.player.skipBack();
APlayerController.player.play();
} catch (error) {
console.log(error);
}
}

// 下一曲
function aplayerForward() {
checkAPlayer();
try {
APlayerController.player.skipForward();
APlayerController.player.play();
} catch (error) {
console.log(error);
}
}

// 调节音量
function aplayerVolume(percent) {
checkAPlayer();
try {
APlayerController.player.volume(percent);
} catch (error) {
console.log(error);
}
}

// 更新音乐标题
function updateTitle() {
checkAPlayer();
try {
let index = APlayerController.player.list.index;
let obj = APlayerController.player.list.audios[index];
let title = obj.title.length > 15 ? "<span class='text-animate'>" + obj.title + "</span>" : obj.title;
document.getElementsByClassName('nav music-title')[0].innerHTML = title;
} catch (error) {
console.log(error);
}
}

// 自动播放音乐
function autoPlayMusic() {
let autoPlayMusic = getCookie('autoPlayMusic') == null ? true : false;
setTimeout(function () {
if ($(window).width() > 500 && autoPlayMusic && APlayerController.autoPlay) {
let isplay = true;
$.message({title: "音乐通知",message: "即将自动播放,点击<a id='stopMusic' class='stopMusic fix-cursor-pointer'>停止播放</a>",type: 'warning'});
setTimeout(function () {
if (APlayerController.player == undefined) {
checkAPlayer();
}
if (isplay) {
aplayerToggle();
}
}, 3500);
$("#stopMusic").click(function () {
isplay = false;
$(".c-message--close").click();
setTimeout(() => {
$.message({title: "音乐通知",time: 999999,message: "是否永久关闭音乐自动播放? <a id='dontPlayMusic' class='stopMusic fix-cursor-pointer'><b>确认</b></a>",type: 'warning'});
$("#dontPlayMusic").click(function () {
var expires = 7 * 24 * 60 * 60 * 1000;
setCookie("autoPlayMusic", 'false', expires, '/');
$(".c-message--close").click();
setTimeout(() => {
$.message({title: '音乐通知',time: 6000,message: '关闭成功,未来一周内将不再提醒~',type: 'success'});
}, 1000);
});
}, 1000);
})
}
}, 1500);
}

(function ($) {
// 网速快
checkAPlayer();
// 网速一般
setTimeout(function () {
checkAPlayer();
}, 3000);
// 网速较慢
setTimeout(function () {
checkAPlayer();
}, 10000);
autoPlayMusic();
})(jQuery);

添加复制通知

打开themes/volantis/layout/third-party/clipboard/script.ejs文件

有亿点懒,直接用下方代码替换掉clipboard/script.ejs文件中原代码即可。

点击查看clipboard/script.ejs代码
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
<script src="<%- theme.plugins.clipboard.js %>"></script>
<script>
var clipboard = new ClipboardJS('.btn-copy', {
target: function (trigger) {
return trigger.nextElementSibling
}
});
function wait(callback, seconds) {
var timelag = null;
timelag = window.setTimeout(callback, seconds)
}
function pjax_initCopyCode() {
if($(".highlight .code pre").length+$(".article pre code").length==0)return;
var copyHtml = '';
copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
copyHtml += '<i class="fas fa-copy"></i><span>COPY</span>';
copyHtml += '</button>';
$(".highlight .code pre").before(copyHtml);
$(".article pre code").before(copyHtml);
clipboard.off('success').on('success', function (e) {
$.message({
title: '复制成功',
message: "代码已复制,请遵守相关授权协议。",
type: 'success'
});
let $btn = $(e.trigger);
$btn.addClass('copied');
let $icon = $($btn.find('i'));
$icon.removeClass('fa-copy');
$icon.addClass('fa-check-circle');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPIED';
wait(function () {
$icon.removeClass('fa-check-circle');
$icon.addClass('fa-copy');
$span[0].innerText = 'COPY'
}, 2000)
});
clipboard.off('error').on('error', function (e) {
e.clearSelection();
let $btn = $(e.trigger);
$btn.addClass('copy-failed');
let $icon = $($btn.find('i'));
$icon.removeClass('fa-copy');
$icon.addClass('fa-times-circle');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPY FAILED';
wait(function () {
$icon.removeClass('fa-times-circle');
$icon.addClass('fa-copy');
$span[0].innerText = 'COPY'
}, 2000)
})
}
$(function () {
pjax_initCopyCode()
});
</script>

『记』

摸清楚原理后,可以自行添加其他行为的弹窗哦~

既然都看到这里啦,不如在下方评论区留下你的脚印再走~

评论