title: Safari Extension - Changing Predefined Javascript Variables Values
body: <p>So what i am trying to achieve is to manipulate a javascript variable from a website, so that when I load the page it changes to a value I have pre determined (inmyscript.js).</p>
  
  <p>In Safari's extension builder I have the following setup:</p>
  
  <ul>
  <li>Access Level: All (To make sure it is running correctly for the time being)</li>
  <li>Start Scripts: jquery.min.js (the jquery script)</li>
  <li>End Scritps: myscript.js (myscript)</li>
  </ul>
  
  <p>The Start Scripts, will load the jquery script, as I want to use jquery for some DOM manipulation.
  The End Script is the script which contains an overwrite for the variable I am trying to change in the html document.</p>
  
  <p>Currently myscript.js looks like:</p>
  
  <pre><code>$(document).ready(function(){
      var numberImThinkingOf = 999;
  });
  </code></pre>
  
  <p>For an example of what I am trying to do: The following page, prints out the value of numberImThinkingOf, by creating a new paragraph element every time the submit button is pressed.</p>
  
  <p>So with out the extension it will print out</p>
  
  <ul>
  <li>Value: 5</li>
  <li>Value: 5</li>
  <li>Value: 5</li>
  </ul>
  
  <p>If pressed three times.</p>
  
  <p>However I want my Safari Extension to change the default value of the numberImThinkingOf variable once all DOM elements are loaded, to that specified in myscript.js So that when I press the submit button it will output:</p>
  
  <ul>
  <li>Value: 999</li>
  </ul>
  
  <p>Ideally I don't want to manipulate the DOM so that it inserts another script element. I originally though that javascript attached variables to the window object. But I guess I was wrong. Event if I have a script such as</p>
  
  <pre><code>$(document).ready(function(){
      alert(numberImThinkingOf)
  });
  </code></pre>
  
  <p>It returns undefined. :( Any help would me much appreciated.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
      &lt;script&gt;
      var numberImThinkingOf = 5;
      function whatNumber(){
          var newElement = document.createElement("p");
          newElement.textContent = "Value: "+numberImThinkingOf;
          document.body.insertBefore(newElement, document.body.firstChild);
      }
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;input type="submit" value="Continue &amp;rarr;" onclick="whatNumber()" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>