Skip to content

Instantly share code, notes, and snippets.

@mjradwin
Last active August 27, 2021 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjradwin/d0b1e8096184c0452c7d6ff651fa85ad to your computer and use it in GitHub Desktop.
Save mjradwin/d0b1e8096184c0452c7d6ff651fa85ad to your computer and use it in GitHub Desktop.
Hebcal Shabbat API with AJAX
<!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>
@seanrawles
Copy link

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?

@CVBruce
Copy link

CVBruce commented Apr 27, 2017

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