@xiee/utils 1.1.10 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/post-nav.js +22 -0
- package/js/toggle-notes.js +4 -2
- package/package.json +1 -1
package/js/post-nav.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// navigate to previous/next posts by Left/Right arrows
|
|
2
|
+
(function(d) {
|
|
3
|
+
const a1 = d.querySelector('.nav-prev > a'), a2 = d.querySelector('.nav-next > a');
|
|
4
|
+
d.addEventListener('keyup', function(e) {
|
|
5
|
+
if (e.target.nodeName.toUpperCase() != 'BODY') return;
|
|
6
|
+
let u;
|
|
7
|
+
if (a1 && e.which == 37) { // Left arrow
|
|
8
|
+
u = a1.href;
|
|
9
|
+
} else if (a2 && e.which == 39) { // Right arrow
|
|
10
|
+
u = a2.href;
|
|
11
|
+
}
|
|
12
|
+
if (u) window.location = u;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const us = d.querySelectorAll('.unlist');
|
|
16
|
+
if (us.length === 0) return;
|
|
17
|
+
const s = sessionStorage.getItem('hide-notes');
|
|
18
|
+
if (s !== null) return us.forEach(u => u.classList.remove('unlist'));
|
|
19
|
+
if (a1 && a2) {
|
|
20
|
+
window.location = d.referrer === a2.href ? a1.href : a2.href;
|
|
21
|
+
}
|
|
22
|
+
})(document);
|
package/js/toggle-notes.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
if (!d.body.classList.contains('has-notes')) return;
|
|
3
3
|
const h = d.querySelector('.title > hr');
|
|
4
4
|
if (!h) return;
|
|
5
|
+
let s = sessionStorage.getItem('hide-notes');
|
|
5
6
|
h.classList.add('toggle-notes');
|
|
6
7
|
h.onclick = function(e) {
|
|
7
|
-
|
|
8
|
+
s === null && !/^(localhost|[0-9.]+)$/.test(location.hostname) &&
|
|
9
|
+
alert('你好像点了个神秘开关……请勿公开,自行阅读即可(再次点击可关闭),谢谢!');
|
|
10
|
+
s = d.body.classList.toggle('hide-notes');
|
|
8
11
|
try { sessionStorage.setItem('hide-notes', s); } catch (e) {};
|
|
9
12
|
};
|
|
10
|
-
const s = sessionStorage.getItem('hide-notes');
|
|
11
13
|
if (s !== null) d.body.classList.toggle('hide-notes', s === 'true');
|
|
12
14
|
})(document);
|