-1

My company currently uses a google chrome extension to pull contact details from LinkedIn by data mining and auto-pagination. This works well, apart from when the plugin will randomly stop, which then requires for us to manually open the extension pop up and select "stop" then "start" to get the plugin running again.

I want to write a script which checks for extension inactivity, then triggers this selection of "stop" then "start" automatically. I could do with any recommendations on how I might do this. I was thinking of writing a python script which monitors for extension-specific javascript actions (I can see these happening on the "inspect elements" console) and triggers the Javascript behind the plugin.


Here is an image showing what I am working on.

ßrilliant
  • 144
  • 1
  • 11
George c
  • 65
  • 1
  • 9
  • I've managed to solve this now, thanks for your answer brilliant. It turned out there was a way to automate button clicks (using $('.[INSERT ELEMENT CLASS NAME HERE]').click(); on the console) and using a selenium pythonscript pointed at the specific instance of chrome, I can read the activity log and implement this action when required – George c Aug 26 '19 at 23:05

2 Answers2

1

I've managed to solve this now, thanks for your answer brilliant. It turned out there was a way to automate button clicks (using $('.[INSERT ELEMENT CLASS NAME HERE]').click(); on the console) and using a selenium pythonscript pointed at the specific instance of chrome, I can read the activity log and implement this action when required – George c

George c
  • 65
  • 1
  • 9
0

Normally, you can test for whether there has been inactivity after a period of time, meaning that after, say five minutes of no user action, you could execute your script. Could You Send Some code to help explain?

Here Is A basic jQuery script which detects for mouse movement and keypress events

<script type="text/javascript">
var idleTime = 0;
$(document).ready(function () {
    //Increment the idle time counter every minute.
    var idleInterval = setInterval(timerIncrement, 60000); // 1 minute

    //Zero the idle timer on mouse movement.
    $(this).mousemove(function (e) {
        idleTime = 0;
    });
    $(this).keypress(function (e) {
        idleTime = 0;
    });
});

function timerIncrement() {
    idleTime = idleTime + 1;
    if (idleTime > 19) { // 20 minutes
        window.location.reload();
    }
}
</script>   

Without using jQuery, only vanilla JavaScript:

var inactivityTime = function () {
    var time;
    window.onload = resetTimer;
    // DOM Events
    document.onmousemove = resetTimer;
    document.onkeypress = resetTimer;

    function logout() {
        alert("You are now logged out.")
        //location.href = 'logout.html'
    }

    function resetTimer() {
        clearTimeout(time);
        time = setTimeout(logout, 3000)
        // 1000 milliseconds = 1 second
    }
};

And init the function where you need it (for example: onPageLoad).

window.onload = function() {
  inactivityTime(); 
}

You can add more DOM events if you need to. Most used are:

document.onload = resetTimer;
document.onmousemove = resetTimer;
document.onmousedown = resetTimer; // touchscreen presses
document.ontouchstart = resetTimer;
document.onclick = resetTimer;     // touchpad clicks
document.onscroll = resetTimer;    // scrolling with arrow keys
document.onkeypress = resetTimer;

Or register desired events using an array

window.addEventListener('load', resetTimer, true);
var events = ['mousedown', 'mousemove', 'keypress', 'scroll', 'touchstart'];
events.forEach(function(name) {
 document.addEventListener(name, resetTimer, true); 
});

DOM Events list: http://www.w3schools.com/jsref/dom_obj_event.asp

Remember use window, or document according your needs. Here you can see the differences between them: What is the difference between window, screen, and document in Javascript?

ßrilliant
  • 144
  • 1
  • 11
  • 1
    Hi, this is very close to what I was thinking- except rather than checking for user inactivity, it would need to check for specific JavaScript activity – George c Aug 26 '19 at 17:43
  • Normally, you can add an event listener which listens for things like clicks, keys typed, or mouse movement. use `document.addEventListener` – ßrilliant Sep 09 '19 at 17:02