Skip to content

Commit

Permalink
Code clean up and some extra shit
Browse files Browse the repository at this point in the history
Fuck it, double release in less than an hour (I'm amazing at maintaining this)
  • Loading branch information
kckarnige committed Feb 1, 2024
1 parent ed408b3 commit 6f7fc92
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion manifest.crx.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Ecsta",
"short_name": "Ecsta",
"version": "0.3.5",
"version": "0.3.6",

"description": "A simple new tab extension meant to stay out of your way while still making for great eye-candy.",

Expand Down
2 changes: 1 addition & 1 deletion manifest.xpi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Ecsta",
"short_name": "Ecsta",
"version": "0.3.5",
"version": "0.3.6",

"description": "A simple new tab extension meant to stay out of your way while still making for great eye-candy.",

Expand Down
32 changes: 18 additions & 14 deletions src/res/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,47 @@ window.onload = () => {
document.getElementById("setKeyBox").value = localStorage.getItem("unsplashApiKey");
};


//Save Query
document.getElementById("saveSettings").addEventListener("click", () => {
localStorage.setItem("unsplashApiQuery", "&query=" + document.getElementById("setQueryBox").value);
localStorage.removeItem("lastFetch");
localStorage.removeItem("lastFetchDate");
parent.location.reload();
})
//Save Key
document.getElementById("saveKey").addEventListener("click", () => {
if (document.getElementById("setKeyBox").value.length == 43) {
localStorage.setItem("unsplashApiKey", document.getElementById("setKeyBox").value);
alert(`Successfully set!`);
parent.location.reload();
} else {
alert(`Must be a 43 character Unsplash access key.`);
}
})

//Reset Query
document.getElementById("resetQuery").addEventListener("click", () => {
localStorage.setItem("unsplashApiQuery", "");
localStorage.removeItem("lastFetch");
localStorage.removeItem("lastFetchDate");
document.getElementById("setQueryBox").value = "";
parent.location.reload();
})
//Hard Reset
document.getElementById("hardReset").addEventListener("click", () => {
if (confirm("Only use this as a last resort, try hitting the reload button first!" + `
` +"Are you sure you wanna do this?")) {
` + "Are you sure you wanna do this?")) {
localStorage.removeItem("unsplashApiQuery");
localStorage.removeItem("lastFetch");
localStorage.removeItem("lastFetchDate");
localStorage.removeItem("unsplashApiKey");
parent.location.reload();
}
})
document.getElementById("saveKey").addEventListener("click", () => {
if (document.getElementById("setKeyBox").value.length == 43) {
localStorage.setItem(
"unsplashApiKey",
document.getElementById("setKeyBox").value
);
alert(`Successfully set!`);
parent.location.reload();
} else {
alert(`Must be a 43 character Unsplash access key.`);
}
})

//Close Panel
document.getElementsByClassName("settings")[0].addEventListener("click", () => {
parent.document.getElementById("settingsPanelContainer").style.display = "none"
parent.document.getElementsByClassName("options")[0].style.display = "block";
setTimeout(() => { parent.silly = false }, 10)
})
45 changes: 22 additions & 23 deletions src/res/js/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const getLastFetch = localStorage.getItem("lastFetch");
const getLastFetch = localStorage.getItem("lastFetch") / 60000;
const getLastFetchDate = localStorage.getItem("lastFetchDate");
const UNSPLASH_API_KEY = localStorage.getItem("unsplashApiKey");
var currentDate = new Date().toISOString().split("T")[0];

if (UNSPLASH_API_KEY) {
//Background code
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.getElementById("tabIcon").setAttribute("href","res/icons/white-256.png")
} else {
document.getElementById("tabIcon").setAttribute("href","res/icons/black-256.png")
}
//Tab Icon
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.getElementById("tabIcon").setAttribute("href", "res/icons/white-256.png")
} else {
document.getElementById("tabIcon").setAttribute("href", "res/icons/black-256.png")
}
//Background Code
function set(fetched) {
localStorage.setItem("fetchedBgImg", fetched.urls.small + "");
localStorage.setItem("unsplashApiCreditName", fetched.user.name + "");
Expand All @@ -26,10 +27,7 @@ if (UNSPLASH_API_KEY) {
}
function getAndSet() {
localStorage.setItem("lastFetch", Date.now());
localStorage.setItem(
"lastFetchDate",
new Date().toISOString().split("T")[0]
);
localStorage.setItem("lastFetchDate", new Date().toISOString().split("T")[0]);
if (document.getElementById("root")) {
fetch(
`https://api.unsplash.com/photos/random/?orientation=landscape${localStorage.getItem("unsplashApiQuery")}`,
Expand Down Expand Up @@ -59,22 +57,15 @@ if (UNSPLASH_API_KEY) {
}

if (getLastFetch && getLastFetchDate) {
if (
getLastFetch / 60000 >= Date.now() / 60000 - 3 ||
getLastFetchDate != currentDate ||
localStorage.getItem("fetchedBgImg") == undefined
) {
if (getLastFetch >= Date.now() / 60000 - 3 || getLastFetchDate != currentDate || localStorage.getItem("fetchedBgImg") == undefined) {
window.onload = () => {
document.getElementById("background").style.backgroundImage = `url(${localStorage.getItem("fetchedBgImg")})`;
if (document.getElementById("imgCreator")) {
document.getElementById("imgCreator").innerText = ("Image by " + localStorage.getItem("unsplashApiCreditName"));
document.getElementById("imgCreator").setAttribute("href", localStorage.getItem("unsplashApiCreditLink"));
}
console.log(
`Hasn't been 3 minutes (Has only been ${(
Date.now() / 60000 -
getLastFetch / 60000
).toFixed(1)}), nor has a full day passed (failsafe solution)`
`Hasn't been 3 minutes (Has only been ${(Date.now() / 60000 - getLastFetch).toFixed(1)}), nor has a full day passed (failsafe solution)`
);
console.log("Using stored image");
console.log(localStorage.getItem("lastFetch"));
Expand All @@ -96,9 +87,7 @@ if (UNSPLASH_API_KEY) {
timeStyle: "short",
hour12: true,
});
document.getElementById("time-sec").textContent = (
"0" + d.getSeconds()
).slice(-2);
document.getElementById("time-sec").textContent = ("0" + d.getSeconds()).slice(-2);
}
time();
setInterval(time, 1000);
Expand All @@ -117,7 +106,17 @@ if (document.getElementsByClassName("reload")[0]) {
});
}

//Settings Panel
var silly = false;
document.getElementsByClassName("settings")[0].addEventListener("click", () => {
document.getElementById("settingsPanelContainer").style.display = "block"
document.getElementsByClassName("options")[0].style.display = "none";
setTimeout(() => { silly = true }, 10)
})
document.getElementById("root").addEventListener("click", () => {
if (silly == true) {
document.getElementById("settingsPanelContainer").style.display = "none"
document.getElementsByClassName("options")[0].style.display = "block";
setTimeout(() => { silly = false }, 10)
}
})

0 comments on commit 6f7fc92

Please sign in to comment.