Last active
March 23, 2024 20:41
-
-
Save ksgwxfan/ed36dd88274998bac60eaf880512978e to your computer and use it in GitHub Desktop.
Fullscreen Toolbar Shortcut for Kiwi mobile browser
This file contains 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
// "create new action" in toolbar shortcut settings | |
// give your shortcut a name and paste following code | |
// add this in the code section and make sure this option | |
// is selected to run when the shortcut key is pressed. | |
// Made by ksgwxfan (with some help from search results/how-to). | |
// Modify/use how you'd like as long as it is for personal use | |
// or with good or legal intentions. | |
// For CSS, use inline elements and use Object.assign for | |
// attribute creation. Otherwise it may not work right. | |
function hidebar() { | |
_bar.style.display = "none"; | |
} | |
function exitfullscreen() { | |
document.exitFullscreen(); | |
hidebar(); | |
} | |
function gofullscreen() { | |
document.body.requestFullscreen({"navigationUI": "hide"}) | |
.then( | |
zxcv => { | |
// these lines are to ensure scrolling is enabled as applicable | |
document.body.style.overflowY = "auto"; | |
document.body.style.overflowX = "auto"; | |
} | |
); | |
hidebar(); | |
} | |
// create the option bar element | |
if ("_bar" in window == false) { | |
// create fullscreen css rules through style element | |
let rule = document.createElement("style"); | |
// this rule is needed to prevent the web page from being blacked out | |
Object.assign(rule, {type: "text/css"}); | |
rule.innerText = "body::backdrop {background:transparent}"; | |
// give this rule to the body element | |
document.body.appendChild(rule); | |
// the element itself | |
_bar = document.createElement("div"); | |
// set css of the bar | |
Object.assign( | |
_bar, | |
{ | |
style: [ | |
"display:flex", | |
"position:fixed", | |
"top:0", | |
"left:0", | |
"background-color:white", | |
"border-top:2px solid black", | |
"border-bottom:2px solid black", | |
"width:100%", | |
"padding:2vmin", | |
"z-index:99999999", | |
].join(";"), | |
} | |
); | |
// bar button style | |
let btnstyle = document.createElement("style"); | |
Object.assign(btnstyle, {type: "text/css"}); | |
btnstyle.innerText = `button {font-size:3vmin;margin:1vmin;padding:3vmin;}`; | |
_bar.appendChild(btnstyle); | |
// *********** Add Button Elements Here *********** | |
// Create Close Button | |
let closebtn = document.createElement("button"); | |
Object.assign(closebtn, {id: "closebar"}); | |
closebtn.onclick = hidebar; | |
closebtn.innerText = "X"; | |
// add close button to bar | |
_bar.appendChild(closebtn); | |
// Fullscreen button | |
let fullbtn = document.createElement("button"); | |
Object.assign(fullbtn, {id: "gofull", onclick: gofullscreen}); | |
fullbtn.innerText = "Go Fullscreen"; | |
// add full screen button to the bar | |
_bar.appendChild(fullbtn); | |
// ************************************************ | |
// add option bar to body | |
document.body.appendChild(_bar); | |
} | |
// since bar has already been created, just reveal it | |
else { | |
// Display bar if it exists | |
_bar.style.display = "block"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment