如何使用 jQuery 通过用户脚本触发 plus.google.com 上此元素的操作?
我非常频繁地使用 Google+,我发现自己非常频繁地做的一件事就是点击左侧边栏中的“更多”按钮来访问隐藏在视图中的圈子。我正在尝试编写一个用户脚本,该脚本将在页面加载时为我激活“更多”链接。这是侧边栏到“更多”元素的 DOM 结构:
<div class="a-b-la-A">
<h2 class="a-za">Navigation</h2>
<a href="/welcome" target="_top" class="d-h a-b-h-Jb a-la-h a-la-aH ">Welcome</a>
<div class="a-la-Dd"></div>
<a href="/stream" target="_top" class="d-h a-b-h-Jb a-la-h a-la-aH a-la-h-Pa">Stream</a>
<div class="a-la-h-ga"><a href="/stream/circles/p5653c3hhy60aadf997" target="_top" class="d-h a-b-h-Jb a-la-h a-la-Rb-h a-b-la-Rb-h">Friends</a></div>
<span role="button" class="d-h a-b-la-gc-h a-la-h a-la-hA" tabindex="0">More<span class="a-b-la-bw a-la-tb-q">▾</span></span>
...这是我正在处理的代码片段:
$('div.a-b-la-A span').filter('[role="button"]:contains("More")').trigger('click');
我可以很好地选择和操作“更多”元素,并且 这里的背景颜色设置为黄色:
$('div.a-b-la-A span').filter('[role="button"]:contains("More")').css({'background-color': 'yellow'});
...但我仍然无法激活与该元素关联的功能。我尝试过的事情:
- 尝试使用 .click() 而不是 trigger('click')
- 尝试识别单击时触发的函数,使用 Firebug 和 Event Spy 但没有成功
- 尝试 .mousedown() 和 trigger('mousedown')而不是触发“点击”事件
还有其他想法吗?
I'm using Google+ quite heavily and one thing I find myself doing extremely frequently is clicking the 'More' button in the left-hand sidebar to access my circles that are hidden from view. I'm trying to write a user script that will activate the "More" link for me on page load. This is the DOM structure of the sidebar upto the "More" element:
<div class="a-b-la-A">
<h2 class="a-za">Navigation</h2>
<a href="/welcome" target="_top" class="d-h a-b-h-Jb a-la-h a-la-aH ">Welcome</a>
<div class="a-la-Dd"></div>
<a href="/stream" target="_top" class="d-h a-b-h-Jb a-la-h a-la-aH a-la-h-Pa">Stream</a>
<div class="a-la-h-ga"><a href="/stream/circles/p5653c3hhy60aadf997" target="_top" class="d-h a-b-h-Jb a-la-h a-la-Rb-h a-b-la-Rb-h">Friends</a></div>
<span role="button" class="d-h a-b-la-gc-h a-la-h a-la-hA" tabindex="0">More<span class="a-b-la-bw a-la-tb-q">▾</span></span>
...and here's the snippet I'm working on:
$('div.a-b-la-A span').filter('[role="button"]:contains("More")').trigger('click');
I can select and manipulate the 'More' element just fine and here's the bg-color set to yellow with:
$('div.a-b-la-A span').filter('[role="button"]:contains("More")').css({'background-color': 'yellow'});
...but I still can't activate the function tied to the element. Things I've tried:
- tried using .click() instead of trigger('click')
- tried to identify the function getting triggered on click, using Firebug and Event Spy with no success
- tried .mousedown() and trigger('mousedown') instead of triggering the 'click' event
Any other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用低级代码来触发 JS 链接。 像这样的东西应该有效:
Use low-level code to Fire the JS link. Something like this should work: