You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome中日期类Bookmarklet无法正常工作,请求技术协助

Fixing Your Blue Apron Grocery Board Bookmarklet

Let's walk through the issues in your bookmarklet and get it working properly:

Key Issues in the Original Code

  • Incorrect HTML Entity: You used & in the URL string, which is an HTML escape sequence. In JavaScript bookmarklets, we need to use the literal & for URL parameters—using & will result in an invalid parameter name (amp;week_starts_on) that the server won't recognize.
  • Duplicate Variable Name: You declared var date twice in the same scope. While JavaScript allows this, it's messy and can lead to confusion down the line.
  • (Minor) Redundant Date Logic: The date formatting works, but we can clean it up a bit for better readability without changing functionality.

Fixed Bookmarklet Code

javascript:(function() {
  const now = new Date();
  // Calculate next Monday (or today if it's already Monday)
  const daysToAdd = (1 + 7 - now.getDay()) % 7;
  now.setDate(now.getDate() + daysToAdd);
  
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  const targetDate = `${year}-${month}-${day}`;
  
  const targetUrl = `https://wms.blueapron.com/facilities/4/grocery-board?view_type=cumulative&week_starts_on=${targetDate}`;
  window.open(targetUrl, "_blank");
})();

What Changed?

  1. Wrapped the code in an IIFE (Immediately Invoked Function Expression) to avoid polluting the global scope—this is a standard best practice for bookmarklets.
  2. Renamed the initial date variable to now to avoid duplication with the formatted date string.
  3. Replaced & with the literal & to ensure the URL parameters are parsed correctly by the server.
  4. Used padStart() for cleaner date formatting (works in all modern browsers; if you need support for very old browsers, you can revert to your original if check logic).
  5. Used template literals for more readable string concatenation instead of manual + joins.

How to Use

  1. Create a new bookmark in your browser.
  2. Replace the bookmark's URL with the fixed code above.
  3. Click the bookmark—it should open the Blue Apron Grocery Board for the next (or current) Monday as intended.

内容的提问来源于stack exchange,提问作者Brandon Hunt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:22:52