Skip to content

Commit

Permalink
Enable custom entires (Beta 1.0 release)
Browse files Browse the repository at this point in the history
  • Loading branch information
downthecrop committed Apr 1, 2021
1 parent f309cb2 commit fb1f6ce
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
66 changes: 38 additions & 28 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ function openlink(caller) {
async function getFavicon(url, callback) {
let f = new FileReader()
f.readAsDataURL(await fetch(url).then(r => r.blob()))
f.onloadend = function(){
callback(f.result)
}
f.onloadend = function () { callback(f.result) }
}

function configureTiles(sites) {
function configureTiles(sites) {
for (let i = 0; i < 8; i += 1) {
let data = JSON.parse(localStorage.getItem("site-" + i))
if (data == null || data.url != sites[i].url) {
if ((data == null || data.url != sites[i].url) && !JSON.parse(localStorage.getItem("enable-custom"))) {
setLocalStorage(sites[i], i)
}
else {
Expand Down Expand Up @@ -66,43 +64,55 @@ function setInactive(e) {
e.setAttribute("class", "")
}

function updateStorage(i) {
let title = document.getElementById("edit-title-" + i)
let url = document.getElementById("edit-link-" + i)
let site = JSON.parse(localStorage.getItem("site-" + i))
site.title = title.value
site.url = url.value
setLocalStorage(site, i)
}

function settingsGUI() {
//settings modal
let modal = document.getElementById("myModal");
let btn = document.getElementById("settings-menu");
let span = document.getElementsByClassName("close")[0];
//Modal
let modal = document.getElementById("myModal")
let openbtn = document.getElementById("settings-menu")
let closebtn = document.getElementsByClassName("close")[0]

btn.onclick = function () {
openbtn.onclick = function () {
modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function () {
closebtn.onclick = function () {
modal.style.display = "none";
}

window.onclick = function (event) {
if (event.target == modal) {
if (event.target == modal)
modal.style.display = "none";
}
}

//Title & URL GUI
for (let i = 0; i < 8; i += 1) {
let j = JSON.parse(localStorage.getItem("site-" + i))
let title = document.getElementById("edit-title-" + i)
let url = document.getElementById("edit-link-" + i)

title.value = j.title
url.value = j.url

title.addEventListener('input', function () { updateStorage(i) })
url.addEventListener('input', function () { updateStorage(i) })
}

//Custom URLs and Titles
document.getElementById("enable-custom").checked = JSON.parse(localStorage.getItem("enable-custom"));
document.getElementById("enable-custom").addEventListener("click", function () {
document.getElementById("enable-custom").onclick = function () {
localStorage.setItem("enable-custom", document.getElementById("enable-custom").checked);
})
}

document.getElementById("clear-storage").addEventListener("click", function () {
document.getElementById("clear-storage").onclick = function () {
localStorage.clear()
window.location.reload()
});

for (let i = 0; i < 8; i += 1) {
let j = JSON.parse(localStorage.getItem("site-"+i))
document.getElementById("edit-title-" + i).value = j.title
document.getElementById("edit-link-" + i).value = j.url
}
};
}

function submitSearch(query) {
Expand All @@ -117,8 +127,8 @@ function submitSearch(query) {
document.addEventListener('DOMContentLoaded', function () {

let lastsearch = ""
let ginput = document.getElementById('ginput');
let results = document.getElementById('results');
let ginput = document.getElementById('ginput')
let results = document.getElementById('results')
let arrows = false

//Keyboard Events for Suggestions
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
.modal {
display: none;
position: fixed;
z-index: 1;
z-index: 100;
left: 0;
top: 0;
width: 100%;
Expand Down

0 comments on commit fb1f6ce

Please sign in to comment.