Skip to content

Commit

Permalink
feat: split inactive notice function
Browse files Browse the repository at this point in the history
  • Loading branch information
Candinya committed Aug 13, 2024
1 parent b88060d commit 90cc600
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 64 deletions.
12 changes: 0 additions & 12 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@ donate:
# link: "" # 和 qrcode 二选一,使用这项则点击图标时会打开前往指定链接的新窗口。
# qrcode: "" # 和 link 二选一,使用这项则点击图标时会在窗口的二维码展示区展示使用指定内容生成的二维码。

################## 娱乐功能配置 ##################

# 站点离开提示
inactive_notice:
enable: true # 是否启用
delay: 30 # 延迟时间(秒)
favicon: # 图标
leave: "/images/failure.png"
message: # 消息
leave: "{{{(>_<)}}}哦哟,崩溃啦~"
return: "(*´∇`*)欸,又好啦~"

# 版权提示
copyright_notice:
in_page: # 在页面内显示
Expand Down
7 changes: 0 additions & 7 deletions scripts/gen-jsconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ hexo.once("generateBefore", () => {
uptime: {
since: themeConfig.footer.components.uptime.since,
},
inactiveNotice: {
enable: themeConfig.inactive_notice.enable,
delay: themeConfig.inactive_notice.delay,
leaveLogo: themeConfig.inactive_notice.favicon.leave,
leaveTitle: themeConfig.inactive_notice.message.leave,
returnTitle: themeConfig.inactive_notice.message.return,
},
copyrightNoticeForCopy: {
enable: themeConfig.copyright_notice.append_copy.enable,
template: themeConfig.copyright_notice.append_copy.template,
Expand Down
Binary file removed source/images/failure.png
Binary file not shown.
45 changes: 0 additions & 45 deletions src/js/kr-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,49 +154,6 @@ import scrollIntoView from "scroll-into-view-if-needed";
}
};

let docTitle = "";
const saveTitle = () => {
docTitle = document.title;
};

const initInactiveNotice = (kr) => {
if (kr.enable) {
let inactiveTimeout = null; // 不活跃的持续时间计时(而不是一不活跃就直接变)
const siteFavicon = document.querySelector('[rel="icon"]');
const originIcon = siteFavicon.getAttribute("href");
document.addEventListener("visibilitychange", () => {
if (document.hidden) {
// 触发离开事件,开始计时
inactiveTimeout = setTimeout(() => {
document.title = kr.leaveTitle;
if (kr.leaveLogo) {
siteFavicon.setAttribute("href", kr.leaveLogo);
}
inactiveTimeout = null;
}, kr.delay * 1000);
} else {
// 触发回归事件
if (inactiveTimeout !== null) {
// 还在计时,(假装)无事发生
clearTimeout(inactiveTimeout);
inactiveTimeout = null;
} else {
// 回归了,庆祝一下
document.title = kr.returnTitle + " " + docTitle;
if (kr.leaveLogo) {
siteFavicon.setAttribute("href", originIcon);
}

// 稍等一等再把标题改回来
setTimeout(() => {
document.title = docTitle;
}, 2000);
}
}
});
}
};

const getTimeString = (msec, exact = true) => {
let tString;
const sec = msec / 1000;
Expand Down Expand Up @@ -668,7 +625,6 @@ import scrollIntoView from "scroll-into-view-if-needed";

const initPerPage = () => {
initTocWidgetAnim();
saveTitle();
initCodeCopy();
initCollapseBoxControl();
commentsLazyLoad();
Expand All @@ -686,7 +642,6 @@ import scrollIntoView from "scroll-into-view-if-needed";

loadConfig().then((kr) => {
initCopyEventListener(kr.copyrightNoticeForCopy);
initInactiveNotice(kr.inactiveNotice);
initUpTime(kr.uptime);
initTopNavScrollToggle(kr.topNavScrollToggle);
initPerPageWithConfig(kr);
Expand Down

0 comments on commit 90cc600

Please sign in to comment.