Talk:Scripts/WME JavaScript development Discussion View history

Revision as of 10:02, 24 November 2015 by Glodenox (talk | contribs) (Created page with "== UserScript Bootstraping == First of, shouldn't this be "bootstrapping"? The part about unsafeWindow of the bootstrap code will no longer work for Google Chrome as they have...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

UserScript Bootstraping

First of, shouldn't this be "bootstrapping"? The part about unsafeWindow of the bootstrap code will no longer work for Google Chrome as they have removed the bug that enabled that to work. See https://code.google.com/p/chromium/issues/detail?id=222652 Also, I'm not sure how many of our scripts actually need access to unsafeWindow. The public variables exposed by Waze generally provide enough access for anything you need to do in a script. And for all other things I've become a big fan of the MutationObserver API. Glodenox (talk) 10:02, 24 November 2015 (UTC)

Code encapsulation

I propose adding an example code block here to show what this entails. The prefixing of functions and variables in the section before will only be of importance to exposed functions at that point. My proposal for the code block, though it might be a bit much with the setTimeouts. But this should be the general template if the script wants to rely on the Waze object or attach itself to certain elements.

(function() {
  function init() {
    // Check all requisites for the script
    if (typeof Waze === undefined ||
        typeof document.querySelector('#WazeMap') === undefined) {
      setTimeout(init, 400);
      return;
    }
    // Initialisation or other statements using dependencies here
  }
  init();
})();

Glodenox (talk) 10:02, 24 November 2015 (UTC)