当前位置:网站首页>Do you want to manually implement CSDN dark mode for web page '?
Do you want to manually implement CSDN dark mode for web page '?
2022-06-21 06:01:00 【lazytomato】
start
As a front-end little hand , Address user needs , Achieve functional effects , It's my interest and work .
The situation a :
Tomato myself is a heavy Dark Mode lovers . for example :Vscode,github, Various types app I always set the theme to dark mode .
But some websites , Dark mode is not supported , Or you have to pay to support dark mode .
This makes me feel bad , The white background is always dazzling . But I need to visit these websites often , What do I do ?

Scenario two :
Good friends A: Brother Tomato , Is there any way to open a new browser tab every time , Automatically open the search box ? Every time I browse the information, I open a new browser tab , You need to press ctrl+f, Open the browser to search , Both fingers are tired .
tomato : This …enenenen
Good friends A: Help me with this , It's my treat , Night crayfish .
tomato : Crayfish …

Problem analysis
All right, guys , Crayfish makes my mouth water , Collect your thoughts , Think about how to solve the problems described above .
In fact, the essence of the above scene is : When browsing the web , Do some operations on other people's web pages , For example, make a dark pattern , For example, make a custom search box .
Browser
- We can enter our own code directly into the browser console ?
Every time you open a new tab All pages need to enter code , tomato , lazy , Don't want to move .
- Write a browser plug-in , own diy All kinds of functions ?
Not yet understood , It costs time to understand , I will have time to study later .
- Browser plug-in
TampermonkeyBe commonly called greasemonkey .
Customize js Script Open a web page to execute Our custom script √
Tampermonkey greasemonkey
1. home page
2. Download plug-ins
chrome Users may be blocked by walls , This demonstration uses Edge Demonstrated .
Mode one : Download from the official website
Tampermonkey download -chrome
Mode two : Plug in store
visit Edge Plug in store
Microsoft Edge add-inSearch for
TampermonkeyAnd install

Rubbish talk
In the future, if I really need to make browser plug-ins , I must go and have a look at the source code of this oil monkey , Learning and learning .
Realization function .
Add a custom script
The language written is js, Just a shuttle .
The notes at the top are important , Is the relevant configuration information .
Top note
// ==UserScript==
// @name csdn free diy Dark Mode
// @namespace http://tampermonkey.net/
// @version 0.1
// @description csdn free diy Dark Mode
// @author tomato7
// @include https://blog.csdn.net/*
// @grant none
// ==/UserScript==
Be careful :@include Configure the web site where this script takes effect .
For detailed use of the tutorial, you can view the official website documents by yourself .
1. Dark Mode
Oil monkey can help us open the website and load my script . So here's what we're going to do , Add code to the script to handle the style of the web page ,
White background =》 Black background,Black font =》 White font, You can customize the dark color modeThe dark patterns of different websites need to be customized css Handle .
Let me show you C Dark mode of station ,C Station official is to provide dark mode , But not free , Need to open VIP.
Open those VIP The web page of , View element styles , Look at the , It shows how the dark theme of this website is realized .
Conclusion : It's an independent css The document is direct
!importantOverride the implementation of the original content style .
… It's a little simple
- A shuttle , direct cv Its dark theme css Style of file , Paste into our code .
- Trunk code
// ==UserScript==
// @name C standing Dark Mode
// @namespace http://tampermonkey.net/
// @version 0.1
// @description C standing Dark Mode
// @author tomato7
// @include https://blog.csdn.net/*
// @grant none
// ==/UserScript==
console.log(' Start ')
window.onload = function() {
addCss()
}
function addCss() {
// I will simply add one of the style arrays added here
var css = ['body .article-search-tip {', ' background: #2e2e32 !important', '}'].join('\n')
if (typeof GM_addStyle !== 'undefined') {
GM_addStyle(css)
} else if (typeof PRO_addStyle !== 'undefined') {
PRO_addStyle(css)
} else if (typeof addStyle !== 'undefined') {
addStyle(css)
} else {
var node = document.createElement('style')
node.type = 'text/css'
node.appendChild(document.createTextNode(css))
var heads = document.getElementsByTagName('head')
if (heads.length > 0) {
heads[0].appendChild(node)
} else {
// no head yet, stick it whereever
document.documentElement.appendChild(node)
}
}
}
- test ( Just find a blog of others )

2. Custom search box
How to implement the search box ? JS Add a search box to all open web pages in the code , Then search all html The content in , Then highlight the corresponding text content .
Code
A little
end
Although not a pure technical blog , But I think it is very meaningful .
Open the website to allow js Script execution , It offers infinite possibilities . Based on this plug-in , There are many scripts with more complex functions that others have written . You can do it yourself diy Some scripts . Very interesting , Fabulous !
边栏推荐
- R统计绘图-环境因子相关性+mantel检验组合图(linkET包介绍1)
- Django database and module models (4)
- 二叉排序树的基本操作
- Program optimization with multi-core and multi thread
- 397 linked list (206. reverse linked list & 24. exchange nodes in the linked list in pairs & 19. delete the penultimate node of the linked list & interview question 02.07. link list intersection & 142
- tf.QueueBase
- ssh-copy-id 批量免密脚本
- Connection refused : no futher information : localhost/127.0.0.1:6379
- Globally in top15, fintech recruitment go
- scala中函数和方法
猜你喜欢

Ironocr 2022.1.0 supports 127 national languages

Huashao, founder of Kechuang · kuxuan Technology: make products with win-win thinking, connect ecology, and realize large-scale development

Two ways to get rid of the setback of the new retail brand "three squirrels"

对网页 ‘’为所欲为‘’ 之手动实现 csdn深色模式?

C language course design (detailed explanation of clothing management system)

Fluorite Cloud Application

数据库是8.0的同学,在这个地方,加这一段?useSSL=false&serverTimezone=GMT%2B8&characterEncoding=utf8

Account1 不在 sudoers 文件中。此事将被报告。

硬件探索——数字钟的设计与制作

sqli-labs25
随机推荐
397-链表(206.反转链表 & 24. 两两交换链表中的节点 & 19. 删除链表的倒数第 N 个结点 & 面试题 02.07. 链表相交 & 142.环形链表II)
Memorizing Normality to Detect Anomaly: Memory-augmented Deep Autoencoder for Unsupervised Anomaly D
微生物生态数据分析——冗余分析
Emotron伊尔通软启动器维修MSF370/MSF450
tf.QueueBase
ssh-copy-id 批量免密脚本
You have an error in your SQL syntax; check the manual that corresponds to your MYSQL server
Dosbox installation
Two ways to get rid of the setback of the new retail brand "three squirrels"
You can have a three piece set without winter. I don't allow you to have PPT, word and excel
应用在电视触摸屏中的十四通道智能触摸芯片
Picture steganography: Method 1
UVC sterilization lamp with integrated sterilization, deodorization and odor removal
Django database and module models (4)
数字式温度传感器工作原理以及测温原理分析
Subtitle, key frame animation and sound processing in PR
Basic operation of binary sort tree
基于注意力的seq2seq模型
【JVM】 类加载器(ClassLoader)
Armcm3 authoritative guide notes - the impact of address misalignment in arm programming