Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created April 29, 2020 02:36
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 hitode909/d5292edf5def11cd316314ce28d0c00b to your computer and use it in GitHub Desktop.
Save hitode909/d5292edf5def11cd316314ce28d0c00b to your computer and use it in GitHub Desktop.
<p><button id="masawada-cast-button" style="display: none">masawada castを開始する</button>
<div id="masawada-cast-button-not-supported" style="display: none">お使いのブラウザは<a href="https://developer.mozilla.org/en-US/docs/Web/API/Presentation_API" target="_blank">Presentation API</a>に対応していないようです</div>
</p>
<script>
(function () {
const button = document.querySelector('#masawada-cast-button');
const error = document.querySelector('#masawada-cast-button-not-supported');
const show = function () {
button.style.display = 'block';
};
const hide = function () {
error.style.display = 'block';
};
try {
const request = new PresentationRequest(['https://files.sushi.money/working-masawada.html']);
navigator.presentation.defaultRequest = request;
request.getAvailability().then(function (availability) {
if (!availability) {
hide();
return;
}
show();
button.addEventListener('click', function () {
request.start();
});
}).catch(function () {
hide();
});
} catch (error) {
hide();
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment