惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Jina AI
Jina AI
H
Help Net Security
月光博客
月光博客
Y
Y Combinator Blog
I
InfoQ
博客园 - Franky
W
WeLiveSecurity
The Register - Security
The Register - Security
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Blog — PlanetScale
Blog — PlanetScale
H
Hacker News: Front Page
L
LangChain Blog
S
Security @ Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
罗磊的独立博客
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
博客园_首页
SecWiki News
SecWiki News
N
News and Events Feed by Topic
B
Blog RSS Feed
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AI
AI
Google Online Security Blog
Google Online Security Blog
MongoDB | Blog
MongoDB | Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
WordPress大学
WordPress大学
小众软件
小众软件
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
PCI Perspectives
PCI Perspectives
博客园 - 聂微东
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Martin Fowler
Martin Fowler
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
博客园 - 司徒正美
Forbes - Security
Forbes - Security
酷 壳 – CoolShell
酷 壳 – CoolShell
S
Security Affairs

星空下的YZY

【生活随笔】终于可以试一试new Bing了 【学习记录】微信小程序tabBar与自定义navigationBar踩坑记录 这小小破站(摸鱼)一周年啦 【个人记录参考】Vue3搭建项目 【学习记录】CSS动画 【随笔】将备案接入服务商转为腾讯云 正则表达式 【随笔】模拟退火 【随笔】博弈题基础回顾 live2d-widget(看板娘)修改及部署至服务器 【生活随笔】又是一年226,祝自己生日快乐 【杂记】各类零碎笔记(不定期更新) 友链朋友圈4.X.X前端适配尝试【基于店长Akilar的旧版方案】 使用JDBC操作数据库 Java读写txt文件 Hexo中使用ECharts动态图表尝试 【随笔】通过必应的工具发现别的网站未经允许的转载 【暂不公开】YZY的ACM模板整理-java版 更换Butterfly主题及其美化记录
指定日期网页自动变灰
星空下的YZY · 2022-12-12 · via 星空下的YZY

前言:

又快到国家公祭日了,就把指定日期网站变灰给加上了

可能方法比较笨拙,欢迎大佬指出或提供更好的方案🤣

【转载说明】本文优先发布于我的个人博客www.226yzy.com ,转载请注明出处并注明作者:星空下的YZY。

本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0许可协议。

js

以Hexo的Butterfly主题为例(其他的其实引入js即可)

themes\butterfly\source\js\下新建grayscale.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
if (mourning()) {
document.getElementsByTagName("html")[0].setAttribute("style", "filter:gray !important;filter:grayscale(100%);-webkit-filter:grayscale(100%);-moz-filter:grayscale(100%);-ms-filter:grayscale(100%);-o-filter:grayscale(100%);");
}

function mourning() {
var Days = new Array("0512", "1213");
var currentdate = new Date();
var str = "";
var mm = currentdate.getMonth() + 1;
if (currentdate.getMonth() > 9) {
str += mm;
} else {
str += "0" + mm;
}
if (currentdate.getDate() > 9) {
str += currentdate.getDate();
} else {
str += "0" + currentdate.getDate();
}
if (Days.indexOf(str) > -1) {
return 1;
} else {
return 0;
}
}

其中var Days = new Array("0512", "1213");可以增添合适日期,如"1213"表示每年的12月13日(即国家公祭日)

然后,就是引入js,butterfly主题的话就在——config.yml中的inject的配置项bottom中添加

1
- <script async src="/js/grayscale.js"></script>

但其实这有一个缺点,就是这样是全站变灰,色彩的缺失可能导致一些必要的阅读受到影响

所以最好是仅在首页页面引入

Butterfly主题仅首页变灰

我目前是通过修改主题源码的方式实现的

另外我目前Butterfly主题版本为4.1.0

增改源码在themes\butterfly\layout\includes\header\index.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
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
if !theme.disable_top_img && page.top_img !== false
if is_post()
- var top_img = page.top_img || page.cover || page.randomcover
else if is_page()
- var top_img = page.top_img || theme.default_top_img
else if is_tag()
- var top_img = theme.tag_per_img && theme.tag_per_img[page.tag]
- top_img = top_img ? top_img : (theme.tag_img !== false ? theme.tag_img || theme.default_top_img : false)
else if is_category()
- var top_img = theme.category_per_img && theme.category_per_img[page.category]
- top_img = top_img ? top_img : (theme.category_img !== false ? theme.category_img || theme.default_top_img : false)
else if is_home()
- var top_img = theme.index_img !== false ? theme.index_img || theme.default_top_img : false
else if is_archive()
- var top_img = theme.archive_img !== false ? theme.archive_img || theme.default_top_img : false
else
- var top_img = page.top_img || theme.default_top_img

if top_img !== false
- var imgSource = top_img && top_img.indexOf('/') !== -1 ? `background-image: url('${url_for(top_img)}')` : `background: ${top_img}`
- var bg_img = top_img ? imgSource : ''
- var site_title = is_archive() ? fragment_cache('findArchivesTitle', function(){return findArchivesTitle(theme.menu);}) : page.title || page.tag || page.category || config.title
- var isHomeClass = is_home() ? 'full_page' : 'not-home-page'
- is_post() ? isHomeClass = 'post-bg' : isHomeClass
else
- var isHomeClass = 'not-top-img'
else
- var top_img = false
- var isHomeClass = 'not-top-img'

header#page-header(class=isHomeClass style=bg_img)
!=partial('includes/header/nav', {}, {cache: true})
script(type='text/javascript').
document.getElementsByTagName("html")[0].setAttribute("style", "filter:grayscale(0%);-webkit-filter:grayscale(0%);-moz-filter:grayscale(0%);-ms-filter:grayscale(0%);-o-filter:grayscale(0%);");
if top_img !== false
if is_post()
include ./post-info.pug
else if is_home()
#site-info
h1#site-title=site_title
if theme.subtitle.enable
- var loadSubJs = true
#site-subtitle
span#subtitle
if(theme.social)
#site_social_icons
!=fragment_cache('social', function(){return partial('includes/header/social')})
#scroll-down
i.fas.fa-angle-down.scroll-down-effects
script(src="/js/grayscale.js")
else
#page-site-info
h1#site-title=site_title

增改的内容在第33-34行和第50行

首先是第50行的(去掉第33-34行可能在48行)

1
script(src="/js/grayscale.js")

这个就是在首页引入js

这里为止我测试的效果是,直接访问非首页不变灰,访问首页变灰

通过首页访问其他页面,其他页面还是灰,但可刷新后颜色正常

通过首页访问其他页面颜色正常

在33行的位置增加

1
2
script(type='text/javascript').
document.getElementsByTagName("html")[0].setAttribute("style", "filter:grayscale(0%);-webkit-filter:grayscale(0%);-moz-filter:grayscale(0%);-ms-filter:grayscale(0%);-o-filter:grayscale(0%);");

可能必交笨拙就是在其他页面将grayscale的参数条为0%

最后

暂时就写到这了,如有错误,欢迎大佬留言指出😆

欢迎访问我的小破站https://www.226yzy.com/ 或者GitHub版镜像 https://226yzy.github.io/ 或Gitee版镜像https://yzy226.gitee.io/

我的Github:226YZY (星空下的YZY) (github.com)

【转载说明】本文优先发布于我的个人博客www.226yzy.com ,转载请注明出处并注明作者:星空下的YZY。

本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0许可协议。

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 星空下的YZY

打赏

  • 微信

    微信

  • 支付宝

    支付宝