Skip to content

Instantly share code, notes, and snippets.

@ihorduchenko
Created December 1, 2021 16:48
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 ihorduchenko/f9cbec4622c9f52b4b6fb61977fb13ee to your computer and use it in GitHub Desktop.
Save ihorduchenko/f9cbec4622c9f52b4b6fb61977fb13ee to your computer and use it in GitHub Desktop.
Strict page content based on license key, stored in Google Sheets
<script defer="defer">
// Format of table is here: http://prntscr.com/219q3nl
const myDomain = window.location.hostname;
const myLicenseKey = '{{ settings.license_key | strip }}';
fetch('https://sheets.googleapis.com/v4/spreadsheets/1JO15y71ImOijJ4rcdMV7avZT5Y5lILkZin6emwg35D0/values/Keys!A2:B10000?key=AIzaSyBxbARr6-hAqdtZXXqSqDPmzap7EULYaFg')
.then(response => response.text())
.then(data => {
let resp = JSON.parse(data);
let respKeys = resp.values;
let allKeys = [];
respKeys.map(key => {
let pair = {
key: key[0],
domain: key[1]
}
allKeys.push(pair);
})
var targetKey = allKeys.filter(obj => {
return obj.key === myLicenseKey
});
if (targetKey.length > 0 && targetKey[0].domain.includes(myDomain)) {
console.log('Your license key is correct, happy using!');
} else {
document.body.innerHTML = '<div style="padding:50px;text-align:center;">Please, <a href="mailto:support@web.site"><strong>email us</strong></a> to purchase your license key!</div>';
}
})
.catch(error => {
console.log(error)
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment