22// @name Bilibili Bangumi Cover
33// @name :zh-CN 哔哩哔哩番剧封面
44// @namespace hoothin
5- // @version 0.1
5+ // @version 0.2
66// @description Show Bilibili Bangumi Cover
77// @description :zh-CN 在哔哩哔哩番剧页面中显示封面
88// @grant GM_xmlhttpRequest
99// @author hoothin
10- // @include http*://bangumi.bilibili.com/anime/v/ *
10+ // @include http*://bangumi.bilibili.com/anime/*
1111// ==/UserScript==
1212
1313( function ( ) {
1414 'use strict' ;
15- var vSmall = document . querySelector ( ".v_small" ) ;
15+ var vSmall = document . querySelector ( ".recom" ) ;
16+ if ( ! vSmall ) return ;
1617 var title = document . createElement ( "h3" ) ;
18+ title . id = "coverTitle" ;
1719 title . classList . add ( "v1-bangumi-head-h3" ) ;
1820 title . style . display = "block" ;
1921 title . innerHTML = "封面" ;
2224 cover . style . width = "270px" ;
2325 coverLink . target = "_blank" ;
2426 coverLink . appendChild ( cover ) ;
25- vSmall . insertBefore ( coverLink , vSmall . firstChild ) ;
26- vSmall . insertBefore ( title , vSmall . firstChild ) ;
27- var bangumiIndex = document . querySelector ( ".v1-bangumi-info-title>a" ) ;
28- if ( bangumiIndex ) {
27+ var MutationObserver = window . MutationObserver || window . WebKitMutationObserver || window . MozMutationObserver ;
28+ var observer = new MutationObserver ( function ( records ) {
29+ if ( vSmall . childNodes . length > 0 && ! vSmall . querySelector ( "h3#coverTitle" ) ) {
30+ vSmall . insertBefore ( coverLink , vSmall . firstChild ) ;
31+ vSmall . insertBefore ( title , vSmall . firstChild ) ;
32+ refreshCover ( ) ;
33+ }
34+ } ) ;
35+ var option = {
36+ 'childList' : true
37+ } ;
38+ observer . observe ( vSmall , option ) ;
39+ function refreshCover ( ) {
2940 GM_xmlhttpRequest ( {
3041 method : 'GET' ,
3142 url : bangumiIndex . href ,
4859 }
4960 } ) ;
5061 }
62+ var bangumiIndex = document . querySelector ( ".v1-bangumi-info-title>a" ) ;
63+ if ( bangumiIndex ) {
64+ refreshCover ( ) ;
65+ }
5166} ) ( ) ;
0 commit comments