0

How to make short and concisely bookmarklet that generates some URL and opens it?

Let's say generates url containing current date (in browser's timezone) and opens it.

This would be helpful, e.g. to make urls to prefilled forms or just bookmarklet implementing yesterbox for some web based email client (like gmail)?

Let's make one for gmail's first/default/0 logged in user , here is URL with date:

https://mail.google.com/mail/u/0/#search/is%3Ainbox+before%3A2016-08-31
# or "priority inbox"
https://mail.google.com/mail/u/0/#search/is%3Ainbox+is%3Aimportant+before%3A2016-08-31
Grzegorz Wierzowiecki
  • 10,545
  • 9
  • 50
  • 88

1 Answers1

0

Bookmarklet that adds "+before:date" to courrent url = if you search on gmail it will add "before:YYYY-MM-DD" to current search! So you can do yesterbox, by each search query you use ! (be careful with just "label:X" queries as they form URL differently)

/* Current View!!! (Adds "before:YYYY-MM-DD" to current URL ! -> gmail search view) */
javascript:(function(){ var d=new Date(); var curr=location.href; location.replace(curr+'+before:'+d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()); })(); /* http://stackoverflow.com/a/29808878 */

Bookmarklet opening new tab/new window with before: set to current date

javascript:(function(){ var d=new Date(); window.open('https://mail.google.com/mail/u/0/#search/is:inbox+before:'+d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()); })();

Easily adopted with "is:important" or "is:unimportant" :

javascript:(function(){ var d=new Date(); window.open('https://mail.google.com/mail/u/0/#search/is:inbox+is:important+before:'+d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()); })();

javascript:(function(){ var d=new Date(); window.open('https://mail.google.com/mail/u/0/#search/is:inbox+is:unimportant+before:'+d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()); })();

And here are versions opening in current tab/window :

javascript:(function(){ var d=new Date(); location.replace('https://mail.google.com/mail/u/0/#search/is:inbox+is:unimportant+before:'+d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()); })(); /* http://stackoverflow.com/a/29808878 */

javascript:(function(){ var d=new Date(); location.replace('https://mail.google.com/mail/u/0/#search/is%3Ainbox+is%3Aimportant+before:'+d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()); })(); /* http://stackoverflow.com/a/29808878 */

and also with "starred" criteria

javascript:(function(){ var d=new Date(); location.replace('https://mail.google.com/mail/u/0/#search/is:inbox+is:unimportant+-is:starred+before:'+d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()); })(); /* http://stackoverflow.com/a/29808878 */

javascript:(function(){ var d=new Date(); location.replace('https://mail.google.com/mail/u/0/#search/is%3Ainbox+(is%3Aimportant+OR+is%3Astarred)+before:'+d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()); })(); /* http://stackoverflow.com/a/29808878 */

References: https://www.mattcutts.com/blog/javascript-bookmarklet-basics/

Grzegorz Wierzowiecki
  • 10,545
  • 9
  • 50
  • 88