Skip to content

Commit

Permalink
Add in self Rage-Click detection in case Boomerang doesn't have it
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Oct 4, 2017
1 parent 911d291 commit 817f8f5
Showing 1 changed file with 74 additions and 8 deletions.
82 changes: 74 additions & 8 deletions perfbar.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,13 +693,80 @@ var UW = unsafeWindow;
};
});

if (UW.BOOMR && UW.BOOMR.subscribe) {
UW.BOOMR.subscribe("rage_click", onRageClick);
} else {
document.addEventListener("onBoomerangLoaded", function() {
UW.BOOMR.subscribe("rage_click", onRageClick);
});
}
/**
* Monitors mouse clicks
*
* @class BOOMR.plugins.Continuity.ClickMonitor
*/
var ClickMonitor = function() {
//
// Constants
//

// number of pixels area for Rage Clicks
var PIXEL_AREA = 10;

// number of clicks in the same area to trigger a Rage Click
var RAGE_CLICK_THRESHOLD = 3;

//
// Local Members
//

// number of click events
var clickCount = 0;

// number of clicks in the same PIXEL_AREA area
var sameClicks = 0;

// last coordinates
var x = 0;
var y = 0;

// last click target
var lastTarget = null;

/**
* Fired when a `click` event happens.
*
* @param {Event} e Event
*/
function onClick(e) {
var newX = e.clientX;
var newY = e.clientY;

// track total number of clicks
clickCount++;

// calculate number of pixels moved
var pixels = Math.round(
Math.sqrt(Math.pow(y - newY, 2) +
Math.pow(x - newX, 2)));

// track Rage Clicks
if (lastTarget === e.target || pixels <= PIXEL_AREA) {
sameClicks++;

if ((sameClicks + 1) >= RAGE_CLICK_THRESHOLD) {
onRageClick(e);
}
}
else {
sameClicks = 0;
}

// track last click coordinates and element
x = newX;
y = newY;
lastTarget = e.target;
}

//
// Startup
//
UW.document.addEventListener("click", onClick, false);
};
var clickMonitor = new ClickMonitor();

setInterval(reportFps, 1000);
}
Expand Down Expand Up @@ -5293,7 +5360,6 @@ function initEmbeddedBoomerangPlugins() {

if ((sameClicks + 1) >= RAGE_CLICK_THRESHOLD) {
rageClicks++;
BOOMR.fireEvent("rage_click", e);
}
}
else {
Expand Down

0 comments on commit 817f8f5

Please sign in to comment.