Skip to content

Commit

Permalink
Merge pull request #8 from aviiciii/4-empty-inputs-submitting-gives-t…
Browse files Browse the repository at this point in the history
…ype-error

Empty inputs handled!
  • Loading branch information
aviiciii authored May 7, 2023
2 parents a6cf402 + 0424254 commit d555cef
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ document.getElementById("myinput").onclick = function () {
// get the link from the input
var link = document.getElementById("linkinput").value;

// check if the link is empty
if (link == "" || link == null) {
// display error message
url = document.getElementById("message").innerHTML;

document.getElementById("message").innerHTML = "Url 404 :(";

setTimeout(function () {
message.innerHTML = url;
}, 2000);
return;
}



// data to be sent to the API
var data = {
domain: "link.laavesh.ml",
Expand Down Expand Up @@ -68,31 +83,16 @@ document.getElementById("copy").onclick = function () {
navigator.clipboard.writeText(url);

// Alert copied to clipboard
message.innerHTML = "Copied!";
message.innerHTML = "Ctrl + C done :)";
console.log("Copied!");

// Change back to link after 800ms
setTimeout(function () {
message.innerHTML = url;
}, 800);
}, 1200);
}


// change github icon on hover


function hover(element) {
// get child element
var child = element.children[0];
child.setAttribute('src', 'assets/github2.png');
}

function unhover(element) {
// get child element
var child = element.children[0];
child.setAttribute('src', 'assets/github.png');
}


// on enter key press click #myinput
document.addEventListener("keyup", function(event) {
Expand All @@ -112,11 +112,24 @@ document.addEventListener("keyup", function(event) {
});


// dark mode toggle

// get the toggle
const toggle = document.getElementById('dark-mode-toggle');
// change github icon on hover
function hover(element) {
// get child element
var child = element.children[0];
child.setAttribute('src', 'assets/github2.png');
}

function unhover(element) {
// get child element
var child = element.children[0];
child.setAttribute('src', 'assets/github.png');
}



// dark mode toggle
const toggle = document.getElementById('dark-mode-toggle');

function toggleDarkMode(state) {
document.documentElement.classList.toggle("dark-mode", state);
Expand Down

0 comments on commit d555cef

Please sign in to comment.