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