|
3 | 3 | // @name:en Jiandan Hero |
4 | 4 | // @name:zh-TW 煎蛋俠 |
5 | 5 | // @namespace hoothin |
6 | | -// @version 1.9 |
| 6 | +// @version 2.0 |
7 | 7 | // @icon http://cdn.jandan.net/static/img/favicon.ico |
8 | 8 | // @description 为煎蛋jandan.net提供左右方向键快捷翻页、上下方向键快捷切图、鼠标悬停显示大图、屏蔽指定用户发言等功能 |
9 | 9 | // @description:en Tools for jandan.net |
|
40 | 40 | }; |
41 | 41 |
|
42 | 42 | document.addEventListener("keyup", function(e) { |
43 | | - //console.log(e.keyCode); |
44 | 43 | if(/INPUT|TEXTAREA/.test(document.activeElement.tagName))return; |
45 | 44 | switch(e.keyCode){ |
46 | 45 | case 37://← |
|
96 | 95 | } |
97 | 96 | } |
98 | 97 | } |
99 | | - var isHttps=location.protocol=="https:"; |
| 98 | + var isHttps=location.protocol=="https:",selector; |
100 | 99 | var isTucao=document.querySelector(".tucao-list")!=null; |
101 | 100 | var isTop=location.href.indexOf("jandan.net/top")!=-1; |
102 | 101 | 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; |
105 | 105 | let changeBtn = author.querySelector("#changeBtn"); |
106 | 106 | if(changeBtn == null){ |
107 | 107 | changeBtn=document.createElement("a"); |
108 | 108 | changeBtn.href=`javascript:void(0);`; |
109 | 109 | changeBtn.id="changeBtn"; |
110 | 110 | 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"); |
113 | 114 | }else if(isTucao){ |
114 | 115 | authorId=author.querySelector(".tucao-author").innerText; |
115 | 116 | author.insertBefore(changeBtn,author.querySelector(".tucao-author").nextSibling); |
|
159 | 160 | changeBtn.innerHTML="隐"; |
160 | 161 | } |
161 | 162 | } |
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"; |
163 | 193 | //console.log(e); |
164 | 194 | }); |
165 | | - $("body").on("mouseout", "div.author,.tucao-author-bar,.commentlist>li>b", e=>{ |
| 195 | + $("body").on("mouseout", selector, e=>{ |
166 | 196 | let author=e.currentTarget; |
167 | 197 | let changeBtn = author.querySelector("#changeBtn"); |
168 | | - if(changeBtn)changeBtn.style.display="none"; |
| 198 | + if(changeBtn)changeBtn.style.display=""; |
169 | 199 | }); |
170 | 200 | /*for(i=0;i<authors.length;i++){ |
171 | 201 | let author=authors[i]; |
|
370 | 400 | .tucao-author-bar #changeBtn{ |
371 | 401 | padding: 0 10px; |
372 | 402 | } |
| 403 | + #changeBtn{ |
| 404 | + display: none; |
| 405 | + } |
373 | 406 | .big_img{ |
374 | 407 | pointer-events: none; |
375 | 408 | position: fixed; |
|
0 commit comments