Skip to content

Commit

Permalink
feat(reset): clear cookies too
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Jan 18, 2024
1 parent b3eacc8 commit 97d2cf1
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions pages/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,55 @@
return
}
// Cookies
clearCookies()
// LocalStorage
clearLocalStorage()
// IndexedDB
await clearIndexedDb()
location.reload()
}
/**
* @see https://stackoverflow.com/a/33366171
*/
function clearCookies() {
var cookies = document.cookie.split('; ')
for (var c = 0; c < cookies.length; c++) {
var d = window.location.hostname.split('.')
while (d.length > 0) {
var cookieBase =
encodeURIComponent(cookies[c].split(';')[0].split('=')[0]) +
'=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=' +
d.join('.') +
' ;path='
var p = location.pathname.split('/')
document.cookie = cookieBase + '/'
while (p.length > 0) {
document.cookie = cookieBase + p.join('/')
p.pop()
}
d.shift()
}
}
}
function clearLocalStorage() {
localStorage.clear()
}
async function clearIndexedDb() {
const indexedDBDatabaseNames = await indexedDB.databases()
for (const { name } of indexedDBDatabaseNames) {
indexedDB.deleteDatabase(name)
}
location.reload()
}
</script>

Expand Down

0 comments on commit 97d2cf1

Please sign in to comment.