Last active
June 14, 2021 22:11
-
-
Save johanbove/2a46d4d3d26a11422986419c238a11c7 to your computer and use it in GitHub Desktop.
Web Monetization snippet
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
<div class="row"> | |
<div class="col-md-12"> | |
<!-- Testing Web Monetization --> | |
<div id="web-monetization" style="text-align:center;margin:2em;">This site is web monetization enabled. <a href="https://webmonetization.org/" rel="noopener noreferrer" style="text-decoration:underline">Learn more about Web Monetization</a>.</p></div> | |
<script> | |
const adCode = '<p>My site is <a href="https://webmonetization.org/" rel="noopener noreferrer">web monetization</a> enabled. Please consider supporting me through <a href="https://coil.com" rel="noopener noreferrer" style="text-decoration:underline">Coil.com</a>.</p>' | |
function showAds () { | |
document.getElementById('web-monetization').innerHTML = adCode | |
} | |
function removeAds () { | |
document.getElementById('web-monetization').innerHTML = '<p><strong>Thank you ❤️</strong> for your generous support using <a href="https://webmonetization.org/" rel="noopener noreferrer" style="text-decoration:underline">web monetization</a>! Welcome to the future of the web! 🤩 🤘</p>' | |
} | |
let hasPaid = false | |
if (document.monetization) { | |
document.monetization.addEventListener('monetizationstart', () => { | |
hasPaid = true | |
removeAds() | |
}) | |
} | |
window.addEventListener('load', () => { | |
if (!document.monetization) { | |
showAds() | |
} else { | |
setTimeout(() => { | |
if (!hasPaid) { | |
showAds() | |
} | |
}, 3000) | |
} | |
}) | |
</script> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment