quash: query parameters for just, has, and do, and some general simplification
This commit is contained in:
parent
f2f4e2e704
commit
4720d408f4
14 changed files with 156 additions and 164 deletions
45
www/public/js/params.js
Normal file
45
www/public/js/params.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
!function() {
|
||||
var p = new URLSearchParams(location.search);
|
||||
|
||||
var just = p.get('just');
|
||||
if (just && /^[a-z0-9-]+$/.test(just)) {
|
||||
document.documentElement.dataset.just = just;
|
||||
var css = 'section[data-section]:not([data-section="' + just + '"]){display:none}'
|
||||
+ ' section[data-section="' + just + '"] .section-label{pointer-events:none;text-decoration:none;color:inherit}';
|
||||
document.head.appendChild(Object.assign(document.createElement('style'), { textContent: css }));
|
||||
}
|
||||
|
||||
var act = p.get('do');
|
||||
var urls = window.__urls;
|
||||
if (urls && urls.length) {
|
||||
if (act === 'random') {
|
||||
var url = urls[Math.floor(Math.random() * urls.length)];
|
||||
location.replace(url.startsWith('http') ? url : location.origin + url);
|
||||
}
|
||||
if (act === 'newest') {
|
||||
location.replace(urls[0].startsWith('http') ? urls[0] : location.origin + urls[0]);
|
||||
}
|
||||
}
|
||||
if (act === 'admin') {
|
||||
location.replace('/admin');
|
||||
}
|
||||
|
||||
var has = p.get('has');
|
||||
if (has) {
|
||||
document.documentElement.dataset.has = has;
|
||||
has = has.toLowerCase();
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.querySelectorAll('section[data-section] pre').forEach(function(pre) {
|
||||
var lines = pre.innerHTML.split('\n');
|
||||
pre.innerHTML = lines.filter(function(line) {
|
||||
return !line.trim() || line.toLowerCase().indexOf(has) !== -1;
|
||||
}).join('\n');
|
||||
});
|
||||
document.querySelectorAll('.guestbook-entry').forEach(function(entry) {
|
||||
if (entry.textContent.toLowerCase().indexOf(has) === -1) {
|
||||
entry.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}();
|
||||
Loading…
Add table
Add a link
Reference in a new issue