|
| 1 | +const iframe = document.getElementById("iframe-container") |
| 2 | + |
| 3 | +if (navigator.userAgent.includes("Chrome")) { |
| 4 | + window.addEventListener("resize", function () { |
| 5 | + navigator.keyboard.lock(["Escape"]) |
| 6 | + }) |
| 7 | +} |
| 8 | + |
| 9 | +// Decode URL |
| 10 | +function decodeXor(input) { |
| 11 | + if (!input) return input |
| 12 | + let [str, ...search] = input.split("?") |
| 13 | + |
| 14 | + return ( |
| 15 | + decodeURIComponent(str) |
| 16 | + .split("") |
| 17 | + .map((char, ind) => (ind % 2 ? String.fromCharCode(char.charCodeAt(NaN) ^ 2) : char)) |
| 18 | + .join("") + (search.length ? "?" + search.join("?") : "") |
| 19 | + ) |
| 20 | +} |
| 21 | + |
| 22 | +// Button Variables |
| 23 | +const iframeContainer = document.getElementById("iframe-container") |
| 24 | +const iframes = Array.from(iframeContainer.querySelectorAll("iframe")) |
| 25 | +const activeIframe = document.querySelector("#iframe-container iframe.active") |
| 26 | + |
| 27 | +function Load() { |
| 28 | + const activeIframe = document.querySelector("#iframe-container iframe.active") |
| 29 | + if (activeIframe && document.readyState === "complete") { |
| 30 | + const website = activeIframe.contentWindow.document.location.href |
| 31 | + |
| 32 | + if (website.includes("/a/")) { |
| 33 | + const websitePath = website.replace(window.location.origin, "").replace("/a/", "") |
| 34 | + const decodedValue = decodeXor(websitePath) |
| 35 | + document.getElementById("is").value = decodedValue |
| 36 | + localStorage.setItem("decoded", decodedValue) |
| 37 | + } else if (website.includes("/a/q/")) { |
| 38 | + const websitePath = website.replace(window.location.origin, "").replace("/a/q/", "") |
| 39 | + const decodedValue = decodeXor(websitePath) |
| 40 | + document.getElementById("is").value = decodedValue |
| 41 | + localStorage.setItem("decoded", decodedValue) |
| 42 | + } else { |
| 43 | + const websitePath = website.replace(window.location.origin, "") |
| 44 | + document.getElementById("is").value = websitePath |
| 45 | + localStorage.setItem("decoded", websitePath) |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +function OnLoad() { |
| 51 | + if (window.loaded) { |
| 52 | + console.log("OnLoad() function already executed. Exiting.") |
| 53 | + return |
| 54 | + } |
| 55 | + window.loaded = true |
| 56 | + |
| 57 | + let GoUrl = sessionStorage.getItem("GoUrl") |
| 58 | + let dyValue = localStorage.getItem("dy") |
| 59 | + |
| 60 | + if (!GoUrl) { |
| 61 | + return |
| 62 | + } |
| 63 | + |
| 64 | + if (!GoUrl.startsWith("/e/")) { |
| 65 | + if (dyValue === "true" || dyValue === "auto") { |
| 66 | + GoUrl = "/a/q/" + GoUrl |
| 67 | + } else { |
| 68 | + GoUrl = "/a/" + GoUrl |
| 69 | + } |
| 70 | + } else { |
| 71 | + } |
| 72 | + console.log(GoUrl) |
| 73 | + |
| 74 | + const activeIframe = document.querySelector("#iframe-container iframe.active") |
| 75 | + if (!activeIframe) { |
| 76 | + return |
| 77 | + } |
| 78 | + |
| 79 | + activeIframe.removeAttribute("onload") |
| 80 | + |
| 81 | + activeIframe.contentWindow.document.location.href = GoUrl |
| 82 | + setTimeout(Load, 1500) |
| 83 | +} |
| 84 | + |
| 85 | +// Reload |
| 86 | +function reload() { |
| 87 | + const activeIframe = document.querySelector("#iframe-container iframe.active") |
| 88 | + if (activeIframe) { |
| 89 | + activeIframe.src = activeIframe.src |
| 90 | + Load() |
| 91 | + } else { |
| 92 | + console.error("No active iframe found") |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +// Popout |
| 97 | +function popout() { |
| 98 | + const activeIframe = document.querySelector("#iframe-container iframe.active") |
| 99 | + |
| 100 | + if (activeIframe) { |
| 101 | + const newWindow = window.open("about:blank", "_blank") |
| 102 | + |
| 103 | + if (newWindow) { |
| 104 | + const name = localStorage.getItem("name") || "My Drive - Google Drive" |
| 105 | + const icon = localStorage.getItem("icon") || "https://ssl.gstatic.com/docs/doclist/images/drive_2022q3_32dp.png" |
| 106 | + |
| 107 | + newWindow.document.title = name |
| 108 | + |
| 109 | + const link = newWindow.document.createElement("link") |
| 110 | + link.rel = "icon" |
| 111 | + link.href = encodeURI(icon) |
| 112 | + newWindow.document.head.appendChild(link) |
| 113 | + |
| 114 | + const newIframe = newWindow.document.createElement("iframe") |
| 115 | + const style = newIframe.style |
| 116 | + style.position = "fixed" |
| 117 | + style.top = style.bottom = style.left = style.right = 0 |
| 118 | + style.border = style.outline = "none" |
| 119 | + style.width = style.height = "100%" |
| 120 | + |
| 121 | + newIframe.src = activeIframe.src |
| 122 | + |
| 123 | + newWindow.document.body.appendChild(newIframe) |
| 124 | + } |
| 125 | + } else { |
| 126 | + console.error("No active iframe found") |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +function erudaToggle() { |
| 131 | + const activeIframe = document.querySelector("#iframe-container iframe.active") |
| 132 | + if (!activeIframe) { |
| 133 | + console.error("No active iframe found") |
| 134 | + return |
| 135 | + } |
| 136 | + |
| 137 | + const erudaWindow = activeIframe.contentWindow |
| 138 | + if (!erudaWindow) { |
| 139 | + console.error("No content window found for the active iframe") |
| 140 | + return |
| 141 | + } |
| 142 | + |
| 143 | + if (erudaWindow.eruda) { |
| 144 | + if (erudaWindow.eruda._isInit) { |
| 145 | + erudaWindow.eruda.destroy() |
| 146 | + } else { |
| 147 | + console.error("Eruda is not initialized in the active iframe") |
| 148 | + } |
| 149 | + } else { |
| 150 | + const erudaDocument = activeIframe.contentDocument |
| 151 | + if (!erudaDocument) { |
| 152 | + console.error("No content document found for the active iframe") |
| 153 | + return |
| 154 | + } |
| 155 | + |
| 156 | + const script = erudaDocument.createElement("script") |
| 157 | + script.src = "https://cdn.jsdelivr.net/npm/eruda" |
| 158 | + script.onload = function () { |
| 159 | + if (!erudaWindow.eruda) { |
| 160 | + console.error("Failed to load Eruda in the active iframe") |
| 161 | + return |
| 162 | + } |
| 163 | + erudaWindow.eruda.init() |
| 164 | + erudaWindow.eruda.show() |
| 165 | + } |
| 166 | + erudaDocument.head.appendChild(script) |
| 167 | + } |
| 168 | +} |
| 169 | + |
| 170 | +// Fullscreen |
| 171 | +function FS() { |
| 172 | + const activeIframe = document.querySelector("#iframe-container iframe.active") |
| 173 | + if (activeIframe) { |
| 174 | + if (!activeIframe.contentDocument.fullscreenElement) { |
| 175 | + activeIframe.contentDocument.documentElement.requestFullscreen() |
| 176 | + } else { |
| 177 | + activeIframe.contentDocument.exitFullscreen() |
| 178 | + } |
| 179 | + } else { |
| 180 | + console.error("No active iframe found") |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +const fullscreenButton = document.getElementById("fullscreen-button") |
| 185 | +fullscreenButton.addEventListener("click", FS) |
| 186 | + |
| 187 | +// Home |
| 188 | +function Home() { |
| 189 | + window.location.href = "./" |
| 190 | +} |
| 191 | + |
| 192 | +const homeButton = document.getElementById("home-page") |
| 193 | +homeButton.addEventListener("click", Home) |
| 194 | + |
| 195 | +// Back |
| 196 | +function goBack() { |
| 197 | + const activeIframe = document.querySelector("#iframe-container iframe.active") |
| 198 | + if (activeIframe) { |
| 199 | + activeIframe.contentWindow.history.back() |
| 200 | + iframe.src = activeIframe.src |
| 201 | + Load() |
| 202 | + } else { |
| 203 | + console.error("No active iframe found") |
| 204 | + } |
| 205 | +} |
| 206 | + |
| 207 | +// Forward |
| 208 | +function goForward() { |
| 209 | + const activeIframe = document.querySelector("#iframe-container iframe.active") |
| 210 | + if (activeIframe) { |
| 211 | + activeIframe.contentWindow.history.forward() |
| 212 | + iframe.src = activeIframe.src |
| 213 | + Load() |
| 214 | + } else { |
| 215 | + console.error("No active iframe found") |
| 216 | + } |
| 217 | +} |
| 218 | + |
| 219 | +// Remove Nav |
| 220 | +document.addEventListener("fullscreenchange", function () { |
| 221 | + const isFullscreen = Boolean(document.fullscreenElement) |
| 222 | + document.body.classList.toggle("fullscreen", isFullscreen) |
| 223 | +}) |
0 commit comments