1+ // ==UserScript==
2+ // @name 煎蛋侠
3+ // @name :en JiandanHero
4+ // @name :zh-TW 煎蛋俠
5+ // @namespace hoothin
6+ // @version 0.3
7+ // @description 为煎蛋网jandan.net提供左右方向键快捷翻页、鼠标悬停显示大图、屏蔽指定用户发言等功能
8+ // @description :en Tools for jiandan
9+ // @description :zh-TW 為煎蛋網jandan.net提供左右方向鍵快捷翻頁、鼠標懸停顯示大圖、屏蔽指定用戶發言等功能
10+ // @author hoothin
11+ // @match http*://jandan.net/*
12+ // @grant GM_setValue
13+ // @grant GM_getValue
14+ // @grant GM_deleteValue
15+ // ==/UserScript==
16+
17+ ( function ( ) {
18+ 'use strict' ;
19+ document . addEventListener ( "keydown" , function ( e ) {
20+ if ( / I N P U T | T E X T A R E A / . test ( document . activeElement . tagName ) ) return ;
21+ switch ( e . keyCode ) {
22+ case 37 ://←
23+ var next = document . querySelector ( "span#nav_next>a" ) ;
24+ if ( next ) next . click ( ) ;
25+ break ;
26+ case 39 ://→
27+ var pre = document . querySelector ( "span#nav_prev>a" ) ;
28+ if ( pre ) pre . click ( ) ;
29+ break ;
30+ }
31+ } ) ;
32+ var authors = document . querySelectorAll ( "div.author" ) , i ;
33+ for ( i = 0 ; i < authors . length ; i ++ ) {
34+ let author = authors [ i ] ;
35+ let authorId = author . querySelector ( "strong" ) . title . replace ( / 防 伪 码 : / , "" ) ;
36+ let changeBtn = document . createElement ( "a" ) ;
37+ changeBtn . href = "javascript:void(0);" ;
38+ changeBtn . id = "changeBtn" ;
39+ changeBtn . style . display = "none" ;
40+ author . insertBefore ( changeBtn , author . querySelector ( "br" ) ) ;
41+ if ( GM_getValue ( "jandanDis_" + authorId ) ) {
42+ author . nextSibling . nextSibling . style . display = "none" ;
43+ changeBtn . innerHTML = "显" ;
44+ } else {
45+ changeBtn . innerHTML = "隐" ;
46+ }
47+ author . onmouseover = function ( ) {
48+ changeBtn . style . display = "block" ;
49+ } ;
50+ author . onmouseout = function ( ) {
51+ changeBtn . style . display = "none" ;
52+ } ;
53+ changeBtn . onclick = function ( ) {
54+ var author_s , j , shown ;
55+ if ( author . nextSibling . nextSibling . style . display == "none" ) {
56+ shown = false ;
57+ GM_deleteValue ( "jandanDis_" + authorId ) ;
58+ } else {
59+ shown = true ;
60+ GM_setValue ( "jandanDis_" + authorId , true ) ;
61+ }
62+ for ( j = 0 ; j < authors . length ; j ++ ) {
63+ author_s = authors [ j ] ;
64+ if ( author_s . querySelector ( "strong" ) . title . replace ( / 防 伪 码 : / , "" ) == authorId ) {
65+ author_s . nextSibling . nextSibling . style . display = shown ?"none" :"block" ;
66+ author_s . querySelector ( "#changeBtn" ) . innerHTML = shown ?"显" :"隐" ;
67+ }
68+ }
69+ } ;
70+ }
71+ var imgs = document . querySelectorAll ( "img" ) ;
72+ var bigImg = document . createElement ( "img" ) ;
73+ bigImg . style . cssText = "pointer-events: none;position:fixed;z-index:999" ;
74+ for ( i = 0 ; i < imgs . length ; i ++ ) {
75+ let img = imgs [ i ] ;
76+ img . onmouseover = function ( e ) {
77+ bigImg . src = img . src . replace ( / \/ s \/ c u s t o m \/ / , "/s/medium/" ) . replace ( / \. s i n a i m g \. c n \/ m w 6 0 0 / , ".sinaimg.cn/large" ) ;
78+ document . body . appendChild ( bigImg ) ;
79+ } ;
80+ img . onmouseout = function ( e ) {
81+ document . body . removeChild ( bigImg ) ;
82+ bigImg . removeAttribute ( "height" ) ;
83+ } ;
84+ img . onmousemove = function ( e ) {
85+ var left = e . clientX ;
86+ var top = e . clientY ;
87+ if ( ! bigImg . src || bigImg . src === "" ) {
88+ bigImg . src = img . src . replace ( / \/ s \/ c u s t o m \/ / , "/s/medium/" ) . replace ( / \. s i n a i m g \. c n \/ m w 6 0 0 / , ".sinaimg.cn/large" ) ;
89+ document . body . appendChild ( bigImg ) ;
90+ }
91+ if ( bigImg . height > document . documentElement . clientHeight ) {
92+ bigImg . height = document . documentElement . clientHeight ;
93+ }
94+ if ( top + bigImg . height > document . documentElement . clientHeight ) {
95+ top = document . documentElement . clientHeight - bigImg . height ;
96+ }
97+ if ( left + bigImg . width > document . documentElement . clientWidth ) {
98+ left = document . documentElement . clientWidth - bigImg . width ;
99+ }
100+ bigImg . style . left = left + 10 + "px" ;
101+ bigImg . style . top = top + "px" ;
102+ } ;
103+ }
104+ } ) ( ) ;
0 commit comments