Giter VIP home page Giter VIP logo

Comments (5)

n-sviridenko avatar n-sviridenko commented on June 28, 2024 2

They have it. But only recent browsers support it. And edge, for example, doesn't. So, it's nice to have some if (supports) { use native } else { use the library }.

from idle.js.

shawnmclean avatar shawnmclean commented on June 28, 2024

Thanks for picking that up. Do you have any suggestion on how to attach to an existing event?

from idle.js.

n-sviridenko avatar n-sviridenko commented on June 28, 2024

@shawnmclean Hi. Thanks for fast reaction. I think it's possible to do something like:

function proxyMethod(object, propName, method) {
  const existingMethod = object[propName];
  let finalMethod = method;

  if (typeof existingMethod === 'function') {
    finalMethod = (...args) => {
      existingMethod(...args);
      return method(...args)
    };
  }

  object[propName] = finalMethod;
}

window.onclick = () => console.log('attached earier');

proxyMethod(window, 'onclick', () => console.log('click'));
proxyMethod(window, 'onclick', () => console.log('click #2'));

https://jsfiddle.net/d9dvfajb/

from idle.js.

n-sviridenko avatar n-sviridenko commented on June 28, 2024

Using the moment, I would like to ask did you thought about https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/idle support?

from idle.js.

shawnmclean avatar shawnmclean commented on June 28, 2024

Thanks for the code suggestion.

Hey! If they now have an idle feature in the browser's api, why use this one? (I haven't dug deeper into it to see what constitutes an Idle state.)

from idle.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.