开发者

How do I trigger the action on this element on plus.google.com via a userscript using jQuery?

开发者 https://www.devze.com 2023-03-16 20:46 出处:网络
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 tr

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>

开发者_如何学C...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?


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号