Changed cookies to localStorage
This commit is contained in:
parent
604a6f1d6f
commit
dec94a1160
7 changed files with 17 additions and 28 deletions
|
@ -7,7 +7,7 @@ const blocks = require('../misc/blocks.json')
|
||||||
|
|
||||||
module.exports = async (app, req, res, level) => {
|
module.exports = async (app, req, res, level) => {
|
||||||
|
|
||||||
let levelString = new Buffer(level.data, 'base64')
|
let levelString = Buffer.from(level.data, 'base64')
|
||||||
let buffer;
|
let buffer;
|
||||||
let response = {};
|
let response = {};
|
||||||
|
|
||||||
|
|
|
@ -56,12 +56,6 @@ module.exports = async (app, req, res) => {
|
||||||
if (filterCheck == 'magic') filters.type = 7
|
if (filterCheck == 'magic') filters.type = 7
|
||||||
if (filterCheck == 'awarded' || filterCheck == 'starred') filters.type = 11
|
if (filterCheck == 'awarded' || filterCheck == 'starred') filters.type = 11
|
||||||
if (filterCheck == 'halloffame' || filterCheck == 'hof') filters.type = 16
|
if (filterCheck == 'halloffame' || filterCheck == 'hof') filters.type = 16
|
||||||
|
|
||||||
if (filterCheck == 'saved') {
|
|
||||||
if (!req.cookies.saved) return res.send("-1")
|
|
||||||
filters.str = req.cookies.saved.split(',').slice(10 * filters.page).slice(0, 10).join(",")
|
|
||||||
if (!filters.str.length) return res.send("-1")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.query.hasOwnProperty("user")) {
|
if (req.query.hasOwnProperty("user")) {
|
||||||
|
|
|
@ -73,16 +73,12 @@
|
||||||
<script type="text/javascript" src="https://asvd.github.io/dragscroll/dragscroll.js"></script>
|
<script type="text/javascript" src="https://asvd.github.io/dragscroll/dragscroll.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
let commentPreset = document.cookie.split('; ').find(x => x.startsWith('comments'))
|
let {mode, compact} = JSON.parse(localStorage.getItem('commentPreset') || '{"mode": "top", "compact": true}')
|
||||||
commentPreset = commentPreset ? commentPreset = commentPreset.slice(9) : "0"
|
|
||||||
|
|
||||||
let lvlID = window.location.pathname.split('/')[2]
|
let lvlID = window.location.pathname.split('/')[2]
|
||||||
let history = false;
|
let history = false;
|
||||||
let page = 0
|
let page = 0
|
||||||
|
|
||||||
let mode = commentPreset % 2 == 0 ? "time" : "top"
|
|
||||||
let compact = commentPreset > 1;
|
|
||||||
|
|
||||||
if (mode == "top") {
|
if (mode == "top") {
|
||||||
$('#timeSort').attr('src', "../assets/sort-time.png")
|
$('#timeSort').attr('src', "../assets/sort-time.png")
|
||||||
$('#topSort').attr('src', "../assets/sort-likes-on.png")
|
$('#topSort').attr('src', "../assets/sort-likes-on.png")
|
||||||
|
@ -251,8 +247,10 @@ $('#refresh').click(function() {
|
||||||
|
|
||||||
$(window).on('beforeunload ',function() {
|
$(window).on('beforeunload ',function() {
|
||||||
//0 - recent, 1 - top, 2 - recent/compact, 3 - top/compact
|
//0 - recent, 1 - top, 2 - recent/compact, 3 - top/compact
|
||||||
let commentScore = (mode == "top") + compact + compact
|
localStorage.setItem('commentPreset', JSON.stringify({
|
||||||
document.cookie = `comments=${commentScore}; expires=Fri, 31 Dec 9999 23:59:59 GMT`
|
mode,
|
||||||
|
compact
|
||||||
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -214,22 +214,21 @@ $(window).on('load', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
let savedLevels = document.cookie.split('; ').find(x => x.startsWith('saved'))
|
let savedLevels = JSON.parse(localStorage.getItem('saved') || '[]');
|
||||||
let levelList = []
|
|
||||||
let deleteMode = false;
|
let deleteMode = false;
|
||||||
if (savedLevels) {
|
if (savedLevels.includes('[[ID]]')) {
|
||||||
levelList = savedLevels.slice(6).split(',')
|
$('#saveButton').attr('src', '../assets/delete.png').attr('onclick', '$("#deleteDiv").show()')
|
||||||
if (levelList.includes('[[ID]]')) $('#saveButton').attr('src', '../assets/delete.png').attr('onclick', '$("#deleteDiv").show()')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveLevel() {
|
function saveLevel() {
|
||||||
let newCookie = savedLevels ? `${savedLevels.slice(6)},[[ID]]` : '[[ID]]'
|
savedLevels.push('[[ID]]');
|
||||||
document.cookie = `saved=${newCookie}; expires=Fri, 31 Dec 9999 23:59:59 GMT`
|
localStorage.setItem('saved', JSON.stringify(savedLevels));
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteLevel() {
|
function deleteLevel() {
|
||||||
document.cookie = `saved=${levelList.filter(x => x != "[[ID]]")}; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
|
savedLevels = savedLevels.filter(function(el) {return el != ['[[ID]]']})
|
||||||
location.reload()
|
localStorage.setItem('saved', JSON.stringify(savedLevels));
|
||||||
|
location.reload()
|
||||||
freeze = true;
|
freeze = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<div class="fancybox bounce center supercenter" style="width: 35%; height: 28%">
|
<div class="fancybox bounce center supercenter" style="width: 35%; height: 28%">
|
||||||
<h2 class="smaller center" style="font-size: 5.5vh">Delete All</h2>
|
<h2 class="smaller center" style="font-size: 5.5vh">Delete All</h2>
|
||||||
<p class="bigger center" style="line-height: 5vh; margin-top: 1.5vh;">
|
<p class="bigger center" style="line-height: 5vh; margin-top: 1.5vh;">
|
||||||
Delete all saved online levels?<br><font color="yellow">Levels will be cleared from your cookies.</font>
|
Delete all saved online levels?<br><font color="yellow">Levels will be cleared from your browser.</font>
|
||||||
</p>
|
</p>
|
||||||
<img src="../assets/btn-cancel.png" height=25%; class="gdButton center closeWindow">
|
<img src="../assets/btn-cancel.png" height=25%; class="gdButton center closeWindow">
|
||||||
<img src="../assets/btn-delete.png" height=25%; id="purgeSaved" class="gdButton center sideSpaceB">
|
<img src="../assets/btn-delete.png" height=25%; id="purgeSaved" class="gdButton center sideSpaceB">
|
||||||
|
@ -117,7 +117,7 @@ function Append() {
|
||||||
$('#pageSelect').val(page + 1)
|
$('#pageSelect').val(page + 1)
|
||||||
$('#loading').show()
|
$('#loading').show()
|
||||||
|
|
||||||
fetch(`../api/search/${accID || path}?page=${page}${window.location.search.replace("?", "&").replace("page", "nope")}`).then(res => res.json()).then(res => {
|
fetch(`../api/search/${type == 'saved' ? JSON.parse(localStorage.getItem('saved') || '[]').toString() : accID || path}?page=${page}${window.location.search.replace("?", "&").replace("page", "nope")}`).then(res => res.json()).then(res => {
|
||||||
|
|
||||||
if (page == 0) $('#pageDown').hide()
|
if (page == 0) $('#pageDown').hide()
|
||||||
else $('#pageDown').show()
|
else $('#pageDown').show()
|
||||||
|
@ -207,7 +207,7 @@ if (!$('#header').text() && typeof userMode != "string") $('#header').text(path
|
||||||
$('.closeWindow').click(function() {$(".popup").attr('style', 'display: none;')})
|
$('.closeWindow').click(function() {$(".popup").attr('style', 'display: none;')})
|
||||||
|
|
||||||
$('#purgeSaved').click(function() {
|
$('#purgeSaved').click(function() {
|
||||||
document.cookie = "saved=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"
|
localStorage.removeItem('saved');
|
||||||
location.reload()
|
location.reload()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
1
index.js
1
index.js
|
@ -11,7 +11,6 @@ app.use(express.json());
|
||||||
app.use(express.urlencoded({extended: true}));
|
app.use(express.urlencoded({extended: true}));
|
||||||
app.use(timeout('25s'));
|
app.use(timeout('25s'));
|
||||||
app.use(haltOnTimedout)
|
app.use(haltOnTimedout)
|
||||||
app.use(require('cookie-parser')());
|
|
||||||
app.set('json spaces', 2)
|
app.set('json spaces', 2)
|
||||||
|
|
||||||
app.modules = {}
|
app.modules = {}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
"canvas": "^2.6.0",
|
"canvas": "^2.6.0",
|
||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
"connect-timeout": "^1.9.0",
|
"connect-timeout": "^1.9.0",
|
||||||
"cookie-parser": "^1.4.4",
|
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"jimp": "^0.8.4",
|
"jimp": "^0.8.4",
|
||||||
"plist": "^3.0.1",
|
"plist": "^3.0.1",
|
||||||
|
|
Loading…
Add table
Reference in a new issue