日期Bookmarklet无法使用chrome

时间:2018-05-05 03:58:03

标签: google-chrome bookmarklet

下面是一个不起作用的书签,有人可以帮助我。

javascript:function url() {
  var date = new Date();
  date.setDate(date.getDate() + (1 + 7 - date.getDay()) % 7);

  var y = date.getFullYear(); 
  var m = date.getMonth() +1; 
  if(m < 10){m = '0' + m;}
  var d = date.getDate();
  if(d < 10){d = '0' + d;}
  var date = y + "-" + m + "-" + d;

  return 'https://wms.blueapron.com/facilities/4/grocery-board?view_type=cumulative&week_starts_on=' + date
}window.open(url(),"_blank");

1 个答案:

答案 0 :(得分:0)

工作书签可能如下所示:

javascript:(function() {
    window.open(url(),"_blank");

    function url() {
        var date = new Date();
        date.setDate(date.getDate() + ((8 - date.getDay()) % 7 ? (8 - date.getDay()) % 7 : 7));

        var y = date.getFullYear(); 
        var m = date.getMonth() +1; 
        if(m < 10){m = '0' + m;}
        var d = date.getDate();
        if(d < 10){d = '0' + d;}
        var date = y + "-" + m + "-" + d;

        return 'https://wms.blueapron.com/facilities/4/grocery-board?view_type=cumulative&week_starts_on=' + date;
    }
})();