gmail javascript 书签
如果我将其加载到新选项卡(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要的是如下所示的内容:
关键是 void((function() {... Your stuff here ... })())
请注意,您还想使用 getDate(),而不是 getDay,因为 getDay 返回星期几!
What you want is something that looks like this:
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!
更好的做法是使用 window.location.href 而不是 document.location
It is better practice to use window.location.href instead of document.location