Skip to content

Instantly share code, notes, and snippets.

@sgtrusty
Last active February 9, 2021 01:39
Show Gist options
  • Save sgtrusty/f068564c6a682b48e572c1cb6f91d26e to your computer and use it in GitHub Desktop.
Save sgtrusty/f068564c6a682b48e572c1cb6f91d26e to your computer and use it in GitHub Desktop.
Useful codes to use on the internet

useful codes to use on the internet

You can use these on the inspector's console, or save them as bookmarks by turning them into a oneliner and writing javascript: before the code.

optimization

  • Clear out website content in order to save RAM:
document.body.innerHTML = "";
document.head.innerHTML = "";
  • Dark mode (not efficient at the moment, sometimes breaks websites):
function dark_mode(x) {
    elements = document.getElementsByTagName(x);
    for (var i = 0; i < elements.length; i++) {
        elements[i].style.backgroundColor = "black";
        elements[i].style.color = "red";
    }
}
dark_mode("div");

forms

  • When filling out long forms, and they don't save automatically:
const form = document.getElementById("sampleForm"); // write form id here
let reqBody = {};
Object.keys(form.elements).forEach(key => {
    let element = form.elements[key];
    if (element.type !== "submit") {
        reqBody[element.name] = element.value;
    }
});
console.log(reqBody); //output will be in console

source: https://stackoverflow.com/questions/23139876/getting-all-form-values-by-javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment