@xiee/utils 1.1.12 → 1.1.14
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/custom-disqus.js +16 -0
- package/js/post-nav.js +22 -0
- package/js/toggle-notes.js +1 -1
- package/package.json +1 -1
package/js/custom-disqus.js
CHANGED
|
@@ -77,6 +77,22 @@
|
|
|
77
77
|
selectTab2();
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
|
+
s.onload = function(e) {
|
|
81
|
+
// if Disqus comment count is zero, just get rid of the Disqus tab
|
|
82
|
+
var dc = d.getElementById('disqus_count');
|
|
83
|
+
if (!dc) return;
|
|
84
|
+
var s3 = d.createElement('script');
|
|
85
|
+
s3.src = '//yihui.disqus.com/count.js';
|
|
86
|
+
s3.id = 'dsq-count-scr';
|
|
87
|
+
t.appendChild(s3);
|
|
88
|
+
new MutationObserver(() => {
|
|
89
|
+
if (dc.innerText == '' || dc.innerText > 0) return;
|
|
90
|
+
selectTab2(); loadScript();
|
|
91
|
+
a.append(a.querySelector('#tab-2 ~ .panel'));
|
|
92
|
+
a.querySelector('.tabs').remove();
|
|
93
|
+
a.querySelector('.panel').style.display = 'block';
|
|
94
|
+
}).observe(dc, {characterData: true, childList: true});
|
|
95
|
+
};
|
|
80
96
|
// show comments when the hash means to jump to a comment
|
|
81
97
|
if (location.hash.match(/^#comment-[0-9]+$/)) return l(true);
|
|
82
98
|
var c = function() {
|
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
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
h.classList.add('toggle-notes');
|
|
7
7
|
h.onclick = function(e) {
|
|
8
8
|
s === null && !/^(localhost|[0-9.]+)$/.test(location.hostname) &&
|
|
9
|
-
alert('
|
|
9
|
+
alert('你好像点了个神秘开关……请勿公开,自行阅读即可(再次点击可关闭),谢谢!');
|
|
10
10
|
s = d.body.classList.toggle('hide-notes');
|
|
11
11
|
try { sessionStorage.setItem('hide-notes', s); } catch (e) {};
|
|
12
12
|
};
|