Jump to content

The wiki is in the process of updating to the latest major game changes. Any contributions are appreciated!
Start here to learn how to edit and join our Discord server to make suggestions.

User:Sur/common.js: Difference between revisions

From The Deadlock Wiki
Sur (talk | contribs)
mNo edit summary
Sur (talk | contribs)
mNo edit summary
Line 15: Line 15:
}
}


// Add the button dynamically to pages (if necessary)
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMContentLoaded", function() {
     var button = document.createElement("button");
     var button = document.createElement("button");
Line 21: Line 20:
     button.onclick = storeInput;
     button.onclick = storeInput;
      
      
     // Append the button to the body or a specific element
     // Append the button to a specific element or the body
     document.body.appendChild(button);
     var buttonContainer = document.getElementById('inputButton');
    if (buttonContainer) {
        buttonContainer.appendChild(button);
    } else {
        // Fallback if the element doesn't exist, append to body
        document.body.appendChild(button);
    }
});
});

Revision as of 00:12, 23 September 2024

function storeInput() {
    // Get the user's input
    var userInput = prompt("Please enter your input:");

    // Set the #var with the user's input by embedding it back into the page
    if (userInput !== null) {
        var variableSyntax = '{{#vardefine: userInput | ' + userInput + '}}';
        
        // Update the HTML element to reflect the user's input
        document.getElementById('display').innerHTML = variableSyntax;

        // To show what is stored
        alert("Stored in #var: " + userInput);
    }
}

document.addEventListener("DOMContentLoaded", function() {
    var button = document.createElement("button");
    button.textContent = "Enter Input";
    button.onclick = storeInput;
    
    // Append the button to a specific element or the body
    var buttonContainer = document.getElementById('inputButton');
    if (buttonContainer) {
        buttonContainer.appendChild(button);
    } else {
        // Fallback if the element doesn't exist, append to body
        document.body.appendChild(button);
    }
});