如何使用 jQuery 通过用户脚本触发 plus.google.com 上此元素的操作?

发布于 2024-11-18 01:31:00 字数 1384 浏览 3 评论 0原文

我非常频繁地使用 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'});

...但我仍然无法激活与该元素关联的功能。我尝试过的事情:

  1. 尝试使用 .click() 而不是 trigger('click')
  2. 尝试识别单击时触发的函数,使用 Firebug 和 Event Spy 但没有成功
  3. 尝试 .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:

  1. tried using .click() instead of trigger('click')
  2. tried to identify the function getting triggered on click, using Firebug and Event Spy with no success
  3. tried .mousedown() and trigger('mousedown') instead of triggering the 'click' event

Any other ideas?

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

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

发布评论

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

评论(1

喜爱皱眉﹌ 2024-11-25 01:31:00

使用低级代码来触发 JS 链接。  像这样的东西应该有效:

var clickEvent  = document.createEvent ("HTMLEvents");
clickEvent.initEvent ("click", true, true);

var jNode       = $('div.a-b-la-A span').filter('[role="button"]:contains("More")');
if (jNode.length != 1)
    alert ('Oops! Found too many (or no) "More" links');

jNode[0].dispatchEvent (clickEvent);

Use low-level code to Fire the JS link.   Something like this should work:

var clickEvent  = document.createEvent ("HTMLEvents");
clickEvent.initEvent ("click", true, true);

var jNode       = $('div.a-b-la-A span').filter('[role="button"]:contains("More")');
if (jNode.length != 1)
    alert ('Oops! Found too many (or no) "More" links');

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