Last active
July 24, 2020 14:32
-
-
Save autoxbc/badda87b6867b377a834b664d7f735d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name preLoadNextPage | |
// @author autoxbc | |
// @version 1.0 | |
// @match *://movie.douban.com/* | |
// @run-at document-start | |
// @require https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.19.1/URI.js | |
// @grant GM_addStyle | |
// ==/UserScript== | |
const fn = target => { | |
preLoadURL( target ,'.paginator .next a'); | |
const [ , , second , third ] = new URI().segment(); | |
if( second !== 'photos' || !['', undefined ].includes(third) ) | |
return; | |
const article = target.querySelector('.article'); | |
if(!article) | |
return; | |
// 缩略图直接显示为大图 | |
[ ...article.querySelectorAll('.poster-col3 .cover > a > img') ].forEach( img => { | |
const uri = new URI(img); | |
if( uri.segment(1) === 'photo' && uri.segment(3) === 'public' ) | |
img.src = uri.segment( 2 ,'raw'); | |
} ); | |
GM_addStyle(` | |
.aside , | |
#db-global-nav , | |
#db-nav-movie { | |
display: none !important; | |
} | |
#wrapper { | |
width: auto !important; | |
max-width: none !important; | |
padding: 0 30px !important; | |
background-color: #333 !important; | |
} | |
#content h1 { | |
padding: 25px 0 !important; | |
color: #949494 !important; | |
text-align: center !important; | |
} | |
.article { | |
float: none !important; | |
width: auto !important; | |
padding-right: 0 !important; | |
} | |
.poster-col3 li { | |
float: none !important; | |
width: auto !important; | |
text-align: center !important; | |
} | |
.poster-col3 .name { | |
color: #949494 !important; | |
} | |
.poster-col3 img { | |
max-height: none !important; | |
} | |
`); | |
}; | |
// 通用 DOM 突变监听 | |
addEventListener('DOMContentLoaded', ({ target }) => { | |
const callback = mttns => mttns.forEach( ({ addedNodes }) => [...addedNodes].forEach( target => fn(target) ) ); | |
new MutationObserver(callback).observe( document , { childList: true , subtree: true } ); | |
fn(target); | |
} ); | |
function preLoadURL( target , selector ) | |
{ | |
const nextPageButton = document.querySelector(selector); | |
switch(false) | |
{ | |
case !!nextPageButton : | |
case self === top : | |
case [ document , document.body ].includes(target): | |
return; | |
} | |
const iframe = Object.assign( document.createElement('iframe') , { | |
src: nextPageButton.href , | |
style: ` | |
height: 0 !important; | |
width: 0 !important; | |
visibility: hidden !important; | |
`, | |
} ); | |
nextPageButton.onclick = () => { | |
history.replaceState( null , null , iframe.src ); | |
document.body.replaceWith( iframe.contentWindow.document.body ); | |
scrollTo( 0 , 0 ); | |
return false ; | |
}; | |
document.body.append(iframe); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment