gmail javascript 书签

发布于 2024-07-17 06:37:37 字数 1371 浏览 9 评论 0原文

如果我将其加载到新选项卡(FF3)中,它就会起作用。 如果我将其加载到当前选项卡中,它只会打印 url。

我认为这实际上是将其加载到现有的 Gmail 选项卡中的问题。 也就是说,制作小书签,单击一次,然后再次单击。 这似乎是重现问题的方法。

知道什么会导致这种情况吗? 我可以想到一些解决方法,但我很好奇它是如何工作的。

javascript:var%20t=new%20Date(),y=t.getFullYear(),m=t.getMonth()+1,d=t.getDate();document.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d

/* same code split up for readability */
javascript:
  var t = new Date(),
      y = t.getFullYear(),
      m = t.getMonth()+1,
   /* d = t.getDay(); I actually have this correct above, but not here.. oops */
      d = t.getDate(); 
  document.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d;

有什么帮助吗?

谢谢:)

更新:

当我从这个答案中删除多余的空格时将必要的空格隐藏为“%20”(url编码),它什么也不做:

 /* this works. I was missing the final ")" altCognito wrote */
 javascript:void((function(){var%20t=%20new%20Date(),y=t.getFullYear(),m=t.getMonth()+1,d=t.getDate();window.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d;})())

我还尝试了一些分号摆弄和其他一般语法检查,但我不确定我在做什么寻找。 它既不能作为书签使用,也不能直接粘贴到地址栏中(无论如何对我来说)。

If I load this in a new tab (FF3) it works. If I load it in the current tab it just prints the url.

I think it's actually a matter of loading it in an existing gmail tab. So say, make the bookmarklet, click it once, then click it again. That seems to be the way to recreate the problem.

Any idea what would cause this? I can think of a few workarounds, but I'm curious about how this works.

javascript:var%20t=new%20Date(),y=t.getFullYear(),m=t.getMonth()+1,d=t.getDate();document.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d

/* same code split up for readability */
javascript:
  var t = new Date(),
      y = t.getFullYear(),
      m = t.getMonth()+1,
   /* d = t.getDay(); I actually have this correct above, but not here.. oops */
      d = t.getDate(); 
  document.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d;

Any help?

Thanks :)

UPDATE:

when I remove the extra whitespace from this answer and covert the necessary spaces to "%20" (url encoding), it does nothing at all:

 /* this works. I was missing the final ")" altCognito wrote */
 javascript:void((function(){var%20t=%20new%20Date(),y=t.getFullYear(),m=t.getMonth()+1,d=t.getDate();window.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d;})())

I also experimented with some semicolon fiddling and other general syntax checks, but I'm not sure what I'm looking for. It works neither as a bookmarklet or when pasted straight into the address bar (for me anyway).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺ぐ爱和你が 2024-07-24 06:37:37

您想要的是如下所示的内容:

javascript:void(
    (function() {
    var t = new Date(),
          y = t.getFullYear(),
          m = t.getMonth()+1,
          d = t.getDate();
      window.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d;
    })()
)

关键是 void((function() {... Your stuff here ... })())

请注意,您还想使用 getDate(),而不是 getDay,因为 getDay 返回星期几!

What you want is something that looks like this:

javascript:void(
    (function() {
    var t = new Date(),
          y = t.getFullYear(),
          m = t.getMonth()+1,
          d = t.getDate();
      window.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d;
    })()
)

The key is the void((function() {... Your stuff here ... })())

Note, that you also want to use getDate(), not getDay, as getDay returns the day of the week!

自控 2024-07-24 06:37:37

更好的做法是使用 window.location.href 而不是 document.location

It is better practice to use window.location.href instead of document.location

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文