Javascript 仅针对带有Greasemonkey的非活动按钮
我正在尝试为站点提升编写一个简短的Greasemonkey脚本。这样做将单击我所有连接的“道具”按钮。这些功能就像Facebook上的“喜欢”按钮——你可以打开和关闭它们 问题是,重新加载页面时,脚本将停用以前激活的按钮。那么,如何修改脚本,使其仅针对非活动的“道具”按钮 我在本页上使用了布罗克·亚当斯的教程作为指导——事实上,下面的大部分内容都是我从StackExchange问题的答案中获得的信息的直接复制/粘贴Javascript 仅针对带有Greasemonkey的非活动按钮,javascript,jquery,html,css,greasemonkey,Javascript,Jquery,Html,Css,Greasemonkey,我正在尝试为站点提升编写一个简短的Greasemonkey脚本。这样做将单击我所有连接的“道具”按钮。这些功能就像Facebook上的“喜欢”按钮——你可以打开和关闭它们 问题是,重新加载页面时,脚本将停用以前激活的按钮。那么,如何修改脚本,使其仅针对非活动的“道具”按钮 我在本页上使用了布罗克·亚当斯的教程作为指导——事实上,下面的大部分内容都是我从StackExchange问题的答案中获得的信息的直接复制/粘贴 // ==UserScript== // @name Lift P
// ==UserScript==
// @name Lift Propper
// @namespace https://lift.do/app/activity
// @description Props friends' lifts automatically
// @include https://lift.do/app/activity
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @version 1
// @grant none
// ==/UserScript==
waitForKeyElements ("a.action-button", triggerMostButtons);
function triggerMostButtons (jNode) {
triggerMouseEvent (jNode[0], "mouseover");
triggerMouseEvent (jNode[0], "mousedown");
triggerMouseEvent (jNode[0], "click"); //only needs click event, I think
triggerMouseEvent (jNode[0], "mouseup");
}
function triggerMouseEvent (node, eventType) {
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent (eventType, true, true);
node.dispatchEvent (clickEvent);
}
我复制了URL的源代码并将其放在这里:,尽管我不知道这有多大帮助,因为活动提要的内容看起来像是通过AJAX传入的
我尝试使用的URL是,但这当然与我的特定帐户有关
以下是我针对的节点的html(来自firebug):
这是处于活动状态的相同按钮:
<a class="action-button prop-button active" ng-class="{active: item.propId}" ng-click="prop(item.id, item.propId)" ng-show="item.proppable"></a>
这两个具有相同的CSS路径。那么,我如何使用WaitFork来区分这两者呢?如何仅针对非活动道具按钮?尝试以下操作:
waitForKeyElements ("a.action-button:not(.active)", triggerMostButtons);
这里的第一个参数类似于jquery选择器。它发现:
- “a”标签(a)
- 带有一类“动作按钮”(.动作按钮)
- 没有“active”类(:not(.active))
以下是jquery对“not”的引用:很酷,它成功了!我理解javascript:not元素的工作原理……你能充实一下.active的背景吗?这能区分css状态吗?为什么firebug的css路径不能区分这两者?补充了进一步的解释。不确定firebug的具体问题。firebug的复制CSS路径工具只显示一个类,即使有更多。这有点烦人,可能值得一次bug报告/功能请求,但我总是检查源代码。
waitForKeyElements ("a.action-button:not(.active)", triggerMostButtons);