Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
b707d2339f | |||
a9ad1cc25c |
235
MCdoc.js
235
MCdoc.js
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name 中国版我的世界开发者文档 美化
|
// @name 中国版我的世界开发者文档 美化
|
||||||
// @namespace https://git.xjyofc.top/xjy/MCdoc_js
|
// @namespace https://git.xjyofc.top/xjy/MCdoc_js
|
||||||
// @version 1.0
|
// @version 2.0
|
||||||
// @description 更好的中国版我的世界开发者文档界面
|
// @description 更好的中国版我的世界开发者文档界面
|
||||||
// @author 仙君御
|
// @author 仙君御
|
||||||
// @match https://mc.163.com/dev/*
|
// @match https://mc.163.com/dev/*
|
||||||
@@ -12,37 +12,23 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// 隐藏NIE-topBar元素
|
// 新样式
|
||||||
document.getElementById('NIE-topBar').style.display = 'none';
|
function newUI(){
|
||||||
|
|
||||||
// 将nav-bar元素置顶
|
|
||||||
const navBar = document.querySelector('.nav-bar');
|
const navBar = document.querySelector('.nav-bar');
|
||||||
if (navBar) {
|
|
||||||
navBar.style.top = '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将header.navbar.fixed-navbar元素置顶
|
|
||||||
const header = document.querySelector('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');
|
const searchBtn = document.querySelector('.search-btn');
|
||||||
if (searchBtn) {
|
|
||||||
searchBtn.style.width = '60px';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置.search-box宽度为auto
|
|
||||||
const searchBox = document.querySelector('.search-box');
|
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 searchCont = document.querySelector('.search-cont');
|
||||||
const newheader = document.querySelector('header.navbar.fixed-navbar');
|
const themeContent = document.querySelector('.theme-default-content');
|
||||||
if (searchCont && newheader) {
|
const sidebar = document.querySelector('.sidebar');
|
||||||
|
const page = document.querySelector('.page');
|
||||||
|
|
||||||
|
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.width = 'auto';
|
||||||
searchCont.style.position = 'fixed';
|
searchCont.style.position = 'fixed';
|
||||||
searchCont.style.top = '22px';
|
searchCont.style.top = '22px';
|
||||||
@@ -50,88 +36,83 @@
|
|||||||
searchCont.style.transform = 'translateX(-90%)';
|
searchCont.style.transform = 'translateX(-90%)';
|
||||||
header.appendChild(searchCont);
|
header.appendChild(searchCont);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏.page-top元素
|
|
||||||
// 动态隐藏.page-top元素
|
|
||||||
function hidePageTop() {
|
|
||||||
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 page = document.querySelector('.page');
|
|
||||||
if (page) {
|
|
||||||
page.style.paddingTop = '0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始隐藏
|
|
||||||
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) {
|
if (sidebar) {
|
||||||
sidebar.style.top = '75px';
|
sidebar.style.top = '75px';
|
||||||
sidebar.style.height = '-webkit-fill-available';
|
sidebar.style.height = '-webkit-fill-available';
|
||||||
sidebar.style.removeProperty('display');
|
sidebar.style.removeProperty('display');
|
||||||
}
|
}
|
||||||
|
if (page) {
|
||||||
|
page.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
|
||||||
|
page.style.borderRadius = '8px';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 动态隐藏元素
|
||||||
|
function hide() {
|
||||||
|
const pageTop = document.querySelector('.page-top');
|
||||||
|
const pageTopFixed = document.querySelector('.page-top-fixed');
|
||||||
|
const pageTopboth = document.querySelector('.page-top-fixed.page-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';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 创建urlmenu菜单
|
// 创建urlmenu菜单
|
||||||
|
function Menu() {
|
||||||
|
const header = document.querySelector('header.navbar.fixed-navbar');
|
||||||
const urlMenu = document.createElement('div');
|
const urlMenu = document.createElement('div');
|
||||||
urlMenu.className = 'urlmenu';
|
urlMenu.className = 'urlmenu';
|
||||||
urlMenu.innerHTML = `
|
urlMenu.innerHTML = `
|
||||||
@@ -143,42 +124,46 @@
|
|||||||
<a href="https://mcdev.webapp.163.com/#/feedbackModal?target=browser" target="_blank">问题反馈</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>
|
<a href="https://adl.netease.com/d/g/mc/c/dev">MCStudio</a>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// 设置菜单样式
|
// 设置菜单样式
|
||||||
urlMenu.style.position = 'fixed';
|
urlMenu.style.position = 'fixed';
|
||||||
urlMenu.style.right = '20px';
|
urlMenu.style.right = '20px';
|
||||||
urlMenu.style.top = '15px';
|
urlMenu.style.top = '15px';
|
||||||
// urlMenu.style.backgroundColor = 'rgba(0, 0, 0, 0)';
|
|
||||||
urlMenu.style.padding = '10px';
|
urlMenu.style.padding = '10px';
|
||||||
urlMenu.style.borderRadius = '5px';
|
urlMenu.style.borderRadius = '5px';
|
||||||
|
// urlMenu.style.backgroundColor = 'rgba(0, 0, 0, 0)';
|
||||||
// 添加到navbar fixed-navbar中
|
// 添加到navbar fixed-navbar中
|
||||||
if (header) {
|
if (header) {header.appendChild(urlMenu);}
|
||||||
header.appendChild(urlMenu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 为.theme-default-content添加圆角
|
// 注册功能函数
|
||||||
const themeContent = document.querySelector('.theme-default-content');
|
function mian() {
|
||||||
if (themeContent) {
|
hide();
|
||||||
themeContent.style.borderRadius = '8px';
|
Menu();
|
||||||
|
newUI();
|
||||||
|
fix();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏footer元素
|
// 监听在页面和脚本渲染完成后
|
||||||
const footer = document.querySelector('.footer');
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
if (footer) {
|
mian();
|
||||||
footer.style.display = 'none';
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// 隐藏反馈按钮
|
// 监听窗口大小变化
|
||||||
const feedbackBtn = document.querySelector('.btn.feedback');
|
window.addEventListener('resize', function() {
|
||||||
if (feedbackBtn) {
|
mian();
|
||||||
feedbackBtn.style.display = 'none';
|
})
|
||||||
}
|
|
||||||
|
|
||||||
// 隐藏.hide-side元素
|
// 监听页面滚动事件
|
||||||
const hideSide = document.querySelector('.hide-side');
|
window.addEventListener('scroll', function() {
|
||||||
if (hideSide) {
|
mian();
|
||||||
hideSide.style.display = 'none';
|
});
|
||||||
|
|
||||||
|
// 监听文档加载状态变化(开始渲染时)
|
||||||
|
document.addEventListener('readystatechange', function() {
|
||||||
|
// interactive表示DOM已加载但资源可能未完成,complete表示所有资源加载完成
|
||||||
|
if (document.readyState === 'interactive' || document.readyState === 'complete') {
|
||||||
|
mian();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Reference in New Issue
Block a user