Skip to content

Instantly share code, notes, and snippets.

@marzocchi
Last active April 5, 2018 14:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marzocchi/11354602 to your computer and use it in GitHub Desktop.
Save marzocchi/11354602 to your computer and use it in GitHub Desktop.
Chrome extension that overrides navigator.geolocation with Mocklocation in all pages
{
"manifest_version": 2,
"name": "Mocklocation",
"description": "Override navigator.geolocation with Mocklocation",
"version": "0.1",
"permissions": [
"http://*/*",
"https://*/*"
],
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["trigger.js"]
},
{
"matches": ["https://*/*"],
"js": ["trigger.js"]
}
]
}
(function(html) {
html.setAttribute('class', html.getAttribute('class') + ' mock-geolocation');
var head = html.querySelector('head');
var scripts = [
'//dl.dropboxusercontent.com/u/577031/mocklocation/mocklocation.js',
'//cdn.leafletjs.com/leaflet-0.7.2/leaflet.js'
];
var styles = [
'//dl.dropboxusercontent.com/u/577031/mocklocation/mocklocation.css',
'//cdn.leafletjs.com/leaflet-0.7.2/leaflet.css'
];
scripts.forEach(function(url) {
var script = document.createElement('script');
script.setAttribute('src', url);
head.insertBefore(script, head.firstChild);
});
styles.forEach(function(url) {
var style = document.createElement('link');
style.setAttribute('rel', 'stylesheet');
style.setAttribute('href', url);
head.insertBefore(style, head.firstChild);
});
}(document.querySelector('html')));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment