File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// ==UserScript==
22// @name Bilibili Bangumi Cover
3- // @name :zh-CN 哔哩哔哩(bilibili.com)番剧封面
3+ // @name :zh-CN 哔哩哔哩番剧封面
44// @namespace hoothin
5- // @version 0.5
5+ // @version 0.6
66// @description Show Bilibili Bangumi Cover
77// @description :zh-CN 在哔哩哔哩番剧页面中显示封面
88// @grant GM_xmlhttpRequest
3939 function refreshCover ( ) {
4040 GM_xmlhttpRequest ( {
4141 method : 'GET' ,
42- url : bangumiIndex . href ,
42+ url : "http://bangumi.bilibili.com/web_api/episode/" + location . hash . slice ( 1 ) + ".json" ,
4343 onload : function ( result ) {
44- var doc = null ;
4544 try {
46- doc = document . implementation . createHTMLDocument ( '' ) ;
47- doc . documentElement . innerHTML = result . responseText ;
48- }
49- catch ( e ) {
45+ var bangumiData = JSON . parse ( result . responseText ) ;
46+ coverLink . href = cover . src = bangumiData . result . currentEpisode . cover ;
47+ } catch ( e ) {
5048 console . log ( e ) ;
5149 }
52- if ( ! doc ) {
53- return ;
54- }
55- var img = doc . querySelector ( "a.v1-complete-text[href='" + location . href . replace ( / h t t p s ? : / , "" ) + "']>div>img" ) ;
56- if ( img ) {
57- coverLink . href = cover . src = img . getAttribute ( "src" ) . replace ( / \d + _ \d + | _ \d + x \d + \. j p g / , "" ) ;
58- }
5950 }
6051 } ) ;
6152 }
62- var bangumiIndex = document . querySelector ( ".v1-bangumi-info-title>a" ) ;
63- if ( bangumiIndex ) {
64- refreshCover ( ) ;
65- }
6653} ) ( ) ;
You can’t perform that action at this time.
0 commit comments