Skip to content

Instantly share code, notes, and snippets.

@azu
Last active January 24, 2022 14:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azu/7665b8c39d6f6a3453bd0dca4b9cf145 to your computer and use it in GitHub Desktop.
Save azu/7665b8c39d6f6a3453bd0dca4b9cf145 to your computer and use it in GitHub Desktop.
Greamonkey Script: irodr integrate with komesan
// ==UserScript==
// @name irodr: komesan
// @namespace github.com/azu
// @match https://irodr.netlify.app/
// @grant none
// @version 1.0
// @author azu
// @description irodr integrate
// @run-at document-end
// ==/UserScript==
const FRAME_ID = "__KOMESAN__FRAME__";
const createFrame = (url) => {
const frame = document.createElement("iframe");
frame.id = FRAME_ID;
frame.dataset.url = url;
frame.style = "position: fixed; bottom: 0; right: 0; width: 320px; height: 480px; z-index: 2147483647";
frame.src = `https://komesan.pages.dev/?url=${encodeURIComponent(url)}&min`;
document.body.append(frame);
};
const removeFrame = () => {
document.querySelector(`#${FRAME_ID}`)?.remove();
};
const toggleFrame = (url) => {
const frame = document.querySelector(`#${FRAME_ID}`);
if(!frame){
return createFrame(url);
}
const currentUrl = frame.dataset.url;
console.log(currentUrl, url)
if (currentUrl === url){
removeFrame();
} else {
removeFrame();
createFrame(url);
}
}
window.addEventListener("keydown", (event) => {
if(event.key == ";") {
const currentUrl = window.userScript?.getActiveContent()?.url
if (currentUrl) {
toggleFrame(currentUrl);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment