0

When visiting a BBC episodes page, I would like "SHOW MORE" to be invoked from a Greasemonkey script.
I have tried half a dozen ways and none work. I think I am missing some fundamental.

Thanks

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Gerald 101
  • 23
  • 4

1 Answers1

2

This is a very common problem; See "Choosing and activating the right controls on an AJAX-driven site" for more details on how to solve this kind of thing.

Given that recipe, the only art/skill/difficult-part is choosing the right jQuery selector(s). In this case, the "Show More" link can be reliably had with:

#synopsis div.copy a.show-more-truncate


So, the complete working script would be:

// ==UserScript==
// @name     _BBC episode, click "Show More" link
// @include  http://www.bbc.co.uk/programmes/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant    GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/

waitForKeyElements (
    "#synopsis div.copy a.show-more-truncate", clickShowMoreLink, true
);

function clickShowMoreLink (jNode) {
    var clickEvent = document.createEvent('MouseEvents');
    clickEvent.initEvent ("click", true, true);
    jNode[0].dispatchEvent (clickEvent);
}
Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Brock, That was perfect. Thanks for all the detail. Love your waitForKeyElements. – Gerald 101 Apr 25 '13 at 22:48
  • The question was answered in a way that solved my problem. I don't understand how that was done if it was vague, etc. :-) – Gerald 101 Apr 29 '13 at 02:19
  • Read the FAQ. In general, people want to see the code needed to demonstrate a problem and the code that you've tried. It's true that I initially voted to close this question (as did 4 other experienced users). But after I searched a little, I decided that this might serve as a simple "How to" that could help beginners. I answered the question, upvoted it and voted to reopen. If you feel the question was closed improperly, you can take it up on [meta]. But, I'd read the FAQ; read [**this link**](http://meta.stackexchange.com/q/156810/) and edit your question first. – Brock Adams Apr 29 '13 at 02:41
  • PS: I also edited the question to give it a broader applicability, but only you can show that you made a programming effort. And, it's your place to show the page's relevant HTML and/or other code. – Brock Adams Apr 29 '13 at 02:43