1. Daniel Davis
  2. I'm Not Here

Commits

Daniel Davis  committed dd52934

Added the ability to change accuracy.

  • Participants
  • Parent commits 4593818
  • Branches default

Comments (0)

Files changed (4)

File config.xml

View file
 <?xml version='1.0' encoding='utf-8'?>
 <widget xmlns="http://www.w3.org/ns/widgets" id="ImNotHere" defaultlocale="en" version="1.0">
   <name>I'm not here</name>
-  <description xml:lang="en">Take control of geolocation data by overriding your browser's location when websites ask. Set your coordinates in the Preferences. A good test site is: http://html5demos.com/geo</description>
+  <description xml:lang="en">Fake your location by overriding your browser's geolocation data. Set your coordinates and accuracy you desire in the Preferences. A good test site is: http://html5demos.com/geo</description>
   <author href="http://people.opera.com/danield/">Daniel Davis (@ourmaninjapan)</author>
   <icon src="images/icon_64.png"/>
   <preference name="latitude" value="59.928312848885064"/>
   <preference name="longitude" value="10.754767656326294"/>
+  <preference name="accuracy" value="100"/>
 </widget>

File includes/injected.js

View file
     var prefs = JSON.parse(event.data);
     ImNotHere.position.coords.latitude = prefs.latitude;
     ImNotHere.position.coords.longitude = prefs.longitude;
+    ImNotHere.position.coords.accuracy = prefs.accuracy;
 };
 
 // Override the geolocation methods

File options.html

View file
         <legend>I'm Not Here: Preferences</legend>
         <label for="txt_latitude">Latitude:</label> <input type="text" id="txt_latitude">
         <label for="txt_longitude">Longitude:</label> <input type="text" id="txt_longitude">
+        <label for="txt_accuracy">Accuracy:</label> <input type="text" id="txt_accuracy">
         <button id="btn_save"><img src="images/save.png" width="24" height="24" alt="Save"> Save</button>
     </fieldset>
 </form>

File scripts/options.js

View file
 window.addEventListener('DOMContentLoaded', function() {
     var btn_save = document.getElementById('btn_save');
+    var options = ['latitude', 'longitude', 'accuracy'];
+    
+    for (var i = 0, option; option = options[i]; i++) {
+        document.getElementById('txt_' + option).value = widget.preferences[option];
+    }
+    
+    /*
     var txt_latitude = document.getElementById('txt_latitude');
     var txt_longitude = document.getElementById('txt_longitude');
+    var txt_accuracy = document.getElementById('txt_accuracy');
     
     txt_latitude.value = widget.preferences['latitude'];
     txt_longitude.value = widget.preferences['longitude'];
+    */
     
     function doSave() {
-        widget.preferences['latitude'] = txt_latitude.value;
-        widget.preferences['longitude'] = txt_longitude.value;
+        //widget.preferences['latitude'] = txt_latitude.value;
+        //widget.preferences['longitude'] = txt_longitude.value;
+        
+        for (var i = 0, option; option = options[i]; i++) {
+            widget.preferences[option] = document.getElementById('txt_' + option).value;
+        }
     }
     
     btn_save.onclick = doSave;