It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                        
                    
                
            
                7年前关闭。
        

    

访问a BBC episodes page时,我希望从Greasemonkey脚本中调用“ SHOW MORE”。
我尝试了六种方法,但均无效果。我想我缺少一些基本知识。

谢谢

最佳答案

这是一个非常普遍的问题。有关如何解决此类问题的更多详细信息,请参见"Choosing and activating the right controls on an AJAX-driven site"

给定该配方,唯一的技巧/技能/难点在于选择正确的jQuery选择器。在这种情况下,可以通过以下方式可靠地使用“显示更多”链接:

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



因此,完整的工作脚本将是:

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

关于javascript - 如何用Greasemonkey单击“显示更多”链接? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16224333/

10-12 06:49