![]() |
|
Javascript on Trends Page - Printable Version +- LogicMachine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: OLD visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9) +--- Thread: Javascript on Trends Page (/showthread.php?tid=6262) |
Javascript on Trends Page - jmir - 22.01.2026 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? RE: Javascript on Trends Page - admin - 22.01.2026 Post your script. RE: Javascript on Trends Page - jmir - 22.01.2026 (22.01.2026, 07:04)admin Wrote: Post your script. I'm using this: https://forum.logicmachine.net/showthread.php?tid=3458&highlight=logout RE: Javascript on Trends Page - admin - 22.01.2026 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)
}
})RE: Javascript on Trends Page - jmir - 22.01.2026 (22.01.2026, 07:49)admin Wrote: It won't work because certain variables (currentPlanId) and functions (showPlan) are not defined in trends. 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? RE: Javascript on Trends Page - admin - 22.01.2026 Replace window.location = '/apps/' with this, change 123 to the real plan ID: Code: if (window.showPlan) {
window.showPlan(123)
}
else {
window.location = '/apps/'
}RE: Javascript on Trends Page - jmir - 22.01.2026 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)
}
}) |