Skip to content

Commit c12dbfb

Browse files
committed
优化 代码
1 parent d90fcf9 commit c12dbfb

1 file changed

Lines changed: 48 additions & 36 deletions

File tree

Zhiyoo-Enhanced.user.js

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
// 注册脚本菜单
3030
function registerMenuCommand() {
31-
var menu_cleanPostTitle_;
31+
let menu_cleanPostTitle_;
3232
if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单
3333
GM_unregisterMenuCommand(menu_cleanPostTitle_ID);
3434
GM_unregisterMenuCommand(menu_qianDaoRedirectURL_ID);
@@ -115,49 +115,49 @@
115115

116116
// 用于脚本内部判断当前 URL 类型
117117
let SiteType = {
118-
FORUMDISPLAY: DBSite.forumdisplay.SiteTypeID, // 各板块帖子列表
119-
SEARCH: DBSite.search.SiteTypeID // 搜索结果列表
118+
FORUMDISPLAY: DBSite.forumdisplay.SiteTypeID, // 各板块帖子列表
119+
SEARCH: DBSite.search.SiteTypeID // 搜索结果列表
120120
};
121121

122122
var attachmentHrefTime = 0;
123-
curSite.pageUrl = ""; // 下一页URL
123+
curSite.pageUrl = ""; // 下一页URL
124124

125-
var patt_thread = /\/thread-\d+-\d+\-\d+.html/, // 匹配 /thread-XXX-X-X.html 帖子正则表达式
126-
patt_search = /\/thread-\d+-\d+\-\d+.html/, // 匹配搜索结果列表正则表达式
127-
patt_posttitle = /^.+()?|^.+()?/, // 匹配帖子标题中的〖XXX〗【XXX】正则表达式
125+
var patt_thread = /\/thread-\d+-\d+\-\d+.html/, // 匹配 /thread-XXX-X-X.html 帖子正则表达式
126+
patt_search = /\/thread-\d+-\d+\-\d+.html/, // 匹配搜索结果列表正则表达式
127+
patt_posttitle = /^.+()?|^.+()?/, // 匹配帖子标题中的〖XXX〗【XXX】正则表达式
128128
patt_attachment_href = /(?<=\\').+(?=\\')/
129129

130130
if (location.pathname === '/plugin.php'){
131131
switch(getQueryVariable("id"))
132132
{
133-
case 'dsu_paulsign:sign': // 被重定向到签到页面
134-
qiandao(); // 自动签到
133+
case 'dsu_paulsign:sign': // 被重定向到签到页面
134+
qiandao(); // 自动签到
135135
break;
136-
case 'piaobo_attachment': // 兑换附件后的提示页面
137-
attachmentBack(); // 立即返回帖子
136+
case 'piaobo_attachment': // 兑换附件后的提示页面
137+
attachmentBack(); // 立即返回帖子
138138
break;
139-
case 'threed_attach:downld': // 附件下载页面
140-
goPan(); // 跳转至网盘页
139+
case 'threed_attach:downld': // 附件下载页面
140+
goPan(); // 跳转至网盘页
141141
break;
142142
}
143143
}else if(location.pathname === '/forum.php'){
144144
switch(getQueryVariable("mod"))
145145
{
146-
case 'viewthread': // 浏览帖子内容
147-
showHide(); // 先看看是否有隐藏内容,如果已显示则定位到隐藏内容区域,如果没有隐藏内容,则啥都不干
148-
autoReply(); // 自动回复(有隐藏内容才会回复),回复过就定位到底部(隐藏内容区域)
146+
case 'viewthread': // 浏览帖子内容
147+
showHide(); // 先看看是否有隐藏内容,如果已显示则定位到隐藏内容区域,如果没有隐藏内容,则啥都不干
148+
autoReply(); // 自动回复(有隐藏内容才会回复),回复过就定位到底部(隐藏内容区域)
149149
var attachmentHref_Interval = setInterval(attachmentHref,100); // 兑换附件按钮改为直链(不再弹出确认提示框)
150150
break;
151-
case 'forumdisplay': // 浏览帖子列表
152-
curSite = DBSite.forumdisplay; // 帖子列表页(自动翻页)
153-
cleanTop(); // 清理置顶帖子
154-
cleanPostTitle(); // 清理帖子列表中帖子标题开头的〖XXX〗【XXX】文字
155-
pageLoading(); // 自动无缝翻页
151+
case 'forumdisplay': // 浏览帖子列表
152+
curSite = DBSite.forumdisplay; // 帖子列表页(自动翻页)
153+
cleanTop(); // 清理置顶帖子
154+
cleanPostTitle(); // 清理帖子列表中帖子标题开头的〖XXX〗【XXX】文字
155+
pageLoading(); // 自动无缝翻页
156156
break;
157157
}
158158
}else if(location.pathname === '/search.php'){
159-
curSite = DBSite.search; // 搜索结果列表页(自动翻页)
160-
pageLoading(); // 自动无缝翻页
159+
curSite = DBSite.search; // 搜索结果列表页(自动翻页)
160+
pageLoading(); // 自动无缝翻页
161161
}else if (patt_thread.test(location.pathname)){ // 对于 /thread-XXX-X-X.html 这种帖子页面也和上面一样
162162
showHide();
163163
autoReply();
@@ -166,7 +166,7 @@
166166

167167
// 判断是否登陆
168168
function checkLogin(){
169-
var checklogin = document.querySelector('.Quater_user.logined');
169+
let checklogin = document.querySelector('.Quater_user.logined');
170170
if (checklogin){
171171
loginStatus = true;
172172
}
@@ -177,8 +177,8 @@
177177
function pageLoading() {
178178
if (curSite.SiteTypeID > 0){
179179
windowScroll(function (direction, e) {
180-
if (direction === "down") { // 下滑才准备翻页
181-
var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
180+
if (direction === "down") { // 下滑才准备翻页
181+
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
182182
let scrollDelta = 666;
183183
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
184184
ShowPager.loadMorePage();
@@ -208,15 +208,20 @@
208208
// 存在隐藏内容,自动回复
209209
if (document.getElementsByClassName("showhide").length == 0){
210210
writeReply();
211-
setTimeout(`window.scrollTo(0,document.querySelector('.showhide').offsetTop)`, 1000);
211+
// 如果使用了我的 [智友邦美化] 脚本,则定位至底部,反之定位至隐藏内容区域
212+
if (document.getElementById("fastpostmessage").offsetParent == null){
213+
setTimeout(`window.scrollTo(0,99999999)`, 500);
214+
}else{
215+
setTimeout(`window.scrollTo(0,document.querySelector('.showhide').offsetTop)`, 500);
216+
}
212217
}
213218
}
214219
}
215220

216221

217222
// 写入自动回复内容
218223
function writeReply(){
219-
var textarea = document.getElementById("fastpostmessage");
224+
let textarea = document.getElementById("fastpostmessage");
220225
if (textarea){
221226
// 随机写入回复内容
222227
textarea.value = textarea.value + replyList[Math.floor((Math.random()*replyList.length))] + replyList[Math.floor((Math.random()*replyList.length))];
@@ -235,15 +240,22 @@
235240
// 如果已显示隐藏内容,则定位到隐藏内容区域
236241
// 如果没有发现已显示隐藏内容,就不定位了
237242
if (document.getElementsByClassName("showhide").length > 0){
238-
setTimeout(`window.scrollTo(0,document.querySelector('.showhide').offsetTop)`, 500);
243+
// 如果使用了我的 [智友邦美化] 脚本,则定位至底部,反之定位至隐藏内容区域
244+
if (document.getElementById("fastpostmessage").offsetParent == null){
245+
setTimeout(`window.scrollTo(0,99999999)`, 500);
246+
console.log("111")
247+
}else{
248+
setTimeout(`window.scrollTo(0,document.querySelector('.showhide').offsetTop)`, 500);
249+
console.log("222")
250+
}
239251
}
240252
}
241253
}
242254

243255

244256
// 兑换附件后立即返回
245257
function attachmentBack() {
246-
var attachmentback = document.querySelector('#messagetext p.alert_btnleft a');
258+
let attachmentback = document.querySelector('#messagetext p.alert_btnleft a');
247259
if (attachmentback){
248260
attachmentback.click();
249261
}
@@ -252,7 +264,7 @@
252264

253265
// 附件下载页直接跳转至网盘
254266
function goPan() {
255-
var gopan = document.querySelector('.threed_panbox .panframe .pan_left p a');
267+
let gopan = document.querySelector('.threed_panbox .panframe .pan_left p a');
256268
if (gopan){
257269
location.href=gopan.href;
258270
}
@@ -262,9 +274,9 @@
262274
// 兑换附件按钮改为直链(不再弹出确认提示框)
263275
function attachmentHref() {
264276
attachmentHrefTime += 1; // 计算该函数执行次数
265-
var attachmenthref = document.querySelector('.tab_button .button a');
277+
let attachmenthref = document.querySelector('.tab_button .button a');
266278
if (attachmenthref && attachmenthref.href == "javascript:;"){
267-
var attachmenthref_href = attachmenthref.onclick.toString();
279+
let attachmenthref_href = attachmenthref.onclick.toString();
268280
attachmenthref.href = attachmenthref_href.match(patt_attachment_href)[0];
269281
attachmenthref.onclick = null;
270282
}
@@ -276,7 +288,7 @@
276288

277289
// 清理置顶帖子
278290
function cleanTop(){
279-
var showhide = document.querySelectorAll("a.showhide.y");
291+
let showhide = document.querySelectorAll("a.showhide.y");
280292
if (showhide.length > 0){
281293
showhide.forEach(el=>el.click());
282294
}
@@ -286,9 +298,9 @@
286298
// 清理帖子列表中帖子标题开头的〖XXX〗【XXX】文字
287299
function cleanPostTitle(){
288300
if (menu_cleanPostTitle){
289-
var cleanposttitle = document.querySelectorAll("a.s.xst");
301+
let cleanposttitle = document.querySelectorAll("a.s.xst");
290302
if (cleanposttitle.length > 0){
291-
for(var num = postNum;num<cleanposttitle.length;num++){
303+
for(let num = postNum;num<cleanposttitle.length;num++){
292304
cleanposttitle[num].innerText = cleanposttitle[num].innerText.replace(patt_posttitle, ``);
293305
postNum += 1;
294306
}

0 commit comments

Comments
 (0)