Created
November 28, 2015 12:16
-
-
Save asahui/1341b26660d56e09e90c to your computer and use it in GitHub Desktop.
Log mouse coordinate posted to server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load("script/utils.js"); | |
load("script/ScriptData.js"); | |
data_prefix = "logMouse_"; | |
ApplicationMain = Java.type("logbook.gui.ApplicationMain"); | |
function gcdFun(a, b) { | |
if ( ! b) { | |
return a; | |
} | |
return gcdFun(b, a % b); | |
} | |
function update(type, data){ | |
var cid = data.getField("api_serial_cid"); | |
if (cid != null) { | |
var mouse = Number(cid.substring(10)); | |
var gcd = getData("gcd"); | |
if (gcd == null) { | |
gcd = 1000; | |
} else { | |
gcd = Number(gcd); | |
} | |
if (mouse % gcd) { | |
log("mouse:" + mouse); | |
log("Please wait for const value calculation"); | |
var lastgcd = Number(getData("lastgcd")); | |
if (lastgcd == null) { | |
lastgcd = mouse; | |
} else { | |
lastgcd = Number(lastgcd); | |
} | |
var g = gcdFun(lastgcd, mouse); | |
setData("lastgcd", g.toString()); | |
setData("gcd", g.toString()); | |
log("newgcd: " + g); | |
return | |
} | |
var xy = mouse / gcd; | |
var x = (((xy - 10000) / 10000) | 0) - 1000; | |
var y = (xy - 10000) % 10000 - 1000; | |
if (x > 0 && y > 0) { | |
log("mouse:" + mouse + " x: " + x + " y: " + y); | |
if (getData("lastgcd") != null) { | |
setData("lastgcd", null); | |
} | |
} else { | |
log("mouse:" + mouse); | |
log("Please wait for const value calculation"); | |
} | |
// uncomment this line to show your own constant value | |
//log("const value: " + gcd); | |
} | |
} | |
function log(str) { | |
main = ApplicationMain.main; | |
main.printMessage(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment