Beautiful Zhihu

美化你的知乎

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Beautiful Zhihu
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  美化你的知乎
// @author       Boseny
// @match        https://www.zhihu.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // console.log('hhhhh')
    // Your code here...
    // 设置主题颜色
    function SetTheme(color) {
        let themecolor = color || '#fff'
        try {
            document.querySelector(".AppHeader").style.backgroundColor = themecolor
            document.querySelector(".Card").style.backgroundColor = themecolor
            clearAll(".TopstoryItem",themecolor)
            clearAll(".ContentItem-actions",themecolor)
            clearAll(".Card", themecolor)
        } catch (error) {
            // console.log(error)
        }
    }
    //修改所有该选择器样式
    function clearAll (querySelector, color) {
        let list = document.querySelectorAll(querySelector)
        for(let item of list) {
            item.style.backgroundColor = color || "#fff"
        }
    }
    //创建一个菜单
    function CreateLayout () {
        let root = document.getElementById("root")
        let fragment = document.createDocumentFragment()
        let Container = CreateWarp()
        let ColorInput = CreateInput()
        let Btn = CreateButton()

        fragment.appendChild(ColorInput)
        fragment.appendChild(Btn)
        
        Container.appendChild(fragment)
      
        root.appendChild(Container)

    }
    function CreateButton() {
        let Button = document.createElement('button')
        Button.innerText = '点我'
        Button.onclick = Setcolor
        return Button
    }
    function Setcolor() {
        let color = document.getElementById('selector-color').value
        SetTheme(color)
    }
    function CreateInput() {
        let Input = document.createElement('input')
        Input.type = 'color'
        Input.id = 'selector-color'
        return Input
    }
    //创建一个Warp
    function CreateWarp() {
        let Container = document.createElement('div')
        Container.style.width = '200px'
        Container.style.height = '200px'
        Container.style.position = 'fixed'
        Container.style.bottom = '20px'
        Container.style.right = '20px'
        Container.style.zIndex = '99999'
        Container.style.backgroundColor = 'white'
       
        Container.id = 'beautiful-zhihu-warp'
        return Container
    }
    //初始化
    function Init() {
        CreateLayout()
       
        // setTimeout(function() {
        //     SetTheme("#eee")
        // },3000)
    }
    Init()
})();