Last active
January 24, 2022 14:53
-
-
Save azu/7665b8c39d6f6a3453bd0dca4b9cf145 to your computer and use it in GitHub Desktop.
Greamonkey Script: irodr integrate with komesan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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