forked from rDrama/rDrama
use permalinks for instant visit marker
parent
23bfbc5de0
commit
5455ec6a7d
|
@ -47,81 +47,84 @@ if (fake_textarea) {
|
||||||
|
|
||||||
if (screen_width < 768) {
|
if (screen_width < 768) {
|
||||||
const post_ids = localStorage.getItem("post_ids").split(', ');
|
const post_ids = localStorage.getItem("post_ids").split(', ');
|
||||||
const current_index = post_ids.indexOf(pid)
|
const permalink = document.getElementById("permalink").value
|
||||||
const id_after = post_ids[current_index+1]
|
const current_index = post_ids.indexOf(`'${permalink}'`)
|
||||||
const id_before = post_ids[current_index-1]
|
if (current_index > -1) {
|
||||||
|
const id_after = post_ids[current_index+1]
|
||||||
|
const id_before = post_ids[current_index-1]
|
||||||
|
|
||||||
const _C = document.querySelector('.container')
|
const _C = document.querySelector('.container')
|
||||||
const N = _C.children.length
|
const N = _C.children.length
|
||||||
const NF = 30
|
const NF = 30
|
||||||
|
|
||||||
let i = 0, x0 = null, y0 = null, locked = false, w, ini, fin, rID = null, anf, n;
|
let i = 0, x0 = null, y0 = null, locked = false, w, ini, fin, rID = null, anf, n;
|
||||||
|
|
||||||
function unify(e) { return e.changedTouches ? e.changedTouches[0] : e };
|
function unify(e) { return e.changedTouches ? e.changedTouches[0] : e };
|
||||||
|
|
||||||
function lock(e) {
|
function lock(e) {
|
||||||
x0 = unify(e).clientX;
|
x0 = unify(e).clientX;
|
||||||
y0 = unify(e).clientY;
|
y0 = unify(e).clientY;
|
||||||
locked = true
|
locked = true
|
||||||
};
|
};
|
||||||
|
|
||||||
function drag(e) {
|
function drag(e) {
|
||||||
if(locked) {
|
if(locked) {
|
||||||
let dx = unify(e).clientX - x0
|
let dx = unify(e).clientX - x0
|
||||||
let f = +(dx/w).toFixed(2);
|
let f = +(dx/w).toFixed(2);
|
||||||
|
|
||||||
let dy = unify(e).clientY - y0
|
let dy = unify(e).clientY - y0
|
||||||
let fy = +(dy/y).toFixed(2);
|
let fy = +(dy/y).toFixed(2);
|
||||||
|
|
||||||
if (!getSelection().toString() && (f > 0.04 || f < -0.04) && (fy < 0.02 && fy > -0.02)) {
|
if (!getSelection().toString() && (f > 0.04 || f < -0.04) && (fy < 0.02 && fy > -0.02)) {
|
||||||
if (id_before && f > 0.2) {
|
if (id_before && f > 0.2) {
|
||||||
location.href = `/post/${id_before}`
|
location.href = id_before.slice(1, -1)
|
||||||
}
|
}
|
||||||
if (id_after && f < -0.2) {
|
if (id_after && f < -0.2) {
|
||||||
location.href = `/post/${id_after}`
|
location.href = id_after.slice(1, -1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function move(e) {
|
||||||
|
if(locked) {
|
||||||
|
let dx = unify(e).clientX - x0,
|
||||||
|
s = Math.sign(dx),
|
||||||
|
f = +(s*dx/w).toFixed(2);
|
||||||
|
|
||||||
|
ini = i - s*f;
|
||||||
|
|
||||||
|
if((i > 0 || s < 0) && (i < N - 1 || s > 0) && f > .2) {
|
||||||
|
i -= s;
|
||||||
|
f = 1 - f
|
||||||
|
}
|
||||||
|
|
||||||
|
fin = i;
|
||||||
|
anf = Math.round(f*NF);
|
||||||
|
n = 2 + Math.round(f)
|
||||||
|
x0 = null;
|
||||||
|
y0 = null;
|
||||||
|
locked = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function move(e) {
|
function size() {
|
||||||
if(locked) {
|
w = window.innerWidth
|
||||||
let dx = unify(e).clientX - x0,
|
y = window.innerHeight
|
||||||
s = Math.sign(dx),
|
};
|
||||||
f = +(s*dx/w).toFixed(2);
|
|
||||||
|
|
||||||
ini = i - s*f;
|
size();
|
||||||
|
_C.style.setProperty('--n', N);
|
||||||
|
|
||||||
if((i > 0 || s < 0) && (i < N - 1 || s > 0) && f > .2) {
|
addEventListener('resize', size, false);
|
||||||
i -= s;
|
|
||||||
f = 1 - f
|
|
||||||
}
|
|
||||||
|
|
||||||
fin = i;
|
_C.addEventListener('mousedown', lock, false);
|
||||||
anf = Math.round(f*NF);
|
_C.addEventListener('touchstart', lock, false);
|
||||||
n = 2 + Math.round(f)
|
|
||||||
x0 = null;
|
_C.addEventListener('mousemove', drag, false);
|
||||||
y0 = null;
|
_C.addEventListener('touchmove', drag, false);
|
||||||
locked = false;
|
|
||||||
|
_C.addEventListener('mouseup', move, false);
|
||||||
|
_C.addEventListener('touchend', move, false);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
function size() {
|
|
||||||
w = window.innerWidth
|
|
||||||
y = window.innerHeight
|
|
||||||
};
|
|
||||||
|
|
||||||
size();
|
|
||||||
_C.style.setProperty('--n', N);
|
|
||||||
|
|
||||||
addEventListener('resize', size, false);
|
|
||||||
|
|
||||||
_C.addEventListener('mousedown', lock, false);
|
|
||||||
_C.addEventListener('touchstart', lock, false);
|
|
||||||
|
|
||||||
_C.addEventListener('mousemove', drag, false);
|
|
||||||
_C.addEventListener('touchmove', drag, false);
|
|
||||||
|
|
||||||
_C.addEventListener('mouseup', move, false);
|
|
||||||
_C.addEventListener('touchend', move, false);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ def front_all(v, hole=None):
|
||||||
|
|
||||||
if v and v.client: return {"data": [x.json for x in posts], "total": total}
|
if v and v.client: return {"data": [x.json for x in posts], "total": total}
|
||||||
|
|
||||||
result = render_template("home.html", v=v, listing=posts, total=total, sort=sort, t=t, page=page, hole=hole, home=True, pins=pins, size=size, post_ids=ids)
|
result = render_template("home.html", v=v, listing=posts, total=total, sort=sort, t=t, page=page, hole=hole, home=True, pins=pins, size=size, post_ids=[p.permalink for p in posts])
|
||||||
|
|
||||||
if not v:
|
if not v:
|
||||||
cache.set(f'frontpage_{sort}_{t}_{page}_{hole}_{pins}', result, timeout=900)
|
cache.set(f'frontpage_{sort}_{t}_{page}_{hole}_{pins}', result, timeout=900)
|
||||||
|
|
|
@ -347,6 +347,8 @@
|
||||||
|
|
||||||
<input hidden class="twoattrs" value="{{p.id}},{{p.comment_count}}">
|
<input hidden class="twoattrs" value="{{p.id}},{{p.comment_count}}">
|
||||||
<script defer src="{{'js/new_comments.js' | asset}}"></script>
|
<script defer src="{{'js/new_comments.js' | asset}}"></script>
|
||||||
|
|
||||||
|
<input hidden id="permalink" value="{{p.permalink}}">
|
||||||
<script defer src="{{'js/post.js' | asset}}"></script>
|
<script defer src="{{'js/post.js' | asset}}"></script>
|
||||||
|
|
||||||
{% if fart and not (v and v.has_badge(128)) %}
|
{% if fart and not (v and v.has_badge(128)) %}
|
||||||
|
|
Loading…
Reference in New Issue