// ==UserScript== // @name ZhiHu Style Adjust // @namespace https://www.zhihu.com/ // @version 0.1 // @description 改善知乎在宽大屏幕上的阅读体验 // @author DistantSaviour_caofs // @match https://www.zhihu.com/* // @license MIT // @grant none // @downloadURL https://update.greasyfork.icu/scripts/429679/ZhiHu%20Style%20Adjust.user.js // @updateURL https://update.greasyfork.icu/scripts/429679/ZhiHu%20Style%20Adjust.meta.js // ==/UserScript== (function () { 'use strict'; let fontFamily = localStorage.getItem('font-family') || 'sans'; let fontSize = Number(localStorage.getItem('font-size')) || 20; //右侧div是否隐藏,默认是不隐藏的 let rightDivVisible = false; let customFont = localStorage.getItem('custom-font') || `'方正悠宋 GBK 508R', serif` //字体格式 function fontFamilyPropertyValue() { if (fontFamily === 'custom'){ return customFont; } if (fontFamily === 'serif'){ return `'Source Serif', 'Noto Serif', 'Source Han Serif SC', 'Noto Serif CJK SC', serif`; }else{ return `'Source Sans', 'Noto Sans', 'Source Han Sans SC', 'Noto Sans CJK SC', sans-serif`; } } //字体大小 function fontSizePropertyValue() { return `${fontSize}px`; } // language=css const css = ` :root { --font-family: ${fontFamilyPropertyValue()}; --font-size: ${fontSizePropertyValue()}; font-family: var(--font-family) !important; font-size: var(--font-size) !important; line-height: 2 !important; } body { font-family: unset; line-height: unset; font-size: unset; } .Button { font-size: unset; } .ContentItem-title{ font-size: unset; } div.CommentItemV2{ font-size: unset; } /* Control */ #control-button { position: fixed; top: 80px; right: 0; width: 48px; height: 48px; font-size: 18px; font-family: sans-serif; line-height: 48px; text-align: center; background: #FFFFFF; border: 1px solid #CCCCCC; border-right: 0; border-top-left-radius: 6px; border-bottom-left-radius: 6px; cursor: pointer; user-select: none; } #control-panel { position: fixed; top: 120px; left: 50%; width: 320px; margin-left: -160px; font-size: 16px; font-family: sans-serif; display: none; background: #FFFFFF; border: 1px solid #CCCCCC; user-select: none; } #control-panel .control-title { display: flex; height: 40px; border-bottom: 1px solid #CCCCCC; } #control-panel .control-title-text { line-height: 40px; flex: 1; padding-left: 8px; } #control-panel #control-close { width: 40px; height: 40px; line-height: 40px; text-align: center; font-size: 24px; border-left: 1px solid #CCCCCC; cursor: pointer; } #control-panel .control-font-family-item { height: 32px; line-height: 32px; text-align: center; margin: 8px; border: 1px solid #CCCCCC; cursor: pointer; } #control-panel #control-font-family-custom { margin-bottom: 0; } #control-panel #control-font-family-custom-input { margin-top: 0; border-top: 0; cursor: unset; } #control-panel #control-font-family-custom-input input { font-family: monospace; font-size: 0.8em; width: 100%; height: 100%; box-sizing: border-box; padding: 0 8px; margin: 0; border: 0; } #control-panel .control-font-size { height: 32px; line-height: 32px; margin: 8px; border: 1px solid #CCCCCC; display: flex; } #control-panel .control-font-size-action { height: 32px; width: 32px; text-align: center; cursor: pointer; } #control-panel #control-font-size-decrease { border-right: 1px solid #CCCCCC; } #control-panel #control-font-size-increase { border-left: 1px solid #CCCCCC; } #control-panel #control-font-size-value { flex: 1; text-align: center; } `; function addStyles() { // 知乎主页 if(document.getElementsByClassName("Topstory-container")[0]){ document.getElementsByClassName("Topstory-container")[0].style.setProperty("width","90%"); //Topstory-mainColumn document.getElementsByClassName("Topstory-mainColumn")[0].style.setProperty("width","70%"); }else{//知乎问题主页 //Question-main document.getElementsByClassName("Question-main")[0].style.setProperty("width","90%"); //ListShortcut document.getElementsByClassName("Question-mainColumn")[0].style.width='90%'; window.onload = function(){ document.getElementsByClassName("ContentItem-actions Sticky RichContent-actions is-fixed is-bottom")[0].style.width='66%'; } } const style = document.createElement('style'); style.appendChild(document.createTextNode(css)); document.head.appendChild(style); } function addControlPanel() { const panel = document.createElement('div'); panel.className = 'control-addon'; panel.id = 'control-panel'; // language=html panel.innerHTML = `