-
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.
Merge pull request #4 from unelmacoin/feature/bookmarks-histroty
Feature/bookmarks histroty
Showing
30 changed files
with
765 additions
and
2,423 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link href="css/bookmarks.css" rel="stylesheet" /> | ||
<script src="https://kit.fontawesome.com/d127033893.js" crossorigin="anonymous"></script> | ||
<title>Bookmarks</title> | ||
</head> | ||
<body> | ||
<script src="bookmarks.js" type="module"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { categorizeByDate } from "./utils/categorize.js"; | ||
|
||
window.addEventListener("DOMContentLoaded", function () { | ||
let bookmarks = document.createElement("div"); | ||
bookmarks.id = "bookmarks"; | ||
|
||
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); | ||
}); | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { | ||
addBookmark, | ||
getBookmarks, | ||
removeFromBookmarks, | ||
} = require("../utils/handleLocalStorage"); | ||
|
||
const BookmarkBtn = () => { | ||
const bookmarkBtn = document.createElement("button"); | ||
bookmarkBtn.id = "bookmark-btn"; | ||
bookmarkBtn.innerHTML = '<i class="fa fa-star"></i>'; | ||
bookmarkBtn.addEventListener("click", function () { | ||
bookmarkBtn.classList.toggle("active"); | ||
const bookmarks = getBookmarks(); | ||
const activeWebview = document.querySelector(".active-webview"); | ||
const url = activeWebview.src; | ||
if (!bookmarks.find((item) => item.url === url)) { | ||
addBookmark(url); | ||
} else { | ||
removeFromBookmarks(url); | ||
} | ||
}); | ||
return bookmarkBtn; | ||
}; | ||
module.exports = BookmarkBtn; |
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,19 +1,19 @@ | ||
const goToLocation = require("../utils/goToLocation"); | ||
|
||
const LocationForm = () => { | ||
const container = document.createElement("div"); | ||
const locationForm = document.createElement("form"); | ||
|
||
container.classList.add("location-container"); | ||
const location = document.createElement("input"); | ||
locationForm.id = "location-form"; | ||
location.id = "location-input"; | ||
location.type = "text"; | ||
location.value = "https://www.unelma.xyz/"; | ||
|
||
locationForm.appendChild(location); | ||
locationForm.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
goToLocation(location); | ||
}); | ||
return locationForm; | ||
}; | ||
module.exports = LocationForm; | ||
module.exports = LocationForm; |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const addTab = require("../utils/addTab"); | ||
const { getCurrentTabs } = require("../utils/handleLocalStorage"); | ||
|
||
const menuItems = [ | ||
{ | ||
name: "Bookmarks", | ||
url: "bookmarks.html", | ||
icon: "bookmark", | ||
}, | ||
{ | ||
name: "History", | ||
url: "history.html", | ||
icon: "history", | ||
}, | ||
]; | ||
|
||
const Menu = () => { | ||
const menu = document.createElement("div"); | ||
menu.id = "menu"; | ||
const menuList = document.createElement("ul"); | ||
menuList.id = "menu-list"; | ||
const bookmarks = document.createElement("li"); | ||
bookmarks.id = "bookmarks"; | ||
menuItems.forEach((item) => { | ||
const menuItem = document.createElement("li"); | ||
menuItem.classList.add("menu-item"); | ||
menuItem.innerHTML = `<i class="fa fa-${item.icon}"></i> ${item.name}`; | ||
menuItem.addEventListener("click", () => { | ||
menu.classList.remove("open"); | ||
const historyTab = getCurrentTabs().find( | ||
(item) => item.url === "history.html" | ||
); | ||
const bookmarksTab = getCurrentTabs().find( | ||
(item) => item.url === "bookmarks.html" | ||
); | ||
if (!historyTab && item.url === "history.html") { | ||
addTab("history.html"); | ||
} | ||
if (!bookmarksTab && item.url === "bookmarks.html") { | ||
addTab("bookmarks.html"); | ||
} | ||
}); | ||
menuList.appendChild(menuItem); | ||
}); | ||
menu.appendChild(menuList); | ||
return menu; | ||
}; | ||
module.exports = Menu; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const MenuButton = () => { | ||
const menuButton = document.createElement("div"); | ||
menuButton.id = "menu-button"; | ||
menuButton.innerHTML = '<i class="fa fa-ellipsis"></i>'; | ||
menuButton.addEventListener("click", () => { | ||
const menu = document.getElementById("menu"); | ||
menu.classList.toggle("open"); | ||
}); | ||
return menuButton; | ||
}; | ||
module.exports = MenuButton; |
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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const handleMaximization = require("../utils/handleMaximization"); | ||
const TopBar = () => { | ||
const topBar = document.createElement("div"); | ||
topBar.classList.add("top-bar"); | ||
const windowControlsClose = document.createElement("button"); | ||
windowControlsClose.id = "window-controls-close"; | ||
windowControlsClose.innerHTML = '<i class="fa fa-times"></i>'; | ||
const windowControlsMinimize = document.createElement("button"); | ||
windowControlsMinimize.id = "window-controls-minimize"; | ||
windowControlsMinimize.innerHTML = '<i class="fa fa-minus"></i>'; | ||
const windowControlsMaximize = document.createElement("button"); | ||
windowControlsMaximize.id = "window-controls-maximize"; | ||
windowControlsMaximize.innerHTML = '<i class="fa fa-expand"></i>'; | ||
|
||
const windowControlsUnmaximize = document.createElement("button"); | ||
windowControlsUnmaximize.id = "window-controls-unmaximize"; | ||
windowControlsUnmaximize.innerHTML = '<i class="fa fa-compress"></i>'; | ||
handleMaximization( | ||
windowControlsUnmaximize, | ||
windowControlsMaximize, | ||
windowControlsClose, | ||
windowControlsMinimize | ||
); | ||
topBar.appendChild(windowControlsMinimize); | ||
topBar.appendChild(windowControlsMaximize); | ||
topBar.appendChild(windowControlsUnmaximize); | ||
topBar.appendChild(windowControlsClose); | ||
return topBar; | ||
}; | ||
module.exports = TopBar; |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
body { | ||
font-family: Lucida Grande, Arial, sans-serif; | ||
background-color: transparent; | ||
} | ||
body::-webkit-scrollbar { | ||
width: 0px; | ||
} | ||
button, | ||
input { | ||
outline: none; | ||
border: 0; | ||
background: none; | ||
} | ||
button { | ||
cursor: pointer; | ||
} | ||
a { | ||
text-decoration: none; | ||
color: rgb(73, 87, 107); | ||
display: block; | ||
width: 200px; | ||
} | ||
ul { | ||
list-style: none; | ||
} | ||
#bookmarks { | ||
border-radius: 7px; | ||
display: flex; | ||
padding: 30px; | ||
width: 100%; | ||
} | ||
#categories-list { | ||
width: 100%; | ||
} | ||
#bookmarks .category { | ||
display: flex; | ||
list-style: none; | ||
flex-direction: column; | ||
width: 100%; | ||
border: 1px solid rgba(216, 220, 226, 0.37); | ||
border-radius: 10px; | ||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); | ||
padding: 15px; | ||
margin-bottom: 20px; | ||
} | ||
#bookmarks .category-list > li { | ||
display: flex; | ||
list-style: none; | ||
flex-direction: column; | ||
width: 100%; | ||
padding: 15px 10px; | ||
margin-bottom: 10px; | ||
} | ||
.history { | ||
width: 100%; | ||
} | ||
.item { | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 15px 20px; | ||
|
||
} | ||
h4 { | ||
border-bottom: 1px solid rgba(211, 211, 211, 0.575); | ||
padding: 20px; | ||
margin-bottom: 10px; | ||
text-transform: capitalize; | ||
} | ||
.time { | ||
font-weight: bold; | ||
font-size: 14px; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
body { | ||
font-family: Lucida Grande, Arial, sans-serif; | ||
background-color: transparent; | ||
} | ||
body::-webkit-scrollbar { | ||
width: 0px; | ||
} | ||
button, | ||
input { | ||
outline: none; | ||
border: 0; | ||
background: none; | ||
} | ||
button { | ||
cursor: pointer; | ||
} | ||
a { | ||
text-decoration: none; | ||
color: rgb(73, 87, 107); | ||
display: block; | ||
width: 200px; | ||
} | ||
ul { | ||
list-style: none; | ||
} | ||
#search-history { | ||
border-radius: 7px; | ||
display: flex; | ||
padding: 30px; | ||
width: 100%; | ||
} | ||
#categories-list { | ||
width: 100%; | ||
} | ||
#search-history .category { | ||
display: flex; | ||
list-style: none; | ||
flex-direction: column; | ||
width: 100%; | ||
border: 1px solid rgba(216, 220, 226, 0.37); | ||
border-radius: 10px; | ||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); | ||
padding: 15px; | ||
margin-bottom: 20px; | ||
} | ||
#search-history .category-list > li { | ||
display: flex; | ||
list-style: none; | ||
flex-direction: column; | ||
width: 100%; | ||
padding: 15px 10px; | ||
margin-bottom: 10px; | ||
} | ||
.history { | ||
width: 100%; | ||
} | ||
.item { | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 15px 20px; | ||
|
||
} | ||
h4 { | ||
border-bottom: 1px solid rgba(211, 211, 211, 0.575); | ||
padding: 20px; | ||
margin-bottom: 10px; | ||
text-transform: capitalize; | ||
} | ||
.time { | ||
font-weight: bold; | ||
font-size: 14px; | ||
} |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link href="css/history.css" rel="stylesheet" /> | ||
<title>History</title> | ||
<script src="https://kit.fontawesome.com/d127033893.js" crossorigin="anonymous"></script> | ||
</head> | ||
<body> | ||
<script src="history.js" type="module"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { categorizeByDate } from "./utils/categorize.js"; | ||
|
||
window.addEventListener("DOMContentLoaded", function () { | ||
const searchHistory = document.createElement("div"); | ||
searchHistory.id = "search-history"; | ||
|
||
const categoriesList = document.createElement("ul"); | ||
categoriesList.id = "categories-list"; | ||
history.className = "history"; | ||
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((i) => i.id !== item.id); | ||
localStorage.setItem("search-history", JSON.stringify(sHistory)); | ||
itemLi.remove(); | ||
if (categoriesList.children.length === 0) { | ||
let li = document.createElement("li"); | ||
li.textContent = "No search history"; | ||
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); | ||
history.appendChild(itemLi); | ||
category.appendChild(history); | ||
categoriesList.appendChild(category); | ||
}); | ||
}); | ||
|
||
if (categoriesList.children.length === 0) { | ||
let li = document.createElement("li"); | ||
li.textContent = "No search history"; | ||
categoriesList.appendChild(li); | ||
} | ||
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
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 |
---|---|---|
|
@@ -36,7 +36,7 @@ strong, | |
sub, | ||
sup, | ||
tt, | ||
var, | ||
let, | ||
b, | ||
u, | ||
i, | ||
|
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export function categorizeByDate(arr) { | ||
const categories = arr.reverse().reduce((acc, item) => { | ||
const date = new Date(item.time); | ||
const today = new Date(); | ||
today.setHours(0, 0, 0, 0); | ||
const yesterday = new Date(today); | ||
yesterday.setDate(today.getDate() - 1); | ||
const older = new Date(today); | ||
older.setDate(today.getDate() - 7); | ||
const category = | ||
date.getTime() > today.getTime() | ||
? `Today - ${date.toDateString()}` | ||
: date.getTime() > yesterday.getTime() | ||
? `Yesterday - ${date.toDateString()}` | ||
: date.getTime() > older.getTime() | ||
? `Last 7 days` | ||
: `Older`; | ||
if (!acc[category]) { | ||
acc[category] = []; | ||
} | ||
acc[category].push(item); | ||
return acc; | ||
}, {}); | ||
|
||
let sortedCategories = {}; | ||
//put key contains today first | ||
//put key contains yesterday second | ||
//put key contains last 7 days third | ||
//put key contains older last | ||
|
||
return categories; | ||
} |
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,9 +1,25 @@ | ||
const { | ||
setCurrentTabs, | ||
getBookmarks, | ||
addHistory, | ||
} = require("./handleLocalStorage"); | ||
const handleSearch = require("./handleSearch"); | ||
|
||
const goToLocation = (input) => { | ||
const activeWebview = document.querySelector(".active-webview"); | ||
const id = +activeWebview.id.split("-")[1]; | ||
activeWebview.src = handleSearch(input.value); | ||
input.value = handleSearch(input.value); | ||
const currentTabs = JSON.parse(localStorage.getItem("current-tabs")); | ||
const indexOfCurrentTab = currentTabs.findIndex((tab) => tab.id === id); | ||
currentTabs[indexOfCurrentTab].url = handleSearch(input.value); | ||
setCurrentTabs(currentTabs); | ||
addHistory(handleSearch(input.value)); | ||
const bookmarks = getBookmarks(); | ||
const bookmarkBtn = document.getElementById("bookmark-btn"); | ||
if (bookmarks.find((item) => item.url === handleSearch(input.value))) | ||
bookmarkBtn.classList.add("active"); | ||
else bookmarkBtn.classList.remove("active"); | ||
}; | ||
|
||
module.exports = goToLocation; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const newId = () => Math.round(Math.random() * 10000 * Math.random()); | ||
const dateTime = () => new Date(Date.now()) | ||
module.exports = { | ||
getCurrentTabs: () => { | ||
return JSON.parse(localStorage.getItem("current-tabs") || "[]"); | ||
}, | ||
setCurrentTabs: (tabs) => { | ||
localStorage.setItem("current-tabs", JSON.stringify(tabs)); | ||
}, | ||
getSearchHistory: () => { | ||
return JSON.parse(localStorage.getItem("search-history") || "[]"); | ||
}, | ||
setSearchHistory: (history) => { | ||
localStorage.setItem("search-history", JSON.stringify(history)); | ||
}, | ||
addHistory: (url) => { | ||
let history = JSON.parse(localStorage.getItem("search-history") || "[]"); | ||
if ( | ||
url !== "https://www.unelma.xyz/" && | ||
!url.includes("history.html") && | ||
!url.includes("bookmarks.html") && | ||
!history.find((item) => item.url === url) | ||
) { | ||
const id = newId(); | ||
history.push({ id, url, time: dateTime() }); | ||
localStorage.setItem("search-history", JSON.stringify(history)); | ||
} | ||
}, | ||
getBookmarks: () => { | ||
return JSON.parse(localStorage.getItem("bookmarks") || "[]"); | ||
}, | ||
setBookmarks: (marks) => { | ||
localStorage.setItem("bookmarks", JSON.stringify(marks)); | ||
}, | ||
addBookmark: (url) => { | ||
let bookmarks = JSON.parse(localStorage.getItem("bookmarks") || "[]"); | ||
if ( | ||
!bookmarks.find((item) => item.url === url) && | ||
!url.endsWith("bookmarks.html") && | ||
!url.endsWith("history.html") | ||
) { | ||
const id = newId(); | ||
bookmarks.push({ id, url, time: dateTime() }); | ||
localStorage.setItem("bookmarks", JSON.stringify(bookmarks)); | ||
} | ||
}, | ||
removeFromBookmarks: (url) => { | ||
let bookmarks = JSON.parse(localStorage.getItem("bookmarks") || "[]"); | ||
bookmarks = bookmarks.filter((item) => item.url !== url); | ||
localStorage.setItem("bookmarks", JSON.stringify(bookmarks)); | ||
}, | ||
removeFromSearchHistroy: (url) => { | ||
let history = JSON.parse(localStorage.getItem("bookmarks") || "[]"); | ||
|
||
history = history.filter((item) => item.url !== url); | ||
localStorage.setItem("search-history", JSON.stringify(history)); | ||
}, | ||
}; |
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