2016-09-01 54 views
0

如何製作簡短的小書籤,生成一些URL並將其打開?Yesterbox - 生成並打開當前日期的URL Javascript Bookmarklet

假設生成包含當前日期的url(在瀏覽器的時區中)並打開它。

這會有幫助,例如,使網址成爲預填表單,或者只是爲一些基於Web的電子郵件客戶端(如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

小書籤,增加了「+前:日期」到courrent URL =如果您在Gmail搜索它將在當前搜索中添加「之前:YYYY-MM-DD」!因此,您可以通過您使用的每個搜索查詢來執行「 (注意只用「標籤: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 */ 

小書籤開放新標籤/新窗口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()); })(); 

「是:重要」或‘是:不重要’:

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()); })(); 

這裏是版本電流T 開幕AB /窗口

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/