|
| 1 | +import { |
| 2 | + domParse, |
| 3 | + onUrlChange, |
| 4 | + waitUrlChange, |
| 5 | +} from 'helper'; |
| 6 | +import { useInit } from 'main'; |
| 7 | + |
| 8 | +(async () => { |
| 9 | + const isMangaPage = () => location.pathname.match(/^\/[0-9]+--/); |
| 10 | + await waitUrlChange(isMangaPage); |
| 11 | + |
| 12 | + const { store, setState, showComic, init } = await useInit('nude-moon', { |
| 13 | + autoShow: false, |
| 14 | + defaultOption: { pageNum: 1 }, |
| 15 | + }); |
| 16 | + |
| 17 | + const original = async () => { |
| 18 | + const url = new URL(location.href); |
| 19 | + const parts = url.pathname.split('-'); |
| 20 | + parts.splice(1, 0, 'online'); |
| 21 | + url.pathname = parts.join('-'); |
| 22 | + |
| 23 | + const html = await fetch(url).then(e => e.text()); |
| 24 | + const doc = domParse(html); |
| 25 | + |
| 26 | + const script = Array.from(doc.querySelectorAll("script")) |
| 27 | + .filter(e => e.textContent.includes("/manga/"))?.[0]; |
| 28 | + if (!script) return []; |
| 29 | + |
| 30 | + return Array.from( |
| 31 | + script.textContent.matchAll(/\/manga\/[^']+/g), |
| 32 | + (e) => `https://nude-moon.org${e[0]}` |
| 33 | + ); |
| 34 | + } |
| 35 | + setState('comicMap', '', { getImgList: original }) |
| 36 | + |
| 37 | + onUrlChange(async (lastUrl) => { |
| 38 | + if (!lastUrl) return; |
| 39 | + |
| 40 | + if (!isMangaPage()) |
| 41 | + return setState((state) => { |
| 42 | + state.fab.show = false; |
| 43 | + state.manga.show = false; |
| 44 | + }); |
| 45 | + |
| 46 | + setState((state) => { |
| 47 | + state.fab.show = undefined; |
| 48 | + state.manga.show = false; |
| 49 | + }); |
| 50 | + |
| 51 | + if (store.options.autoShow) await showComic(); |
| 52 | + }); |
| 53 | + |
| 54 | + init(); |
| 55 | +})(); |
0 commit comments