-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
categorize history and bookmarks by date
- Loading branch information
Showing
7 changed files
with
257 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,80 @@ | ||
import { categorizeByDate } from "./utils/categorize.js"; | ||
|
||
window.addEventListener("DOMContentLoaded", function () { | ||
var bookmarks = document.createElement("div"); | ||
let bookmarks = document.createElement("div"); | ||
bookmarks.id = "bookmarks"; | ||
var marks = document.createElement("ul"); | ||
marks.className = "marks"; | ||
JSON.parse(localStorage.getItem("bookmarks") || "[]") | ||
.reverse() | ||
.forEach(function ({ url, id }) { | ||
var li = document.createElement("li"); | ||
var a = document.createElement("a"); | ||
a.href = url; | ||
a.textContent = url; | ||
a.target = "_blank"; | ||
var button = document.createElement("button"); | ||
button.innerHTML = "<i class='fa fa-times'></i>"; | ||
button.addEventListener("click", function () { | ||
const sHistory = JSON.parse(localStorage.getItem("bookmarks")).filter( | ||
(item) => item.id !== id | ||
); | ||
|
||
const categoriesList = document.createElement("ul"); | ||
categoriesList.id = "categories-list"; | ||
const searchHistoryArray = JSON.parse( | ||
localStorage.getItem("search-history") || "[]" | ||
); | ||
const categories = categorizeByDate(searchHistoryArray); | ||
console.log(categories); | ||
|
||
const sortedKeys = Object.keys(categories).sort((a, b) => { | ||
if (a.includes("Today")) return -1; | ||
if (b.includes("Today")) return 1; | ||
if (a.includes("Yesterday")) return -1; | ||
if (b.includes("Yesterday")) return 1; | ||
if (a.includes("Last 7 days")) return -1; | ||
if (b.includes("Last 7 days")) return 1; | ||
if (a.includes("Older")) return -1; | ||
if (b.includes("Older")) return 1; | ||
return 0; | ||
}); | ||
|
||
sortedKeys.forEach((key) => { | ||
const category = document.createElement("li"); | ||
category.className = "category"; | ||
const categoryTitle = document.createElement("h4"); | ||
categoryTitle.innerText = key; | ||
category.appendChild(categoryTitle); | ||
const categoryList = document.createElement("ul"); | ||
categoryList.className = "category-list"; | ||
categories[key].forEach((item) => { | ||
let marks = document.createElement("ul"); | ||
marks.className = "marks"; | ||
const itemLi = document.createElement("li"); | ||
itemLi.className = "item"; | ||
const itemLink = document.createElement("a"); | ||
const time = document.createElement("div"); | ||
time.className = "time"; | ||
time.innerText = new Date(item.time).toLocaleTimeString(); | ||
let button = document.createElement("button"); | ||
button.innerHTML = "<i class='fa fa-times'></i>"; | ||
button.addEventListener("click", function () { | ||
const sHistory = JSON.parse( | ||
localStorage.getItem("bookmarks") | ||
).filter((i) => i.id !== item.id); | ||
localStorage.setItem("bookmarks", JSON.stringify(sHistory)); | ||
itemLi.remove(); | ||
if (categoriesList.children.length === 0) { | ||
let li = document.createElement("li"); | ||
li.textContent = "No Bookmarks"; | ||
categoriesList.appendChild(li); | ||
} | ||
}); | ||
itemLink.href = item.url; | ||
itemLink.innerText = item.url.slice( | ||
item.url.indexOf("//") + 2, | ||
item.url.indexOf("/", item.url.indexOf("//") + 2) | ||
); | ||
itemLink.target = "_blank"; | ||
itemLi.appendChild(itemLink); | ||
itemLi.appendChild(time); | ||
itemLi.appendChild(button); | ||
marks.appendChild(itemLi); | ||
category.appendChild(marks); | ||
categoriesList.appendChild(category); | ||
}); | ||
}); | ||
|
||
localStorage.setItem("bookmarks", JSON.stringify(sHistory)); | ||
li.remove(); | ||
if (marks.children.length === 0) { | ||
var ss = document.createElement("li"); | ||
ss.textContent = "No Bookmarks"; | ||
marks.appendChild(ss); | ||
} | ||
}); | ||
li.appendChild(a); | ||
li.appendChild(button); | ||
marks.appendChild(li); | ||
}); | ||
if (marks.children.length === 0) { | ||
var li = document.createElement("li"); | ||
li.textContent = "No Bookmarks"; | ||
marks.appendChild(li); | ||
} | ||
bookmarks.appendChild(marks); | ||
document.body.appendChild(bookmarks); | ||
if (categoriesList.children.length === 0) { | ||
let li = document.createElement("li"); | ||
li.textContent = "No Bookmarks"; | ||
categoriesList.appendChild(li); | ||
} | ||
bookmarks.appendChild(categoriesList); | ||
document.body.appendChild(bookmarks); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,80 @@ | ||
import { categorizeByDate } from "./utils/categorize.js"; | ||
|
||
window.addEventListener("DOMContentLoaded", function () { | ||
var searchHistory = document.createElement("div"); | ||
const searchHistory = document.createElement("div"); | ||
searchHistory.id = "search-history"; | ||
var history = document.createElement("ul"); | ||
|
||
const categoriesList = document.createElement("ul"); | ||
categoriesList.id = "categories-list"; | ||
history.className = "history"; | ||
JSON.parse(localStorage.getItem("search-history") || "[]") | ||
.reverse() | ||
.forEach(function ({ url, id }) { | ||
var li = document.createElement("li"); | ||
var a = document.createElement("a"); | ||
a.href = url; | ||
a.textContent = url; | ||
a.target = "_blank"; | ||
var button = document.createElement("button"); | ||
const searchHistoryArray = JSON.parse( | ||
localStorage.getItem("search-history") || "[]" | ||
); | ||
const categories = categorizeByDate(searchHistoryArray); | ||
console.log(categories); | ||
|
||
const sortedKeys = Object.keys(categories).sort((a, b) => { | ||
if (a.includes("Today")) return -1; | ||
if (b.includes("Today")) return 1; | ||
if (a.includes("Yesterday")) return -1; | ||
if (b.includes("Yesterday")) return 1; | ||
if (a.includes("Last 7 days")) return -1; | ||
if (b.includes("Last 7 days")) return 1; | ||
if (a.includes("Older")) return -1; | ||
if (b.includes("Older")) return 1; | ||
return 0; | ||
}); | ||
|
||
sortedKeys.forEach((key) => { | ||
const category = document.createElement("li"); | ||
category.className = "category"; | ||
const categoryTitle = document.createElement("h4"); | ||
categoryTitle.innerText = key; | ||
category.appendChild(categoryTitle); | ||
const categoryList = document.createElement("ul"); | ||
categoryList.className = "category-list"; | ||
categories[key].forEach((item) => { | ||
const history = document.createElement("ul"); | ||
const itemLi = document.createElement("li"); | ||
itemLi.className = "item"; | ||
const itemLink = document.createElement("a"); | ||
const time = document.createElement("div"); | ||
time.className = "time"; | ||
time.innerText = new Date(item.time).toLocaleTimeString(); | ||
let button = document.createElement("button"); | ||
button.innerHTML = "<i class='fa fa-times'></i>"; | ||
button.addEventListener("click", function () { | ||
const sHistory = JSON.parse( | ||
localStorage.getItem("search-history") | ||
).filter((item) => item.id !== id); | ||
|
||
).filter((i) => i.id !== item.id); | ||
localStorage.setItem("search-history", JSON.stringify(sHistory)); | ||
li.remove(); | ||
if (history.children.length === 0) { | ||
var ss = document.createElement("li"); | ||
ss.textContent = "No search history"; | ||
history.appendChild(ss); | ||
itemLi.remove(); | ||
if (categoriesList.children.length === 0) { | ||
let li = document.createElement("li"); | ||
li.textContent = "No search history"; | ||
categoriesList.appendChild(li); | ||
} | ||
}); | ||
li.appendChild(a); | ||
li.appendChild(button); | ||
history.appendChild(li); | ||
itemLink.href = item.url; | ||
itemLink.innerText = item.url.slice( | ||
item.url.indexOf("//") + 2, | ||
item.url.indexOf("/", item.url.indexOf("//") + 2) | ||
); | ||
itemLink.target = "_blank"; | ||
itemLi.appendChild(itemLink); | ||
itemLi.appendChild(time); | ||
itemLi.appendChild(button); | ||
history.appendChild(itemLi); | ||
category.appendChild(history); | ||
categoriesList.appendChild(category); | ||
}); | ||
if (history.children.length === 0) { | ||
var li = document.createElement("li"); | ||
}); | ||
|
||
if (categoriesList.children.length === 0) { | ||
let li = document.createElement("li"); | ||
li.textContent = "No search history"; | ||
history.appendChild(li); | ||
categoriesList.appendChild(li); | ||
} | ||
searchHistory.appendChild(history); | ||
searchHistory.appendChild(categoriesList); | ||
document.body.appendChild(searchHistory); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ strong, | |
sub, | ||
sup, | ||
tt, | ||
var, | ||
let, | ||
b, | ||
u, | ||
i, | ||
|
Oops, something went wrong.