隐藏标题栏

隐藏网站的标题栏

目前为 2024-12-11 提交的版本。查看 最新版本

// ==UserScript==
// @name        隐藏标题栏
// @namespace   Violentmonkey Scripts
// @match       https://pychina.org/*
// @match       https://*.pychina.org/*
// @match       https://realpython.com/*
// @match       https://*.realpython.com/*
// @match       https://v2ex.com/*
// @match       https://*.v2ex.com/*
// @grant       none
// @version     1.0
// @author      @cichine
// @description 隐藏网站的标题栏
// @license    GPL
// ==/UserScript==

// 设置刷新时间间隔[minute]
(() => {
	const url = window.location.href;
	const protocol = window.location.protocol;
	const host = window.location.host;
	const port = window.location.port;
	const path = window.location.pathname;
	const search = window.location.search;

	const styleMap = {
		"pychina.org": `
        /* 清除顶栏固定 */
        .navbar-fixed-top {
          top: unset;
          z-index: unset;
          position: unset;
        }
        body{
          padding-top: unset;
        }
    `,
		"realpython.com": `
        /* 清除顶栏固定 */
        .fixed-top {
          position: unset;
        }
        /* 隐藏右下角Help */
        #beacon-container {
          display: none;
        }
    `,
		"v2ex.com": `
        /* 隐藏背景 */
        #Wrapper {
          background-color: #fff !important;
          background-image: unset !important;
        }
        /* 隐藏头像 */
        .avatar {
          display: none;
        }`,
	};

	// 查找匹配的域名样式
	let s = "";
	for (const domain in styleMap) {
		if (host.endsWith(domain)) {
			s = styleMap[domain];
			break;
		}
	}
	console.log(`host: ${host}, style: ${s}`);

	const style = document.createElement("style");
	style.innerHTML = s;
	document.head.appendChild(style);
})();