From b3a781b34e6f9bf9025b38f165ad18cb18dc5bad Mon Sep 17 00:00:00 2001 From: mkusaka Date: Sat, 28 Oct 2023 01:48:34 +0900 Subject: [PATCH] drop support slide={number} feature and remove whole ads from sites --- .gitignore | 2 + README.md | 5 +- content.ts | 202 -------------------------------------------------- manifest.json | 8 +- package.json | 1 - rules.json | 11 +++ yarn.lock | 19 ----- 7 files changed, 21 insertions(+), 227 deletions(-) create mode 100644 rules.json diff --git a/.gitignore b/.gitignore index e526aff..86ab6d5 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,5 @@ dist .tern-port content.js + +_metadata diff --git a/README.md b/README.md index 02d3fed..c62fb87 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,7 @@ Chrome extension which provides a better slideshare experience ## features -- remove ad in slide -- hide special offer modal -- add `slide={pageNumber}` format suffix & if you reload this page, current page will be shown again. -- prefetch images +- remove ad in whole site # chrome store diff --git a/content.ts b/content.ts index 929cbb1..c6700d5 100644 --- a/content.ts +++ b/content.ts @@ -1,206 +1,4 @@ -import { createBrowserHistory } from "history"; import Cookies from "js-cookie"; -const history = createBrowserHistory(); - -function getPropsData() { - const propsElement = document.getElementById("__NEXT_DATA__"); - const propsJSON = JSON.parse(propsElement.innerHTML); - return propsJSON; -} - -function seekIframeInfo() { - const iframeEmbed: - | { - height: number; - width: number; - url: string; - } - | undefined = getPropsData()?.props?.pageProps?.slideshow?.iframeEmbed; - if (!iframeEmbed) { - console.log("cannot find valid iframeEmbed"); - return null; - } - - return iframeEmbed; -} - -function parseSlideParam() { - const { search } = history.location; - const slide = new URLSearchParams(search).get("slide"); - if (typeof slide === "string") { - return parseInt(slide, 10); - } - return null; -} - -function generateURL(url: string, slide: number) { - const parsedURL = new URL(url); - parsedURL.searchParams.set("startSlide", slide); - return parsedURL.toString(); -} - -function proxyClickEventToSlideIFrame(event: Event) { - const iframe = document.querySelector("#iframe-rfs"); - const rect = iframe.getBoundingClientRect(); - const x = event.clientX - rect.left; - const y = event.clientY - rect.top; - - // Access to elements in iframe - const iframeDocument = - iframe.contentDocument || iframe.contentWindow.document; - const clickedElement = iframeDocument.elementFromPoint(x, y); - if (clickedElement) { - // Simulate click event - clickedElement.dispatchEvent( - new MouseEvent("click", { - bubbles: true, - cancelable: true, - view: iframe.contentWindow, - }), - ); - } -} - -function getSlideNumber() { - // parse slide params - const urlSearchParams = new URLSearchParams(window.location.search); - const slideNumber = urlSearchParams.get("slide"); - if (slideNumber) { - return parseInt(slideNumber, 10); - } - return null; -} - -function setSlideSearchParams(slideNumber: number, withDelete = false) { - // parse slide params - const urlSearchParams = new URLSearchParams(window.location.search); - if (withDelete) { - urlSearchParams.delete("slide"); - } else { - urlSearchParams.set("slide", slideNumber); - } - return urlSearchParams; -} - -function prefetchImages() { - const slideImages = - getPropsData()?.props?.pageProps?.slideshow?.slideImages || []; - - const fragment = document.createDocumentFragment(); - for (let i = 0; i < slideImages.length; i++) { - const link = document.createElement("link"); - link.rel = "prefetch"; - link.href = slideImages[i].webpSrcset.split(",").map(it => it.trim().split(" ")[0]).at(-1); - fragment.appendChild(link); - } - - document.head.appendChild(fragment); -} - -const container = document.getElementById("new-player"); -if (container) { - const iframeInfo = seekIframeInfo(); - if (iframeInfo) { - const { url } = iframeInfo; - const slide = parseSlideParam(); - const newURL = slide ? generateURL(url, slide) : url; - const { width, height } = container.getBoundingClientRect(); - container.innerHTML = ` -
- -
-