Skip to content

Instantly share code, notes, and snippets.

@blakecrosby
Last active July 28, 2020 18:20
Show Gist options
  • Save blakecrosby/e8d830a364469b6bf62a3ef9720e11a6 to your computer and use it in GitHub Desktop.
Save blakecrosby/e8d830a364469b6bf62a3ef9720e11a6 to your computer and use it in GitHub Desktop.
<!-- Insert this code at the bottom of your Drupal PHP template -->
<script type='text/javascript'>
(function() {
function loadConfig (config) {
var el = document.createElement('script');
el.type = 'application/json';
el.id = 'laterpay-connector';
el.innerHTML = JSON.stringify(config);
document.head.appendChild(el);
}
function loadScript (url) {
var el = document.createElement('script');
el.type = 'text/javascript';
el.src = url;
document.head.appendChild(el);
}
function writeArticleID () {
var el = document.createElement('meta');
el.setAttribute('name', 'laterpay:connector:article_id');
el.content = "paid";
document.head.appendChild(el);
}
var pathname = window.location.href;
var isArticle = pathname.indexOf('/article/') > -1 && pathname.indexOf('/article/2020/mar/29/chronicle-thank-you-h-f') === -1;
var isBlogPost = pathname.indexOf('/blog/') > -1;
var isLoggedIn = document.body.classList.contains('logged-in');
// Only show the paywall on articles or blog posts and if the user isn't logged in
if ((isArticle || isBlogPost) && !isLoggedIn) {
loadConfig({
appearance: {
primaryColor: '#357CCE',
variant: 'raw-white'
}
});
writeArticleID();
loadScript('https://connector-script.uselaterpay.com/3-stable/us/prod/app-en-us.js');
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment