|
| 1 | +import { hotkeysMap } from 'components/Manga'; |
| 2 | +import { |
| 3 | + domParse, |
| 4 | + getKeyboardCode, |
| 5 | + linstenKeydown, |
| 6 | + querySelectorClick, |
| 7 | +} from 'helper'; |
| 8 | +import { useInit } from 'main'; |
| 9 | + |
| 10 | +(async () => { |
| 11 | + const isMangaPage = () => location.pathname.match(/^\/\d+-/) !== null; |
| 12 | + |
| 13 | + const original = async () => { |
| 14 | + const url = new URL(location.href); |
| 15 | + const parts = url.pathname.split('-'); |
| 16 | + parts.splice(1, 0, 'online'); |
| 17 | + url.pathname = parts.join('-'); |
| 18 | + |
| 19 | + const html = await fetch(url).then((e) => e.text()); |
| 20 | + const doc = domParse(html); |
| 21 | + |
| 22 | + const script = [...doc.querySelectorAll('script')].find((e) => |
| 23 | + e.textContent.includes('/manga/'), |
| 24 | + ); |
| 25 | + if (!script) return []; |
| 26 | + |
| 27 | + return Array.from( |
| 28 | + script.textContent.matchAll(/\/manga\/[^']+/g), |
| 29 | + (e) => `https://nude-moon.org${e[0]}`, |
| 30 | + ); |
| 31 | + }; |
| 32 | + |
| 33 | + const { setState } = await useInit('nude-moon', { |
| 34 | + autoShow: false, |
| 35 | + defaultOption: { pageNum: 1 }, |
| 36 | + }); |
| 37 | + |
| 38 | + setState((state) => { |
| 39 | + if (isMangaPage()) state.comicMap[''].getImgList = original; |
| 40 | + }); |
| 41 | + |
| 42 | + linstenKeydown((e) => { |
| 43 | + switch (hotkeysMap()[getKeyboardCode(e)]) { |
| 44 | + case 'scroll_right': |
| 45 | + e.preventDefault(); |
| 46 | + return querySelectorClick('a.small', 'Следующая')?.(); |
| 47 | + case 'scroll_left': |
| 48 | + e.preventDefault(); |
| 49 | + return querySelectorClick('a.small', 'Предыдущая')?.(); |
| 50 | + } |
| 51 | + }); |
| 52 | +})(); |
0 commit comments