()
| 20 | ?.innerText.trim() |
| 21 | |
| 22 | export default function CustomOverlay() { |
| 23 | const [summary, setSummary] = useStorage("app-summary", "") |
| 24 | |
| 25 | useEffect(() => { |
| 26 | setIcon(true) |
| 27 | }, []) |
| 28 | |
| 29 | useMessage(async (req: any, res: any) => { |
| 30 | if (req.name == "app-downloadImages") { |
| 31 | await downloadImages(req.body?.onProgress) |
| 32 | } |
| 33 | if (req.name == "app-get-summary") { |
| 34 | setSummary("") |
| 35 | const res = await getSummary(location.href) |
| 36 | if (res.code == 0) { |
| 37 | const result = JSON.parse(res.data) |
| 38 | setSummary(result) |
| 39 | } |
| 40 | } |
| 41 | if (req.name == "app-makerQRPost") { |
| 42 | makerQRPost() |
| 43 | } |
| 44 | if (req.name == "app-getArticle") { |
| 45 | const href = encodeURIComponent(location.href) |
| 46 | window.open(`https://paywallbuster.com/articles/?article=${href}`) |
| 47 | } |
| 48 | if (req.name == "app-full-page-screenshot") { |
| 49 | if (confirm(i18n("confirmScreenshot"))) { |
| 50 | const { scrollHeight, clientHeight } = document.documentElement |
| 51 | const devicePixelRatio = window.devicePixelRatio || 1 |
| 52 | |
| 53 | let capturedHeight = 0 |
| 54 | let capturedImages = [] |
| 55 | |
| 56 | const captureAndScroll = async () => { |
| 57 | const scrollAmount = clientHeight * devicePixelRatio |
| 58 | const res = await sendToBackground({ name: "screenshot" }) |
| 59 | const dataUrl = res.dataUrl |
| 60 | |
| 61 | capturedHeight += scrollAmount |
| 62 | if (capturedHeight < scrollHeight * devicePixelRatio) { |
| 63 | capturedImages.push(dataUrl) |
| 64 | window.scrollTo(0, capturedHeight) |
| 65 | setTimeout(captureAndScroll, 2000) // Adjust the delay as needed |
| 66 | } else { |
| 67 | DrawImages(capturedImages, articleTitle) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | captureAndScroll() |
| 72 | } |
| 73 | } |
| 74 | }) |
| 75 | |
| 76 | async function downloadImages( |
| 77 | onProgress?: (current: number, total: number) => void |
| 78 | ) { |
| 79 | const imageUrls = Array.from(document.images).map((img) => img.src) |
nothing calls this directly
no test coverage detected