anka-213 / webcomic_reader

Webcomic Reader userscript at
https://openuserjs.org/scripts/anka-213/Webcomic_Reader
MIT License
120 stars 27 forks source link

Funmanga.com support #136

Open blindbox opened 5 years ago

blindbox commented 5 years ago

Hey guys, I've added funmanga support.

If I have the time to figure out how to add it directly into the code, and make sure it's compatible with older browers, I'll create a pull request, but for now, here's the export (path of least resistance 😄 )

    {
        url:    'funmanga.com/',
        img:    [['#chapter_img']],
        back:   function(html, pos){
                const parser = new DOMParser();

                const doc = parser.parseFromString(html, "text/html");

                const currentPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option[selected="selected"]')[0].value

                const firstPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:nth-child(2)')[0].value

                const firstLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:nth-child(2)')[0].value

                const currentChapter = parseInt(currentPageLink.split('/')[4])

                const firstChapter = parseInt(doc.querySelectorAll(".extra-buttons > select > option:last-child")[0].value.split('/')[4])

                const lastChapter = parseInt(doc.querySelectorAll(".extra-buttons > select > option:first-child")[0].value.split('/')[4])

                const currentPage = parseInt(currentPageLink.split('/')[5])

                const lastPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:last-child')[0].value

                const isFirstPage = currentPageLink === firstPageLink

                const isLastPage = currentPageLink === lastPageLink

                const nextChapter = isLastPage ? currentChapter + 1 : currentChapter

                const nextPage = isLastPage ? 1 : currentPage + 1

                const prevPage = isFirstPage ? 1 : currentPage - 1

                const isFirstChapter = firstChapter === currentChapter

                const prevChapter = isFirstPage && !isFirstChapter ? currentChapter - 1 : currentChapter

                const seriesSlug = currentPageLink.split('/')[3]

                const nextPageLink = '/' + seriesSlug + '/' + nextChapter + '/' + nextPage

                const prevPageLink = '/' + seriesSlug + '/' + prevChapter + '/' + prevPage
                return prevPageLink
                },
        next:   function(html, pos){
                const parser = new DOMParser();

                const doc = parser.parseFromString(html, "text/html");

                const currentPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option[selected="selected"]')[0].value

                const firstPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:nth-child(2)')[0].value

                const firstLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:nth-child(2)')[0].value

                const currentChapter = parseInt(currentPageLink.split('/')[4])

                const firstChapter = parseInt(doc.querySelectorAll(".extra-buttons > select > option:last-child")[0].value.split('/')[4])

                const lastChapter = parseInt(doc.querySelectorAll(".extra-buttons > select > option:first-child")[0].value.split('/')[4])

                const currentPage = parseInt(currentPageLink.split('/')[5])

                const lastPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:last-child')[0].value

                const isFirstPage = currentPageLink === firstPageLink

                const isLastPage = currentPageLink === lastPageLink

                const nextChapter = isLastPage ? currentChapter + 1 : currentChapter

                const nextPage = isLastPage ? 1 : currentPage + 1

                const prevPage = isFirstPage ? 1 : currentPage - 1

                const isFirstChapter = firstChapter === currentChapter

                const prevChapter = isFirstPage && !isFirstChapter ? currentChapter - 1 : currentChapter

                const seriesSlug = currentPageLink.split('/')[3]

                const nextPageLink = '/' + seriesSlug + '/' + nextChapter + '/' + nextPage

                const prevPageLink = '/' + seriesSlug + '/' + prevChapter + '/' + prevPage
                return nextPageLink
                },
        first:  function(html){
                const parser = new DOMParser();

                const doc = parser.parseFromString(html, "text/html");

                const currentPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option[selected="selected"]')[0].value

                const firstPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:nth-child(2)')[0].value

                const firstLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:nth-child(2)')[0].value

                const currentChapter = parseInt(currentPageLink.split('/')[4])

                const firstChapter = parseInt(doc.querySelectorAll(".extra-buttons > select > option:last-child")[0].value.split('/')[4])

                const lastChapter = parseInt(doc.querySelectorAll(".extra-buttons > select > option:first-child")[0].value.split('/')[4])

                const currentPage = parseInt(currentPageLink.split('/')[5])

                const lastPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:last-child')[0].value

                const isFirstPage = currentPageLink === firstPageLink

                const isLastPage = currentPageLink === lastPageLink

                const nextChapter = isLastPage ? currentChapter + 1 : currentChapter

                const nextPage = isLastPage ? 1 : currentPage + 1

                const prevPage = isFirstPage ? 1 : currentPage - 1

                const isFirstChapter = firstChapter === currentChapter

                const prevChapter = isFirstPage && !isFirstChapter ? currentChapter - 1 : currentChapter

                const seriesSlug = currentPageLink.split('/')[3]

                const nextPageLink = '/' + seriesSlug + '/' + nextChapter + '/' + nextPage

                const prevPageLink = '/' + seriesSlug + '/' + prevChapter + '/' + prevPage
                return firstPageLink
                },
        last:   function(html){
                const parser = new DOMParser();

                const doc = parser.parseFromString(html, "text/html");

                const currentPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option[selected="selected"]')[0].value

                const firstPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:nth-child(2)')[0].value

                const firstLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:nth-child(2)')[0].value

                const currentChapter = parseInt(currentPageLink.split('/')[4])

                const firstChapter = parseInt(doc.querySelectorAll(".extra-buttons > select > option:last-child")[0].value.split('/')[4])

                const lastChapter = parseInt(doc.querySelectorAll(".extra-buttons > select > option:first-child")[0].value.split('/')[4])

                const currentPage = parseInt(currentPageLink.split('/')[5])

                const lastPageLink = doc.querySelectorAll('.widget-heading select.hidden-xs option:last-child')[0].value

                const isFirstPage = currentPageLink === firstPageLink

                const isLastPage = currentPageLink === lastPageLink

                const nextChapter = isLastPage ? currentChapter + 1 : currentChapter

                const nextPage = isLastPage ? 1 : currentPage + 1

                const prevPage = isFirstPage ? 1 : currentPage - 1

                const isFirstChapter = firstChapter === currentChapter

                const prevChapter = isFirstPage && !isFirstChapter ? currentChapter - 1 : currentChapter

                const seriesSlug = currentPageLink.split('/')[3]

                const nextPageLink = '/' + seriesSlug + '/' + nextChapter + '/' + nextPage

                const prevPageLink = '/' + seriesSlug + '/' + prevChapter + '/' + prevPage
                return lastPageLink
                },
    }