-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
33 lines (29 loc) · 1.21 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict";
// Create a request variable and assign a new XMLHttpRequest object to it.
var request = new XMLHttpRequest();
request.open("GET", "https://inspirobot.me/api?generate=true", true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
const inspiration = document.getElementById("inspiration");
inspiration.src = this.response;
inspiration.setAttribute("alt", "freshly generated inspiration");
inspiration.style.maxHeight = "500px";
const copyText = document.getElementById("imageLinkContent");
copyText.setAttribute("value", this.response);
copyText.style.width = "55%";
const copyButton = document.getElementById("copyButton");
copyButton.addEventListener("click", function() {
const copyText = document.getElementById("imageLinkContent");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
alert("Copied image link: " + copyText.value);
});
} else {
const errorMessage = document.createElement("marquee");
errorMessage.textContent = `Gah, it's not working!`;
errorMessage.style.width = "300px";
inspiroImage.appendChild(errorMessage);
}
};
request.send();