Activity 在 scalajs 中跟踪网页
Activity Tracking on webpage in scalajs
我正在尝试跟踪网页上的用户活动,如果用户在当前选项卡上,那么它应该 return TRUE 然后它应该跟踪鼠标活动,如左键单击次数、右键单击、用户是否滚动、鼠标向上、鼠标向下、鼠标左移、鼠标右移的最大值、用户在当前选项卡上停留的时间以及从加载页面到第一次点击页面的时间段等。
我正在导入 dom.document 来引用网页,代码是:
import scala.scalajs.js.JSApp
import org.scalajs.dom
import dom.document
object test extends JSApp{
def main():Unit = {
val title=document.title.toString()
}
def appendPar(targetNode: dom.Node, text: String): Unit = {
val parNode = document.createElement("p")
val textNode = document.createTextNode(text)
parNode.appendChild(textNode)
targetNode.appendChild(parNode)
}
}
我正在构建一个 scalajs 项目。我怎样才能完成上述任务?请从这里引导我。提前致谢。
对于鼠标事件的一般操作,您可以从这里开始:
dom.document.onmousedown = (e: dom.MouseEvent) => println("mouseup")
dom.document.onmouseup = (e: dom.MouseEvent) => println("mouseup")
dom.document.onmousemove = (e: dom.MouseEvent) => println("mousemove")
dom.document.onmouseout = (e: dom.MouseEvent) => println("mouseout")
dom.document.onmouseover = (e: dom.MouseEvent) => println("mouseout")
dom.document.onmousewheel = (e: dom.MouseEvent) => println("mousewheel")
如果您需要计算每个时间段(例如每秒)的点击次数:
var count = 0 //your counter
var n = 0 //number of times
dom.document.onmousedown = (e: dom.MouseEvent) => count += 1
// ms - duration of an interval in ms
def countMousedown(ms: Int): Unit ={
if (n == 100) return
n += 1
if(n != 0) println(count)
count = 0
dom.setTimeout(() => countMousedown(ms), ms)
}
countMousedown(1000)
获取坐标:
dom.document.onmousedown = (e: dom.MouseEvent) => {
val coords = (e.clientX, e.clientY)
println(s"x: ${coords._1}, y: ${coords._2}")
}
我正在尝试跟踪网页上的用户活动,如果用户在当前选项卡上,那么它应该 return TRUE 然后它应该跟踪鼠标活动,如左键单击次数、右键单击、用户是否滚动、鼠标向上、鼠标向下、鼠标左移、鼠标右移的最大值、用户在当前选项卡上停留的时间以及从加载页面到第一次点击页面的时间段等。 我正在导入 dom.document 来引用网页,代码是:
import scala.scalajs.js.JSApp
import org.scalajs.dom
import dom.document
object test extends JSApp{
def main():Unit = {
val title=document.title.toString()
}
def appendPar(targetNode: dom.Node, text: String): Unit = {
val parNode = document.createElement("p")
val textNode = document.createTextNode(text)
parNode.appendChild(textNode)
targetNode.appendChild(parNode)
}
}
我正在构建一个 scalajs 项目。我怎样才能完成上述任务?请从这里引导我。提前致谢。
对于鼠标事件的一般操作,您可以从这里开始:
dom.document.onmousedown = (e: dom.MouseEvent) => println("mouseup")
dom.document.onmouseup = (e: dom.MouseEvent) => println("mouseup")
dom.document.onmousemove = (e: dom.MouseEvent) => println("mousemove")
dom.document.onmouseout = (e: dom.MouseEvent) => println("mouseout")
dom.document.onmouseover = (e: dom.MouseEvent) => println("mouseout")
dom.document.onmousewheel = (e: dom.MouseEvent) => println("mousewheel")
如果您需要计算每个时间段(例如每秒)的点击次数:
var count = 0 //your counter
var n = 0 //number of times
dom.document.onmousedown = (e: dom.MouseEvent) => count += 1
// ms - duration of an interval in ms
def countMousedown(ms: Int): Unit ={
if (n == 100) return
n += 1
if(n != 0) println(count)
count = 0
dom.setTimeout(() => countMousedown(ms), ms)
}
countMousedown(1000)
获取坐标:
dom.document.onmousedown = (e: dom.MouseEvent) => {
val coords = (e.clientX, e.clientY)
println(s"x: ${coords._1}, y: ${coords._2}")
}