From a379039ed1b7c9bdafebc0736448f152c23b904a Mon Sep 17 00:00:00 2001 From: j m <1406993111@qq.com> Date: Sat, 6 Apr 2024 17:30:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E4=B8=AD=E8=BD=AC=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- settings.yaml | 39 ++++++ src/css/security-link.less | 133 +++++++++++++++++++++ src/js/common.js | 52 ++++++-- templates/assets/css/security-link.min.css | 1 + templates/assets/img/warning.webp | Bin 0 -> 2066 bytes templates/assets/js/common.min.js | 2 +- templates/common/config.html | 3 + templates/security_link.html | 34 ++++++ theme.yaml | 8 +- 9 files changed, 260 insertions(+), 12 deletions(-) create mode 100644 src/css/security-link.less create mode 100644 templates/assets/css/security-link.min.css create mode 100644 templates/assets/img/warning.webp create mode 100644 templates/security_link.html diff --git a/settings.yaml b/settings.yaml index 81df286..5658464 100644 --- a/settings.yaml +++ b/settings.yaml @@ -1397,6 +1397,45 @@ spec: label: 开启 - value: false label: 关闭 + - group: security_link_config + label: '安全链接' + formSchema: + - $formkit: radio + name: enable_security_link + id: enable_security_link + label: 开启 安全链接页面 + value: false + help: '开启安全链接页面前,请先使用’安全链接页面模版‘创建页面。' + options: + - value: true + label: 开启 + - value: false + label: 关闭 + - $formkit: attachment + name: security_link_site_img + if: $get(enable_security_link).value + label: 安全链接页面-站点图标 + placeholder: '请输入/选择安全链接页面站点的图标' + help: '请输入/选择安全链接页面站点的图标,留空使用站点的favicon。' + - $formkit: text + name: security_link_url + label: 安全链接页面-URL + if: $get(enable_security_link).value + validation: required + placeholder: '请输入使用’安全链接页面模版‘创建的页面访问路径' + help: '输入使用’安全链接页面模版‘创建的页面访问路径,不能省略’/‘。' + - $formkit: attachment + name: security_link_tip_img + if: $get(enable_security_link).value + label: 安全链接页面-提示区域图标 + placeholder: '请输入/选择安全链接页面提示区域的图标' + help: '输入/选择安全链接页面提示区域的图标,留空使用默认图标。' + - $formkit: text + name: security_link_tip_desc + if: $get(enable_security_link).value + label: 安全链接页面-提示区域文本描述 + placeholder: '请输入安全链接页面提示区域的文本描述' + help: '输入安全链接页面提示区域的文本描述,留空使用默认文本描述。' - group: custom label: '定制主题' formSchema: diff --git a/src/css/security-link.less b/src/css/security-link.less new file mode 100644 index 0000000..4471617 --- /dev/null +++ b/src/css/security-link.less @@ -0,0 +1,133 @@ +@charset "utf-8"; + +// 移动设备最大宽度 +@mobile-max-width: 768px; +// 平板最小宽度 +@table-min-width: 769px; +// 笔记本电脑最小宽度 +@laptop-min-width: 1024px; +// 桌面设备最小宽度 +@desktop-min-width: 1216px; +// 显示器最小宽度 +@display-min-width: 1700px; +// 宽屏设备最小宽度 +@widescreen-min-width: 2200px; + +html { + background-color: var(--bg-f); + color: var(--main); + font-family: "Dream Font", serif; + + body { + width: 100%; + height: 100%; + overflow: hidden; + display: flex; + justify-content: center; + align-items: center; + position: absolute; + + + @media (max-width: (@mobile-max-width - 1)) { + .content { + max-width: 90% !important; + min-width: auto !important; + } + } + + .content { + max-width: 500px; + min-width: 360px; + margin-bottom: 10%; + + &-title { + padding: 24px; + align-items: center; + display: flex; + justify-content: center; + + img { + height: 3rem; + width: auto; + } + + span { + font-size: 1.5rem; + margin-left: 10px; + font-weight: bold; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + } + + .others { + padding: 24px; + border-radius: 15px; + border: var(--theme) solid 1px; + background-color: var(--background); + + &-tip { + display: flex; + padding: 20px; + background-color: var(--theme); + align-items: center; + border-radius: 10px; + + img { + height: 2rem; + width: 2rem; + } + + span { + margin-left: 10px; + color: #fafafa; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; + text-overflow: ellipsis; + } + } + + &-topic { + margin-top: 20px; + word-break: break-all; + + span { + + } + + .site-title { + color: var(--theme); + } + + a { + color: var(--theme); + } + } + + &-end { + justify-content: flex-end; + margin-top: 20px; + display: flex; + + a { + border-radius: 2rem; + width: 4rem; + padding: 5px; + text-align: center; + color: var(--theme); + border: var(--theme) solid 1px; + text-decoration: none; + } + + } + + } + + } + + + } +} \ No newline at end of file diff --git a/src/js/common.js b/src/js/common.js index 22a5b46..01d0528 100644 --- a/src/js/common.js +++ b/src/js/common.js @@ -288,7 +288,7 @@ const commonContext = { let timer = null document.addEventListener('visibilitychange', function () { if (document.hidden) { - if(!DreamConfig.document_visible_title || document.title !== DreamConfig.document_visible_title) { + if (!DreamConfig.document_visible_title || document.title !== DreamConfig.document_visible_title) { originTitle = document.title } DreamConfig.document_hidden_title && (document.title = DreamConfig.document_hidden_title) @@ -296,7 +296,7 @@ const commonContext = { } else { document.title = DreamConfig.document_visible_title || originTitle DreamConfig.document_visible_title && (timer = setTimeout(function () { - if(document.title === DreamConfig.document_visible_title){ + if (document.title === DreamConfig.document_visible_title) { document.title = originTitle } }, 2000)) @@ -424,19 +424,19 @@ const commonContext = { let nowYear = now.getFullYear() const grt = new Date(DreamConfig.website_time) let getYear = grt.getFullYear() - if(nowYear === getYear) { - webCopyright.innerText = '© '+nowYear+' '+ DreamConfig.site_title + if (nowYear === getYear) { + webCopyright.innerText = '© ' + nowYear + ' ' + DreamConfig.site_title return } - webCopyright.innerText = '© '+getYear + '-'+nowYear+' '+ DreamConfig.site_title + webCopyright.innerText = '© ' + getYear + '-' + nowYear + ' ' + DreamConfig.site_title }, /* 激活侧边栏人生倒计时 */ initTimeCount() { if (!$('.timelife').length) { return } - if(timeLifeHour === new Date().getHours()) { + if (timeLifeHour === new Date().getHours()) { return } let timelife = [ @@ -523,15 +523,47 @@ const commonContext = { }) $('.aside-timelife').html(htmlStr) }, + /* 安全链接 */ + initSecurityLink() { + if (!DreamConfig.enable_security_link || !DreamConfig.security_link_url || DreamConfig.security_link_url.length === 0) { + return + } + $(document).on('click', 'a[target=_blank]', (event) => { + event.preventDefault() // 防止链接默认行为,即打开新页面 + var href = $(event.currentTarget).attr('href') + var hostname = window.location.hostname + + const isInternalLink = (url, siteDomain) => { + // 将URL和站点域名转换为小写,去除前导和尾随空格 + url = url.toLowerCase().trim() + siteDomain = siteDomain.toLowerCase().trim() + // 如果URL是协议相对路径或者绝对路径,则转换为完整的URL + if (url.startsWith('//')) { + url = window.location.protocol + url + } else if (url.startsWith('/')) { + url = window.location.origin + url + } + // 如果URL以'http://'或'https://'开头,则去除尾部斜杠 + if (url.startsWith('http://') || url.startsWith('https://')) { + url = url.replace(/\/$/, '') + } + // 对比URL和站点域名 + return url.includes(siteDomain) + } + + var tempwindow = window.open('_blank') + tempwindow.location = isInternalLink(href, hostname) ? href : (DreamConfig.security_link_url + '?target=' + encodeURIComponent(href)) + }) + }, /* 灰色模式 */ initGrayMode() { - if(DreamConfig.gray_mode === true) { + if (DreamConfig.gray_mode === true) { $('html').addClass('gray-mode') - } else if(DreamConfig.gray_mode === 'custom') { + } else if (DreamConfig.gray_mode === 'custom') { var now = new Date().getTime() var startTime = new Date(DreamConfig.gray_mode_start_time).getTime() var endTime = new Date(DreamConfig.gray_mode_end_time).getTime() - if(now >= startTime && now <= endTime) { + if (now >= startTime && now <= endTime) { $('html').addClass('gray-mode') } } @@ -566,7 +598,7 @@ const commonContext = { }, /* 显示主题版本信息 */ showThemeVersion() { - if(!DreamConfig.enable_console_version_info) { + if (!DreamConfig.enable_console_version_info) { return } window.logger(`%c页面加载耗时:${Math.round(performance.now())}ms | Theme By Dream2 Plus ${DreamConfig.theme_version}`, diff --git a/templates/assets/css/security-link.min.css b/templates/assets/css/security-link.min.css new file mode 100644 index 0000000..d2afe84 --- /dev/null +++ b/templates/assets/css/security-link.min.css @@ -0,0 +1 @@ +@charset "utf-8";html{background-color:var(--bg-f);color:var(--main);font-family:"Dream Font",serif}html body{width:100%;height:100%;overflow:hidden;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;position:absolute}@media (max-width:767px){html body .content{max-width:90%!important;min-width:auto!important}}html body .content{max-width:500px;min-width:360px;margin-bottom:10%}html body .content-title{padding:24px;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center}html body .content-title img{height:3rem;width:auto}html body .content-title span{font-size:1.5rem;margin-left:10px;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}html body .content .others{padding:24px;border-radius:15px;border:var(--theme) solid 1px;background-color:var(--background)}html body .content .others-tip,html body .content-title{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}html body .content .others-tip{padding:20px;background-color:var(--theme);border-radius:10px}html body .content .others-tip img{height:2rem;width:2rem}html body .content .others-tip span{margin-left:10px;color:#fafafa;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis}html body .content .others-topic{margin-top:20px;word-break:break-all}html body .content .others-topic .site-title,html body .content .others-topic a{color:var(--theme)}html body .content .others-end{-webkit-box-pack:end;-ms-flex-pack:end;justify-content:flex-end;margin-top:20px;display:-webkit-box;display:-ms-flexbox;display:flex}html body .content .others-end a{border-radius:2rem;width:4rem;padding:5px;text-align:center;color:var(--theme);border:var(--theme) solid 1px;text-decoration:none} \ No newline at end of file diff --git a/templates/assets/img/warning.webp b/templates/assets/img/warning.webp new file mode 100644 index 0000000000000000000000000000000000000000..b3988b716f13a6d2bda13afe85f1e84e2637b30d GIT binary patch literal 2066 zcma)7c~nz(7Je*B5~wU?Qk}u|JSz4{eZ|FG`O#X>Fpfzm@jW%~eJP z60Uc`x%;}}4ffhy8h7fQ6kWfvE3D(5YR^=eP}-2Q7LdO3c#g4r^7yP8P+^vwmAd0O zPj{l`yi;;l$k**z#TaFYJ~HEKJ~^7Lag`foku~gTR2ByNEGxq|=Q4F%01#7uEvmia zuVa;PQqTI?EL)pzdZ2eihn8^2oOCRsCU61PsHn3DsH^|A=K83?KFKN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%1Wc{zR9 zSC;)=X>~L{WI#FN>GRyIc$-VK_mg-h%c&<83}?^WK&%=X4q#O0 z2F2lejUwkItHHKs2S~T({CG>RIxe$SWoO>L(Fp5VRg?rSzWr!~8?oH$Y=50PYMdz8 zq2*}#V;}uWR|@G&FDhiq5nG!c6Rpye3|*zcxJo%XZC;T`b#;v?U`)03m)?IE;~mVc cQkZ_!sx0TE^1ejRz1CAji_PlS6wv?sPlE_ofB*mh literal 0 HcmV?d00001 diff --git a/templates/assets/js/common.min.js b/templates/assets/js/common.min.js index 6e38c1a..3519d34 100644 --- a/templates/assets/js/common.min.js +++ b/templates/assets/js/common.min.js @@ -11,4 +11,4 @@
${e.percent}
- `}),$(".aside-timelife").html(n)}},initGrayMode(){var e,t,n;(!0===DreamConfig.gray_mode||"custom"===DreamConfig.gray_mode&&(e=(new Date).getTime(),t=new Date(DreamConfig.gray_mode_start_time).getTime(),n=new Date(DreamConfig.gray_mode_end_time).getTime(),t<=e)&&e<=n)&&$("html").addClass("gray-mode")},initEffects(){Utils.isMobile()||(DreamConfig.cursor_move&&Utils.cachedScript(`${DreamConfig.theme_base}/js/cursor/move/${DreamConfig.cursor_move}.min.js?mew=`+DreamConfig.theme_version),DreamConfig.cursor_click&&Utils.cachedScript(`${DreamConfig.theme_base}/js/cursor/click/${DreamConfig.cursor_click}.min.js?mew=`+DreamConfig.theme_version),DreamConfig.enable_live2d&&Utils.cachedScript(DreamConfig.theme_base+"/js/autoload.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_lantern_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/lantern.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_sakura_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/sakura.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_snowflake_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/snowflake.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_universe_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/universe.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_circle_magic_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/circleMagic.min.js?mew="+DreamConfig.theme_version))},initTagCloud(){$(".tagcloud").length&&DreamConfig.show_tagcloud_style&&tagcloud({selector:".tagcloud .card-content",fontsize:18,radius:75,mspeed:"slow",ispeed:"slow",direction:45,keep:!1})},showThemeVersion(){DreamConfig.enable_console_version_info&&window.logger(`%c页面加载耗时:${Math.round(performance.now())}ms | Theme By Dream2 Plus `+DreamConfig.theme_version,"color:#fff; background: linear-gradient(270deg, #986fee, #8695e6, #68b7dd, #18d7d3); padding: 8px 15px; border-radius: 0 15px 0 15px")}};window.commonContext=t;let o=-1;{const n=["initCarousel","sparkInput","websiteTime"],i=["initEffects","showThemeVersion"];Object.keys(t).forEach(e=>!n.includes(e)&&!i.includes(e)&&t[e]()),document.addEventListener("DOMContentLoaded",function(){$("html").addClass("loaded"),n.forEach(e=>t[e]&&t[e]())}),window.addEventListener("load",function(){i.forEach(e=>t[e]&&t[e]()),$("html").addClass("ready")})}})(); \ No newline at end of file + `}),$(".aside-timelife").html(n)}},initSecurityLink(){DreamConfig.enable_security_link&&DreamConfig.security_link_url&&0!==DreamConfig.security_link_url.length&&$(document).on("click","a[target=_blank]",e=>{e.preventDefault();var t,e=$(e.currentTarget).attr("href"),n=window.location.hostname;window.open("_blank").location=(n=n,t=(t=e).toLowerCase().trim(),n=n.toLowerCase().trim(),t.startsWith("//")?t=window.location.protocol+t:t.startsWith("/")&&(t=window.location.origin+t),(t=t.startsWith("http://")||t.startsWith("https://")?t.replace(/\/$/,""):t).includes(n)?e:DreamConfig.security_link_url+"?target="+encodeURIComponent(e))})},initGrayMode(){var e,t,n;(!0===DreamConfig.gray_mode||"custom"===DreamConfig.gray_mode&&(e=(new Date).getTime(),t=new Date(DreamConfig.gray_mode_start_time).getTime(),n=new Date(DreamConfig.gray_mode_end_time).getTime(),t<=e)&&e<=n)&&$("html").addClass("gray-mode")},initEffects(){Utils.isMobile()||(DreamConfig.cursor_move&&Utils.cachedScript(`${DreamConfig.theme_base}/js/cursor/move/${DreamConfig.cursor_move}.min.js?mew=`+DreamConfig.theme_version),DreamConfig.cursor_click&&Utils.cachedScript(`${DreamConfig.theme_base}/js/cursor/click/${DreamConfig.cursor_click}.min.js?mew=`+DreamConfig.theme_version),DreamConfig.enable_live2d&&Utils.cachedScript(DreamConfig.theme_base+"/js/autoload.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_lantern_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/lantern.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_sakura_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/sakura.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_snowflake_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/snowflake.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_universe_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/universe.min.js?mew="+DreamConfig.theme_version),DreamConfig.effects_circle_magic_mode&&Utils.cachedScript(DreamConfig.theme_base+"/js/effects/circleMagic.min.js?mew="+DreamConfig.theme_version))},initTagCloud(){$(".tagcloud").length&&DreamConfig.show_tagcloud_style&&tagcloud({selector:".tagcloud .card-content",fontsize:18,radius:75,mspeed:"slow",ispeed:"slow",direction:45,keep:!1})},showThemeVersion(){DreamConfig.enable_console_version_info&&window.logger(`%c页面加载耗时:${Math.round(performance.now())}ms | Theme By Dream2 Plus `+DreamConfig.theme_version,"color:#fff; background: linear-gradient(270deg, #986fee, #8695e6, #68b7dd, #18d7d3); padding: 8px 15px; border-radius: 0 15px 0 15px")}};window.commonContext=t;let o=-1;{const n=["initCarousel","sparkInput","websiteTime"],i=["initEffects","showThemeVersion"];Object.keys(t).forEach(e=>!n.includes(e)&&!i.includes(e)&&t[e]()),document.addEventListener("DOMContentLoaded",function(){$("html").addClass("loaded"),n.forEach(e=>t[e]&&t[e]())}),window.addEventListener("load",function(){i.forEach(e=>t[e]&&t[e]()),$("html").addClass("ready")})}})(); \ No newline at end of file diff --git a/templates/common/config.html b/templates/common/config.html index abe37f5..37515f5 100644 --- a/templates/common/config.html +++ b/templates/common/config.html @@ -104,6 +104,9 @@ DreamConfig["show_tagcloud_style"] = [[${theme.config.sidebar.show_tagcloud_style}]]; /** 控制台主题信息 */ DreamConfig["enable_console_version_info"] = [[${theme.config.enhance.enable_console_version_info}]]; + /** 安全链接配置 */ + DreamConfig["enable_security_link"] = [[${theme.config.security_link_config.enable_security_link}]]; + DreamConfig["security_link_url"] = [[${theme.config.security_link_config.security_link_url}]]; DreamConfig["theme_version"] = [[${theme.spec.version}]]; DreamConfig["theme_base"] = "[(${#theme.assets('/')})]"; diff --git a/templates/security_link.html b/templates/security_link.html new file mode 100644 index 0000000..a94130c --- /dev/null +++ b/templates/security_link.html @@ -0,0 +1,34 @@ + + + + + + + + + + + +
+
+ favicon + [[${site.title}]] +
+
+
+ + [[${#strings.isEmpty(theme.config.security_link_config.security_link_tip_desc) ? '请注意您的账号和财产安全!': theme.config.security_link_config.security_link_tip_desc}]] +
+
+ 您即将离开[[${site.title}]],去往:[[${url}]] +
+
+ 继续 +
+
+
+ + \ No newline at end of file diff --git a/theme.yaml b/theme.yaml index 250d07b..ad958ab 100644 --- a/theme.yaml +++ b/theme.yaml @@ -11,6 +11,12 @@ spec: name: 智识家 # 作者网址 website: https://www.sw0.top + customTemplates: + page: + - name: 安全链接页面模版 + description: 支持安全链接页面配置 + screenshot: + file: security_link.html # 主题描述 description: '梦之城,童话梦境' # 主题logo地址 @@ -22,6 +28,6 @@ spec: settingName: theme-dream-setting configMapName: theme-dream-configMap # 版本号 - version: 1.0.4 + version: 1.0.4.50 # 最低支持的 Halo 版本 require: ">=2.6.0" \ No newline at end of file