1
0

更新 MCdoc.js

This commit is contained in:
xjy
2025-07-15 19:42:56 +08:00
parent a9ad1cc25c
commit b707d2339f

287
MCdoc.js
View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name 中国版我的世界开发者文档 美化
// @namespace https://git.xjyofc.top/xjy/MCdoc_js
// @version 1.0
// @version 2.0
// @description 更好的中国版我的世界开发者文档界面
// @author 仙君御
// @match https://mc.163.com/dev/*
@@ -12,173 +12,158 @@
(function() {
'use strict';
// 隐藏NIE-topBar元素
document.getElementById('NIE-topBar').style.display = 'none';
// 新样式
function newUI(){
const navBar = document.querySelector('.nav-bar');
const header = document.querySelector('header.navbar.fixed-navbar');
const searchBtn = document.querySelector('.search-btn');
const searchBox = document.querySelector('.search-box');
const searchCont = document.querySelector('.search-cont');
const themeContent = document.querySelector('.theme-default-content');
const sidebar = document.querySelector('.sidebar');
const page = document.querySelector('.page');
// 将nav-bar元素置顶
const navBar = document.querySelector('.nav-bar');
if (navBar) {
navBar.style.top = '0';
if (navBar) {navBar.style.top = '0';}
if (header) {header.style.top = '0';}
if (searchBtn) { searchBtn.style.width = '60px';}
if (searchBox) {searchBox.style.width = 'auto';}
if (themeContent) { themeContent.style.borderRadius = '8px'; }
if (searchCont && header) {
searchCont.style.width = 'auto';
searchCont.style.position = 'fixed';
searchCont.style.top = '22px';
searchCont.style.left = '50%';
searchCont.style.transform = 'translateX(-90%)';
header.appendChild(searchCont);
}
if (sidebar) {
sidebar.style.top = '75px';
sidebar.style.height = '-webkit-fill-available';
sidebar.style.removeProperty('display');
}
if (page) {
page.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
page.style.borderRadius = '8px';
}
}
// 将header.navbar.fixed-navbar元素置顶
const header = document.querySelector('header.navbar.fixed-navbar');
if (header) {
header.style.top = '0';
}
// 设置.search-btn的宽度为65px
const searchBtn = document.querySelector('.search-btn');
if (searchBtn) {
searchBtn.style.width = '60px';
}
// 设置.search-box宽度为auto
const searchBox = document.querySelector('.search-box');
if (searchBox) {
searchBox.style.width = 'auto';
}
// 设置.search-cont宽度为auto并移动到navbar fixed-navbar中置顶居中
const searchCont = document.querySelector('.search-cont');
const newheader = document.querySelector('header.navbar.fixed-navbar');
if (searchCont && newheader) {
searchCont.style.width = 'auto';
searchCont.style.position = 'fixed';
searchCont.style.top = '22px';
searchCont.style.left = '50%';
searchCont.style.transform = 'translateX(-90%)';
header.appendChild(searchCont);
}
// 隐藏.page-top元素
// 动态隐藏.page-top元素
function hidePageTop() {
// 动态隐藏元素
function hide() {
const pageTop = document.querySelector('.page-top');
const pageTopFixed = document.querySelector('.page-top-fixed');
const pageTopboth = document.querySelector('.page-top-fixed.page-top');
if (pageTop) {
pageTop.style.display = 'none';
}
if (pageTopFixed) {
pageTopFixed.style.display = 'none';
}
if (pageTopboth) {
pageTopboth.style.display = 'none';
}
// 移除.page元素的padding-top
const navBtn = document.querySelector('.nav-btn');
const btnCont = document.querySelector('.btn-cont');
const openRight = document.querySelector('.open-right');
const page = document.querySelector('.page');
const footer = document.querySelector('.footer');
const feedbackBtn = document.querySelector('.btn.feedback');
const hideSide = document.querySelector('.hide-side');
const nietopbar = document.getElementById('NIE-topBar');
if (pageTop) { pageTop.style.display = 'none'; }
if (pageTopFixed) {pageTopFixed.style.display = 'none';}
if (pageTopboth) {pageTopboth.style.display = 'none';}
if (page) {page.style.paddingTop = '0';}
if (navBtn) {navBtn.style.display = 'none';}
if (btnCont) {btnCont.style.display = 'none';}
if (openRight) {openRight.style.display = 'none';}
if (footer) {footer.style.display = 'none';}
if (feedbackBtn) {feedbackBtn.style.display = 'none';}
if (hideSide) { hideSide.style.display = 'none';}
if (nietopbar) {nietopbar.style.display = 'none';}
}
// 页面布局修复
function fix() {
const page = document.querySelector('.page');
if (page) {
page.style.paddingTop = '0';
page.style.flex = '0';
page.style.marginLeft = 'auto';
page.style.width = '67%';
page.style.overflow = 'visible';
}
const pageContent = document.querySelector('.page-container');
if (pageContent) {
pageContent.style.display = 'block';
}
// 设置html宽度为浏览器窗口实际大小
const htmlElement = document.documentElement;
if (htmlElement) {
htmlElement.style.width = window.innerWidth + 'px';
htmlElement.style.minWidth = window.innerWidth + 'px';
htmlElement.style.transform = 'none';
// 确保不出现横向滚动条
htmlElement.style.overflowX = 'hidden';
}
// 设置body元素宽度
if (document.body) {
document.body.style.width = window.innerWidth + 'px';
}
// 设置id为app的元素宽度
const appElement = document.getElementById('app');
if (appElement) {
appElement.style.width = window.innerWidth + 'px';
}
}
// 初始隐藏
hidePageTop();
// 监听DOM变化和页面重新渲染
const observer = new MutationObserver(function(mutations) {
hidePageTop();
// 检查是否有节点被添加或属性变化
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length > 0 || mutation.attributeName) {
console.log('检测到页面重新渲染');
// 在这里添加重新渲染后的处理逻辑
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['style', 'class']
});
// 监听窗口缩放事件
window.addEventListener('resize', hidePageTop);
// 监听滚动事件
window.addEventListener('scroll', hidePageTop);
// 隐藏.nav-btn元素
const navBtn = document.querySelector('.nav-btn');
if (navBtn) {
navBtn.style.display = 'none';
}
// 设置.center-cont宽度为auto
const centerCont = document.querySelector('.center-cont');
if (centerCont) {
// centerCont.style.width = 'auto';
}
// 隐藏.btn-cont元素
const btnCont = document.querySelector('.btn-cont');
if (btnCont) {
btnCont.style.display = 'none';
}
// 隐藏.open-right元素
const openRight = document.querySelector('.open-right');
if (openRight) {
openRight.style.display = 'none';
}
// 设置.sidebar元素的top样式
const sidebar = document.querySelector('.sidebar');
if (sidebar) {
sidebar.style.top = '75px';
sidebar.style.height = '-webkit-fill-available';
sidebar.style.removeProperty('display');
}
// 创建urlmenu菜单
const urlMenu = document.createElement('div');
urlMenu.className = 'urlmenu';
urlMenu.innerHTML = `
<a href="https://mc.163.com/dev/apidocs.html">API文档</a>
<a href="https://mc.163.com/dev/guide.html">开发指南</a>
<a href="https://mc.163.com/dev/course.html">教学课程</a>
<a href="https://mc.163.com/dev/newslist.html">新闻与活动</a>
<a href="https://mc.163.com/dev/help.html">帮助中心</a>
<a href="https://mcdev.webapp.163.com/#/feedbackModal?target=browser" target="_blank">问题反馈</a>
<a href="https://adl.netease.com/d/g/mc/c/dev">MCStudio</a>
`;
// 设置菜单样式
urlMenu.style.position = 'fixed';
urlMenu.style.right = '20px';
urlMenu.style.top = '15px';
// urlMenu.style.backgroundColor = 'rgba(0, 0, 0, 0)';
urlMenu.style.padding = '10px';
urlMenu.style.borderRadius = '5px';
// 添加到navbar fixed-navbar中
if (header) {
header.appendChild(urlMenu);
}
// 为.theme-default-content添加圆角
const themeContent = document.querySelector('.theme-default-content');
if (themeContent) {
themeContent.style.borderRadius = '8px';
function Menu() {
const header = document.querySelector('header.navbar.fixed-navbar');
const urlMenu = document.createElement('div');
urlMenu.className = 'urlmenu';
urlMenu.innerHTML = `
<a href="https://mc.163.com/dev/apidocs.html">API文档</a>
<a href="https://mc.163.com/dev/guide.html">开发指南</a>
<a href="https://mc.163.com/dev/course.html">教学课程</a>
<a href="https://mc.163.com/dev/newslist.html">新闻与活动</a>
<a href="https://mc.163.com/dev/help.html">帮助中心</a>
<a href="https://mcdev.webapp.163.com/#/feedbackModal?target=browser" target="_blank">问题反馈</a>
<a href="https://adl.netease.com/d/g/mc/c/dev">MCStudio</a>
`;
// 设置菜单样式
urlMenu.style.position = 'fixed';
urlMenu.style.right = '20px';
urlMenu.style.top = '15px';
urlMenu.style.padding = '10px';
urlMenu.style.borderRadius = '5px';
// urlMenu.style.backgroundColor = 'rgba(0, 0, 0, 0)';
// 添加到navbar fixed-navbar中
if (header) {header.appendChild(urlMenu);}
}
// 隐藏footer元素
const footer = document.querySelector('.footer');
if (footer) {
footer.style.display = 'none';
// 注册功能函数
function mian() {
hide();
Menu();
newUI();
fix();
}
// 隐藏反馈按钮
const feedbackBtn = document.querySelector('.btn.feedback');
if (feedbackBtn) {
feedbackBtn.style.display = 'none';
}
// 监听在页面和脚本渲染完成后
document.addEventListener('DOMContentLoaded', function() {
mian();
});
// 隐藏.hide-side元素
const hideSide = document.querySelector('.hide-side');
if (hideSide) {
hideSide.style.display = 'none';
}
// 监听窗口大小变化
window.addEventListener('resize', function() {
mian();
})
// 监听页面滚动事件
window.addEventListener('scroll', function() {
mian();
});
// 监听文档加载状态变化(开始渲染时)
document.addEventListener('readystatechange', function() {
// interactive表示DOM已加载但资源可能未完成complete表示所有资源加载完成
if (document.readyState === 'interactive' || document.readyState === 'complete') {
mian();
}
});
})();