Last active
May 9, 2022 15:43
-
-
Save andersonbosa/98c96867c2bdbf77ac0bdd25fd21c802 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 mangalivre.net upgrader | |
// @namespace Violentmonkey Scripts | |
// @match https://mangalivre.net/ler/* | |
// @author github.com/andersonbosa | |
// @gist https://gist.github.com/andersonbosa/98c96867c2bdbf77ac0bdd25fd21c802 | |
// ==/UserScript== | |
function nextChapter () { | |
window.document | |
.querySelector( | |
'#reader-wrapper > div.reader-navigation.clear-fix > div.chapter-selection-container > div.chapter-next' | |
) | |
.click() | |
window.alert('loading next chpater...') | |
window.autoScrollController.scrollStep = 0 | |
} | |
function previousChapter () { | |
window.document.querySelector( | |
'#reader-wrapper > div.reader-navigation.clear-fix > div.chapter-selection-container > div.chapter-previous' | |
).click | |
} | |
function bindShortcut () { | |
window.document.addEventListener('keydown', (evt) => { | |
if (!evt.shiftKey) { | |
return | |
} | |
if (evt.key === 'ArrowRight') { | |
nextChapter() | |
} else if (evt.key === 'ArrowLeft') { | |
previousChapter() | |
} | |
}) | |
} | |
function hiddenElement (htmlEl) { | |
htmlEl.style.display = 'none' | |
} | |
function hiddenAds () { | |
Array.from(document.querySelectorAll('.manga-vignette')).map(hiddenElement) | |
} | |
function userConfirm () { | |
const anwser = window.prompt('Go to next chapter? [OK/ESC] [y/n]', 'y') | |
if (!anwser || anwser !== 'y') return | |
return true | |
} | |
function bindAutoNextChapter () { | |
const observer = new IntersectionObserver( | |
(entries, observer) => { | |
entries.forEach((entry) => { | |
if (!entry.isIntersecting) return | |
if (window.bindAutoNextChapterFirstTrigger) { | |
window.bindAutoNextChapterFirstTrigger = false | |
return | |
} | |
nextChapter() | |
}) | |
}, | |
{ | |
rootMargin: '0px', | |
threshold: 1, | |
} | |
) | |
const sel = | |
'#reader-wrapper > div.comments-wrapper > div.content-wrapper > div > div > h2' // caixa de comentário depois do botão "próximo capítulo" | |
observer.observe(document.querySelector(sel)) | |
window.bindAutoNextChapterFirstTrigger = true | |
} | |
function scrollPage (y) { | |
window.document.body.scrollTo(0, window.document.body.scrollTop + y) | |
} | |
window.autoScrollController = { | |
status: false, | |
autoScrollFuncInterval: 15, | |
scrollStep: 15, | |
bindShortcutListener () { | |
window.document.addEventListener('keydown', (evt) => { | |
if (evt.code === 'Space') { | |
window.autoScrollController.status = !window.autoScrollController.status | |
} | |
}) | |
}, | |
toggleAutoScroll () { | |
setInterval(() => { | |
if (window.autoScrollController.status) { | |
scrollPage(window.autoScrollController.scrollStep) | |
} | |
}, this.autoScrollFuncInterval) | |
}, | |
} | |
function init () { | |
bindShortcut() | |
bindAutoNextChapter() | |
hiddenAds() | |
window.autoScrollController.bindShortcutListener() | |
window.autoScrollController.toggleAutoScroll() | |
} | |
setTimeout(init, 2500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment