Skip to content

Commit 6c8cdec

Browse files
committed
Update JiandanHero.user.js
1 parent ffdfa8d commit 6c8cdec

1 file changed

Lines changed: 43 additions & 10 deletions

File tree

JiandanHero/JiandanHero.user.js

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:en Jiandan Hero
44
// @name:zh-TW 煎蛋俠
55
// @namespace hoothin
6-
// @version 1.9
6+
// @version 2.0
77
// @icon http://cdn.jandan.net/static/img/favicon.ico
88
// @description 为煎蛋jandan.net提供左右方向键快捷翻页、上下方向键快捷切图、鼠标悬停显示大图、屏蔽指定用户发言等功能
99
// @description:en Tools for jandan.net
@@ -40,7 +40,6 @@
4040
};
4141

4242
document.addEventListener("keyup", function(e) {
43-
//console.log(e.keyCode);
4443
if(/INPUT|TEXTAREA/.test(document.activeElement.tagName))return;
4544
switch(e.keyCode){
4645
case 37://←
@@ -96,20 +95,22 @@
9695
}
9796
}
9897
}
99-
var isHttps=location.protocol=="https:";
98+
var isHttps=location.protocol=="https:",selector;
10099
var isTucao=document.querySelector(".tucao-list")!=null;
101100
var isTop=location.href.indexOf("jandan.net/top")!=-1;
102101
var isMobile=location.href.indexOf("i.jandan.net")!=-1;
103-
$("body").on("mouseover", "div.author,.tucao-author-bar,.commentlist>li>b", e=>{
104-
let author=e.currentTarget,authorId;
102+
103+
function checkBan(author){
104+
let authorId;
105105
let changeBtn = author.querySelector("#changeBtn");
106106
if(changeBtn == null){
107107
changeBtn=document.createElement("a");
108108
changeBtn.href=`javascript:void(0);`;
109109
changeBtn.id="changeBtn";
110110
if(isMobile){
111-
authorId=author.childNodes[0].nodeValue;
112-
author.appendChild(changeBtn);
111+
authorId=author.querySelector("b").innerText;
112+
author.insertBefore(changeBtn,author.querySelector(".righttext"));
113+
author=author.querySelector("b");
113114
}else if(isTucao){
114115
authorId=author.querySelector(".tucao-author").innerText;
115116
author.insertBefore(changeBtn,author.querySelector(".tucao-author").nextSibling);
@@ -159,13 +160,42 @@
159160
changeBtn.innerHTML="隐";
160161
}
161162
}
162-
changeBtn.style.display="";
163+
return changeBtn;
164+
}
165+
166+
if(isMobile){
167+
selector=".commentlist>li";
168+
}else{
169+
selector="div.author,.tucao-author-bar";
170+
}
171+
[].forEach.call(document.querySelectorAll(selector), item=>{
172+
checkBan(item);
173+
});
174+
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
175+
var observer = new MutationObserver(function(records){
176+
records.map(function(record) {
177+
for(var i=0;i<record.addedNodes.length;i++){
178+
var curNode=record.addedNodes[i];
179+
if(curNode.className=="tucao-row"){
180+
checkBan(curNode.querySelector(selector));
181+
}
182+
}
183+
});
184+
});
185+
var option = {
186+
'childList': true
187+
};
188+
var tucaoList=document.querySelector("div.tucao-list");
189+
if(tucaoList)observer.observe(tucaoList, option);
190+
$("body").on("mouseover", selector, e=>{
191+
let changeBtn=checkBan(e.currentTarget);
192+
changeBtn.style.display="initial";
163193
//console.log(e);
164194
});
165-
$("body").on("mouseout", "div.author,.tucao-author-bar,.commentlist>li>b", e=>{
195+
$("body").on("mouseout", selector, e=>{
166196
let author=e.currentTarget;
167197
let changeBtn = author.querySelector("#changeBtn");
168-
if(changeBtn)changeBtn.style.display="none";
198+
if(changeBtn)changeBtn.style.display="";
169199
});
170200
/*for(i=0;i<authors.length;i++){
171201
let author=authors[i];
@@ -370,6 +400,9 @@
370400
.tucao-author-bar #changeBtn{
371401
padding: 0 10px;
372402
}
403+
#changeBtn{
404+
display: none;
405+
}
373406
.big_img{
374407
pointer-events: none;
375408
position: fixed;

0 commit comments

Comments
 (0)