如何简短而简洁地生成一些URL并打开它?
假设生成包含当前日期的网址(在浏览器的时区中)并打开它。
这会有所帮助,例如为某些基于网络的电子邮件客户端(如gmail)制作网页预填表格或只是实施yesterbox的书签?
让我们为gmail的第一个/默认/ 0登录用户创建一个,这里是带日期的URL:
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
答案 0 :(得分:0)
将“+ before:date”添加到courrent网址的Bookmarklet =如果您在gmail上搜索,它会将“before:YYYY-MM-DD”添加到当前搜索中!所以你可以通过你使用的每个搜索查询来做yesterbox! (请注意“label:X”查询,因为它们形成不同的URL)
/* 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打开新标签/新窗口,before:
设置为当前日期
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()); })();
轻松采用“is:important”或“is:notmportant”:
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()); })();
以下版本在当前标签/窗口中打开:
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 */
以及“已加星标”的标准
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 */
参考文献:https://www.mattcutts.com/blog/javascript-bookmarklet-basics/