redirect.js 825 B

12345678910111213141516171819202122
  1. // need to redirect in javascript to keep the hash
  2. // simple redirect; no line anchor
  3. if (document.location.hash === '') {
  4. document.location = document.body.getAttribute('data-redirect-to');
  5. }
  6. var url = new URL(document.location);
  7. var action = url.searchParams.get('a') || 'browse';
  8. var start = url.searchParams.get('s');
  9. var end = url.searchParams.get('e') || start;
  10. // simple redirect if not channel browsing, or browsing for a single date
  11. if ((action !== 'browse') || (start && (start === end))) {
  12. document.location = document.body.getAttribute('data-redirect-to') + document.location.hash;
  13. }
  14. // need to lookup the date from the comment id. shift hash to query-string so
  15. // server can lookup and reidrect.
  16. url.searchParams.set('cid', url.hash.substring(1));
  17. url.hash = '';
  18. document.location = url.toString();