Skip to content

Instantly share code, notes, and snippets.

@torgeir torgeir/domains.js
Last active Jan 15, 2018

Embed
What would you like to do?
Naive available domain lookup
const domains = ["domain.no"];
const normalize = s => s.replace(/[^a-z]/g, "")
const status = d => new Promise(function (resolve, reject) {
const fn = `handle_result_${normalize(d)}`;
window[fn] = data => resolve(data);
const script = document.createElement("script");
script.src = `https://das2.hostpartner.no/das/${encodeURIComponent(d)}?callback=${encodeURIComponent(fn)}`;
script.onload = () => delete window[fn];
script.onerror = function (err) {
delete window[fn];
reject(err);
};
document.body.appendChild(script);
});
Promise.all(domains.map(status))
.then(results => results.map(({ domain, status }) => ({ domain, status })))
.then(console.log)
.catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.