This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Javascript on Trends Page
#1
Hi,

Is Custom javascript running on trends page? 
I want to use a function to jump to visu start page after a time when no activity, but on trends page (and schedulers) it doesn't work...
Is there any way to do it?
Reply
#2
Post your script.
Reply
#3
(22.01.2026, 07:04)admin Wrote: Post your script.

I'm using this:
https://forum.logicmachine.net/showthrea...ght=logout
Reply
#4
It won't work because certain variables (currentPlanId) and functions (showPlan) are not defined in trends.

Try this for trends and schedulers. Adjust timeout value and location as needed.
Code:
$(function() {
  var body = $('body')
  var timeout = 90 // seconds
  
  if (body.hasClass('trends') || body.hasClass('schedulers')) {
    var events = ['pointermove', 'keydown', 'click', 'scroll']
    var ticks = 0
  
    function reset() {
      ticks = 0
    }
  
    events.forEach(function(event) {
      document.addEventListener(event, reset, true)
    })
    
    setInterval(function() {
      ticks++
      
      if (ticks >= timeout) {
        window.location = '/apps/'
      }
    }, 1000)
  }
})
Reply
#5
(22.01.2026, 07:49)admin Wrote: It won't work because certain variables (currentPlanId) and functions (showPlan) are not defined in trends.

Try this for trends and schedulers. Adjust timeout value and location as needed.
Code:
$(function() {
  var body = $('body')
  var timeout = 90 // seconds
 
  if (body.hasClass('trends') || body.hasClass('schedulers')) {
    var events = ['pointermove', 'keydown', 'click', 'scroll']
    var ticks = 0
 
    function reset() {
      ticks = 0
    }
 
    events.forEach(function(event) {
      document.addEventListener(event, reset, true)
    })
   
    setInterval(function() {
      ticks++
     
      if (ticks >= timeout) {
        window.location = '/apps/'
      }
    }, 1000)
  }
})

Hi, It works! 
Is there a way to adapt this function so that it also works in the visualisation and redirects to a specific plan?
Reply
#6
Replace window.location = '/apps/' with this, change 123 to the real plan ID:
Code:
if (window.showPlan) {
  window.showPlan(123)
}
else {
  window.location = '/apps/'
}
Reply
#7
Hi,
It works, I've added body.hasClass('usermode') and an extra if to check if we're on initial plan
Perhaps something can be improved...
Code:
  $(function() {
    var body = $('body')
    var timeout = 10 // seconds
    var ini_plan_id = 7 //numero de la pantalla inicial

    if (body.hasClass('trends') || body.hasClass('schedulers')  || body.hasClass('usermode') ){
      var events = ['pointermove', 'keydown', 'click', 'scroll']
      var ticks = 0

      function reset() {
        ticks = 0
      }

      events.forEach((event) => document.addEventListener(event, reset, true))

      setInterval(() => {
        ticks++

        if (ticks >= timeout) {
          if (window.showPlan) {
            if (window.currentPlanId !== ini_plan_id) {
              window.showPlan(ini_plan_id)
            }           
          }
          else {
            window.location = '/scada-vis/'
          }
        }
      }, 1000)
    }
  })
Reply


Forum Jump: