该切换控件是由javascript(jQuery)添加的,因此您必须使用支持AJAX的技术来访问它。
见Choosing and activating the right controls on an AJAX-driven site。
您指出的链接有一个CSS类(i_expanded
),它为waitForKeyElements()
提供了一个很好的选择器。 因此,对于该网站所产生的完整的脚本很简单:
// ==UserScript==
// @name aniDB, auto-close the sidebar menu
// @match *://anidb.net/perl-bin/animedb*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/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 (
".filter_menu.expanded .i_expanded", clickNode, true
);
function clickNode (jNode) {
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
jNode[0].dispatchEvent (clickEvent);
}
$( '一[标题= “菜单的切换显示”]')点击()。 –