Skip to content

Commit

Permalink
support manipurelate with keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
mkusaka committed Jul 6, 2023
1 parent e9dbb70 commit 2404ff0
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions content.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createBrowserHistory } from "history";
import Cookies from "js-cookie";
import queryString from "query-string";
import { createBrowserHistory } from "history";

const history = createBrowserHistory();

Expand All @@ -13,10 +13,10 @@ function getPropsData() {
function seekIframeInfo() {
const iframeEmbed:
| {
height: number;
width: number;
url: string;
}
height: number;
width: number;
url: string;
}
| undefined = getPropsData()?.props?.pageProps?.slideshow?.iframeEmbed;
if (!iframeEmbed) {
console.log("cannot find valid iframeEmbed");
Expand Down Expand Up @@ -90,7 +90,6 @@ function prefetchImages() {

slideImages.forEach((image) => {
const url = image.baseUrl;
console.log({url})
if (url) {
let img = new Image();
img.src = url;
Expand Down Expand Up @@ -134,6 +133,26 @@ if (container) {
}
history.replace(url.toString());
});
document.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
if (left) {
const rect = left.getBoundingClientRect();

const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;

const clickEvent = new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: true,
clientX: centerX,
clientY: centerY
});

left.dispatchEvent(clickEvent);
}
}
})
const right = document.querySelector("#right-overlay-rfs");
right?.addEventListener("click", (event) => {
proxyClickEventToSlideIFrame(event);
Expand All @@ -159,6 +178,26 @@ if (container) {
url.search = urlSearchParams;
history.replace(url.toString());
});
document.addEventListener("keydown", (event) => {
if (event.key === "ArrowRight") {
if (right) {
const rect = right.getBoundingClientRect();

const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;

const clickEvent = new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: true,
clientX: centerX,
clientY: centerY
});

right.dispatchEvent(clickEvent);
}
}
})
}
}

Expand Down

0 comments on commit 2404ff0

Please sign in to comment.