I'm trying to put together a short Greasemonkey script for the site Lift.do that will click all my connections' "Prop" buttons. These function like the 'like' button on Facebook - you can turn them on and off.
The problem is, when reloading the page, the script will deactivate buttons it activated previously. So how do I modify the script to only target non-active "Prop" buttons?
I used Brock Adams' tutorial on this page as a guide - Choosing and activating the right controls on an AJAX-driven site - and in fact most everything below is a direct copy/paste from info I got from answers to StackExchange questions.
// ==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);
}
I copied the URL's source and put it up here: http://pastebin.com/mfF8tbdC , although I don't know how much help that is because the content of the activity feed looks like it's coming in via AJAX.
The URL I'm trying to work on is https://lift.do/app/activity , but that's tied to my specific account, of course.
Here's the html of the node I'm targeting (from firebug):
<a class="action-button prop-button" ng-class="{active: item.propId}" ng-click="prop(item.id, item.propId)" ng-show="item.proppable"></a>
And here's the same button in the active state:
<a class="action-button prop-button active" ng-class="{active: item.propId}" ng-click="prop(item.id, item.propId)" ng-show="item.proppable"></a>
These two have the same CSS Path. So how do I, using waitForKeyElements, distinguish between the two? How to target only non-active Prop buttons?