Created
March 17, 2018 03:45
-
-
Save bwedding/eefbdac4af57dfebf2d11a6da12047cd to your computer and use it in GitHub Desktop.
Will modify any text fitting this patter {{city}}, to the current location or if it can't get location, it will change it to "in your area"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() | |
{ | |
var curCity = "In Your Area"; // You can change this to fit your needs | |
var curState = ""; // No default state | |
$.getJSON('//freegeoip.net/json/?callback=?', | |
function(location, textStatus, jqXHR) | |
{ | |
if(textStatus == "success") | |
{ | |
curCity = location.city; | |
curState = location.region_name; | |
} | |
$("body *").contents().each(function() | |
{ | |
if(this.nodeType == 3) // 3 are text elements | |
{ | |
// If you want to use another word | |
this.nodeValue = this.nodeValue.replace(/{{city}}/g, curCity); | |
// Uncomment this to also replace the state | |
// this.nodeValue = this.nodeValue.replace(/{{state}}/g, curState); | |
} | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment