-
Notifications
You must be signed in to change notification settings - Fork 1
/
HUPU-BBS-Beautification.user.js
133 lines (127 loc) · 6.36 KB
/
HUPU-BBS-Beautification.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// ==UserScript==
// @name 虎扑网页端优化
// @namespace http://tampermonkey.net/
// @homepage https://github.com/Trrrrw/UserScript
// @version 0.1.2
// @description 优化虎扑网页端
// @author Trrrrw
// @match https://bbs.hupu.com/*
// @grant GM_addStyle
// @grant GM_addElement
// @grant window.onload
// @grant window.history
// @icon https://w1.hoopchina.com.cn/images/pc/old/favicon.ico
// @downloadURL https://cdn.staticaly.com/gh/Trrrrw/UserScript@main/HUPU-BBS-Beautification.user.js
// @updateURL https://cdn.staticaly.com/gh/Trrrrw/UserScript@main/HUPU-BBS-Beautification.user.js
// @license GPL-3.0
// ==/UserScript==
//帖子在当前页面打开
function set_title() {
for (var k = 0; k < document.getElementsByClassName('p-title').length; k++) {
document.getElementsByClassName('p-title')[k].target = '_self';
}
}
/**
* 这个函数用于删除传入的元素
* @param {string} selector - 要删除的元素
*/
function del_dom(selector) {
GM_addStyle(`${selector}{display:none !important;}`)
}
(function () {
//删除元素
var domToDel = [
'.hu-pc-navigation-type',//话题广场
'.hu-pc-navigation-topic-type-item',
'.index_game-center-sidebar__xz6S_',//虎扑游戏悬浮窗
'.index_game-center-entrance-container-title__BNope','#game-center-entrance-container',//虎扑游戏中心
'.index_right-post__Yuzlv:nth-of-type(2)',//热门游戏
'.index_download-app__ui5ia',//下载虎扑侧栏
'.index_qrcodeBox__zLFSV',//下载虎扑二维码
'.index_right-post__Yuzlv'//崩坏3最热帖
];
domToDel.forEach(selector => {
del_dom(selector)
});
//调整元素
GM_addStyle('.index_bbs-post-web-body-left-wrapper__O14II{flex: auto;width: auto;}')//调整帖子样式
GM_addStyle('.backToTop_2mZa6{bottom:10px;right:8px;}')//右下按钮
GM_addStyle('.index_backToTop__rx3__{bottom:10px !important;right:8px !important;}')//帖子内右下按钮
//删除顶部红条
GM_addStyle('.hp-pc-rc-TopMenu{height: 24px !important;}')
GM_addStyle('.hp-pc-rc-TopMenu-banner{display:none !important;}')
// //最上方一栏 #c60100
GM_addStyle('.hp-pc-rc-TopMenu-top-container{background-color: #fff;box-shadow: 0px 0.1px 0px black;}'); GM_addStyle('.hp-pc-rc-TopMenu-top{background-color: #fff;}')
// //字体颜色
// GM_addStyle('.hp-pc-rc-TopMenu-top .hp-topLogin-info .hasLogin li a {color: #fff;}')
// GM_addStyle('.hp-pc-rc-TopMenu-top .hp-topLogin-info .hasLogin li a:hover {color: #dedede;}')
// GM_addStyle('.hp-pc-rc-TopMenu-top .hp-topLogin-info {color: #fff;}')
// GM_addStyle('.hp-pc-rc-TopMenu-top .hp-topLogin-info .hasLogin .hp-topNotificat:hover {color: #dedede;}')
// GM_addStyle('.hp-pc-rc-TopMenu-top .hp-quickNav a {color: #fff;}')
// GM_addStyle('.hp-pc-rc-TopMenu-top .hp-quickNav a:hover {color: #dedede;}')
//帖子在当前页面打开
set_title()
document.onmouseup = function () {
set_title()
}
window.onload = function () {
//深色模式版头图片
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
// 系统处于深色模式
try{
console.log('系统处于深色模式')
var topPic = document.getElementsByClassName('bbs-sl-web-intro')[0]
const topPicStyle = topPic.style.cssText
const darkTopPicStyle = topPicStyle.replace(/rgb\(255, 255, 255\)/g, 'rgba(0, 0, 0, 0.95)').replace(/rgba\(255, 255, 255, 0.9\)/g, 'rgba(0, 0, 0, 0.9)');
topPic.style.cssText = darkTopPicStyle
GM_addStyle('#container > div > div.bbs-sl-web-holder > div > div.bbs-sl-web-topic-wrap > div.bbs-sl-web-intro > div.bbs-sl-web-intro-avatar > img{background: linear-gradient(90deg, rgba(0, 0, 0, 0.95) 20%, rgba(0, 0, 0, 0.9));}')
}
catch{
console.log('...')
}
} else {
// 系统处于浅色模式
try{
console.log('系统处于深色模式')
}
catch{
console.log('...')
}
};
//添加返回按钮
var backLink = document.querySelector("#__next > div > div.index_bbs-post-web-container___cRHg > div.index_bbs-post-web-body__XQ5Sq > div.index_bbs-post-web-body-left-wrapper__O14II > div > div > div:nth-child(1) > section > span:nth-child(3) > a").href
GM_addStyle('.iconxiazaihupu{display:none !important}')
GM_addElement('link', {
rel: 'stylesheet',
href: 'https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css'
});
GM_addElement(document.getElementsByClassName('index_link__U4H39')[0], 'i', {
class: 'fa fa-arrow-left index_icon__lUGzK',
'aria-hidden': 'true'
})
document.getElementsByClassName('index_text__XBhts')[0].innerText = '返回'; document.getElementsByClassName('index_text__XBhts')[1].innerText = '上级'
document.getElementsByClassName('index_box__x5WWh')[0].onclick = function () {
// window.history.back();
window.open(backLink,'_self')
};
//添加跳转到评论区
document.getElementsByClassName("post-reply_post-reply__D1M4P")[0].id="commentArea";
document.getElementsByClassName('index_text__XBhts')[2].innerText = '前往'; document.getElementsByClassName('index_text__XBhts')[3].innerText = '评论'
var commentButton=document.getElementsByClassName("index_link__U4H39")[1];
commentButton.removeAttribute("target");
commentButton.setAttribute("href","#commentArea");
commentButton.addEventListener('click', function(event) {
// 取消默认的点击行为
event.preventDefault();
// 获取目标元素
var targetElement = document.getElementById('commentArea');
// 计算目标位置
var targetPosition = targetElement.offsetTop;
// 滚动到目标位置
window.scrollTo({
top: targetPosition,
behavior: 'smooth' // 平滑滚动
});
});
}
})();