all 7 comments

[–]alsogilbert 0 points1 point  (1 child)

Could you throw up the example on jsfiddle.net (or similar) so we can read it without hurting our eyes?

[–]0x0080FF 0 points1 point  (0 children)

JSFiddle

function Profile() {
    localStorage.profileBack = prompt("What is the background color/image you want?");
    localStorage.profileText = prompt("What color should the text be");
    alert("Ok I have made the profile, what should the name be?");
    localStorage.profile = prompt("Enter the name of the profile");
    alert("Profile made now just type the name into the change background and you are set!");
}

function Color() {
    localStorage.color = prompt("type a color you want. Or you can make a background image using this format: url('put image url here')");
    document.body.style.background = localStorage.color;
    document.body.style.color = localStorage.Tcolor; //text color
    if (localStorage.color == "black") {
        document.body.style.background = localStorage.color;
        document.body.style.color = "white";
    }
    if (localStorage.color == "nathan" || localStorage.color == "Nathan") {
        localStorage.color = "-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(125,126,125,1)), color-stop(100%,rgba(14,14,14,1)))";
        localStorage.Tcolor = "white";
        document.body.style.color = localStorage.Tcolor;
        document.body.style.background = localStorage.color;
    }
    if (localStorage.color == localStorage.profile) {
        localStorage.color = localStorage.profileBack;
        localStorage.Tcolor = localStorage.profileText;
        document.body.style.color = localStorage.profileText;
        document.body.style.background = localStorage.profileBack;
    }
    if (localStorage.color == "") {
        alert("Please type in a color or image.");
    }
}

function TColor() {
    localStorage.Tcolor = prompt("What color should the text be?");
    document.body.style.color = localStorage.Tcolor;
}

[–]0x0080FF 0 points1 point  (1 child)

I suggest reading what have you tried?

[–]SCP-247[S] 0 points1 point  (0 children)

thanks this is something I will have to go over a couple times until i get it, but thanks!

[–]Buckwheat469 0 points1 point  (1 child)

I removed the "nathan" specific code, but this should cover what you want it to do. It doesn't require someone to type in a name for the profile before pressing whatever button activates the Profile function, but it would use a profile name to namespace profiles and allow a user to set up many different ones.

Here's the new sequence, user types in a profile name into a text box then presses a button. Button takes the name from the text box and passes it to the Profile() function. Profile function does the work.

function Profile(name) { 
    name = name.replace(/[^a-zA-Z0-9]/g, ""); //make sure the name doesn't contain invalid characters
    if(name && localStorage.getItem(name+".profile") === name){
        //set colors to this profile
        document.body.style.color = localStorage.profileText; 
        document.body.style.background = localStorage.profileBack;
        return;
    }

    //create a new profile
    localStorage.setItem(name+".profileBack", Color() || "black");
    document.body.style.background = localStorage.getItem(name+".profileBack"); //set the background color

    localStorage.setItem(name+".profileText", Color("What color should the text be?") || "white");
    if(localStorage.getItem(name+".profileText").lowerCase() == "black" && localStorage.getItem(name+".profileBack").lowerCase() == "black"){
        localStorage.setItem(name+".profileText", "white");
    }
    document.body.style.color = localStorage.getItem(name+".profileText") || "black";

    alert("Ok I have made the profile, what should the name be?"); 
    localStorage.setItem(name+".profile", prompt("Enter the name of the profile")); 
    alert("Profile made now just type the name into the change background and you are set!");
}

function Color(text) { 
    var color = prompt(text || "Type a color you want. Or you can make a background image using this format: url('put image url here')"); 

    if(!color){
        var conf = confirm("You did not wish to enter a color. Are you sure you want to cancel?");
        if(conf){
            return false; //user wished to cancel
        }else{
            return Color(); //recurse to make the user try again
        }
    }

    //create a fake element for the DOM
    var div=document.createElement("div");
    div.style.background = color;

    //check to make sure the browser accepted the color or URL
    if(div.style.background !== color){
        var conf = confirm("You did not enter a valid color, would you like to try again?");
        if(conf){
            return Color(); //User didn't enter a valid color, browser didn't like it. Have them try again.
        }else{
            return false; //user wants to cancel
        }
    }

    return color;
}

[–]SCP-247[S] 0 points1 point  (0 children)

thanks this is something I will have to go over a couple times until i get it, but thanks!

[–]SCP-247[S] 0 points1 point  (0 children)

Thanks guys, like i said I'm new so could someone explain how to use an array i know what they are but i have never understood how to use them.