Talk:Scripts/WME JavaScript development View history

(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...")
 
(Took discussion to https://www.waze.com/forum/viewtopic.php?f=276&t=172503)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== 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.
[[User:Glodenox|Glodenox]] ([[User talk: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.
<pre>(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();
})();</pre>
[[User:Glodenox|Glodenox]] ([[User talk:Glodenox|talk]]) 10:02, 24 November 2015 (UTC)

Latest revision as of 19:13, 3 January 2016