Last active
August 27, 2021 21:46
-
-
Save mjradwin/d0b1e8096184c0452c7d6ff651fa85ad to your computer and use it in GitHub Desktop.
Hebcal Shabbat API with AJAX
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
<!DOCTYPE html> | |
<html><head> | |
<meta charset="UTF-8"> | |
<title>Example</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
<body> | |
<div id="results"></div> | |
<script> | |
document.addEventListener('DOMContentLoaded', function() { | |
function formatHebcalShabbatEvents() { | |
const response = JSON.parse(this.responseText); | |
var arr = response.items.map(function(x) { | |
if (typeof x === 'object' && typeof x.category === 'string') { | |
if (x.category === 'candles') { | |
return x.title; | |
} else if (x.category === 'parashat') { | |
return 'Torah portion: <a href="' + x.link + '">' + x.title + '</a>'; | |
} else if (x.category === 'havdalah') { | |
return x.title.replace(/\s+\(\d+ min\)/, ''); | |
} else { | |
return x.title; | |
} | |
} | |
}); | |
arr = arr.filter(function(n){ return n != undefined }); | |
var html = arr.map(function(x) { return '<li>' + x + '</li>\n'; }).join(''); | |
document.getElementById('results').innerHTML = '<ul>' + html + '</ul>'; | |
} | |
var oReq = new XMLHttpRequest(); | |
oReq.addEventListener("load", formatHebcalShabbatEvents); | |
oReq.open("GET", "http://www.hebcal.com/shabbat/?geo=geoname&geonameid=5128581&m=50&cfg=json"); | |
oReq.send(); | |
}); | |
</script> | |
</body> | |
</html> |
In line 9, missing http: before //ajax.... ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can HEBCAL be made to be a callback function so a date can be displayed in the Roman calendar OR the hebrew one and the user can input either?