/* eslint-disable */ !(function() { var PAYWALLZ_SITE_ID = '52104796'; var PAYWALLZ_SITE_KEY = 'pw_bOZOFHUYvuAA4KWMsEUS'; var PAYWALLZ_PAGES = [{"id":10001634,"path":"/writing","includes_page":true,"includes_subpages":true}]; var PAYWALLZ_HUD_POSITION = {"bottom":0,"left":"16px"}; // TODO add alternate_domain var PAYWALLZ_TARGET_ORIGIN = 'https://api.mmbr.io'; var PAYWALLZ_COMPARE_DOMAIN = 'www.sabinehossenfelder.com'; var PAYWALLZ_MESSAGE_DOMAIN = 'https://' + 'www.sabinehossenfelder.com'; var PAYWALLZ_SERVER_PAINTER = 'https://api.mmbr.io/painter/v1'; var PAYWALLZ_SERVER_CLERK = 'https://api.mmbr.io/clerk/v1'; var PAYWALLZ_SERVER_WAITER = 'https://api.mmbr.io/waiter/v1'; var PAYWALLZ_SERVER_BOUNCER = 'https://api.mmbr.io/bouncer'; var PAYWALLZ_SITE_NAME = 'Homepage' var PAYWALLZ_USER = {"has_access":false}; var PAYWALLZ_CURRENT_PATH = decodeURIComponent(window.location.pathname.replace(/\/$/, '').trim()); var PAYWALLZ_SHARE_KEY = decodeURIComponent(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURIComponent('share_key').replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")); var ua = window.navigator.userAgent; var iOSSafari = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i) && !!ua.match(/WebKit/i) && !ua.match(/CriOS/i); var payload = { isPageProtected: isPageProtected(), isUserAllowed: isUserAllowed(), path: window.location.pathname, href: window.location.href, user: PAYWALLZ_USER, shareKey: PAYWALLZ_SHARE_KEY && PAYWALLZ_SHARE_KEY.length > 0 ? PAYWALLZ_SHARE_KEY : false }; window.addEventListener('load', function(event) { if (payload.isPageProtected && !payload.shareKey && !payload.isUserAllowed) { var curtain = addCurtain(); } var paywall = addPaywall(); var sync = paywallSync(payload, paywall); paywall.addEventListener('load', sync(true), false); window.addEventListener('hashchange', sync(false), false); window.addEventListener('popstate', sync(false), false); window.addEventListener('message', function(event) { if (event.origin === (PAYWALLZ_TARGET_ORIGIN)) { switch (event.data.action) { case 'LOGIN': var returnTo = encodeURIComponent(window.location.href); var url = PAYWALLZ_SERVER_BOUNCER + '/login?returnTo=' + returnTo; if (event.data.email) { url = url + '&email=' + encodeURIComponent(event.data.email); } if (PAYWALLZ_SITE_ID) { url = url + '&context=site_' + PAYWALLZ_SITE_ID; } window.location.href = url; break; case 'REGISTER': var returnTo = encodeURIComponent(window.location.href); var url = PAYWALLZ_SERVER_BOUNCER + '/register?returnTo=' + returnTo; if (event.data.email) { url = url + '&email=' + encodeURIComponent(event.data.email); } if (PAYWALLZ_SITE_ID) { url = url + '&context=site_' + PAYWALLZ_SITE_ID; } window.location.href = url; break; case 'LOGOUT': var returnTo = encodeURIComponent(window.location.href); var url = PAYWALLZ_SERVER_BOUNCER + '/logout?returnTo=' + returnTo; window.location.href = url; break; case 'PROTECT': protect() break; case 'HAS_ACCESS': window.location.reload(); break; case 'OVERLAY_DOWN': if (curtain) { curtain.parentNode.removeChild(curtain); } break; case 'GO_BACK': if (PAYWALLZ_CURRENT_PATH === window.location.origin) { window.history.go(-1); } else { window.location.assign(window.location.origin); } break; case 'CURTAIN_UP': paywall.style.width = '100%'; paywall.style.height = '100%'; if (iOSSafari) { paywall.style.position = 'absolute'; } break; case 'CURTAIN_DOWN': paywall.style.width = '189px'; paywall.style.height = '80px'; paywall.style.position = 'fixed'; break; }; } }, false); }); function protect() { var content = (document.querySelectorAll('.paywallz_content') || []); if (content.length === 0) { for (var i = 0; i < document.body.children.length; i++) { var child = document.body.children[i]; if (child.id !== 'paywallz-overlay' && child.id !== 'paywallz-iframe') { document.body.removeChild(child); } } } else { var protectedElements = document.querySelectorAll('.paywallz_content'); for (var i = 0, l = protectedElements.length; i < l; i++) { protectedElements[i].parentNode.removeChild(protectedElements[i]); } } } function paywallSync(payload, paywall) { return function(init) { return function() { payload.action = init ? 'INIT' : 'SYNC'; payload.shareKey = init ? payload.shareKey : undefined; paywall.contentWindow.postMessage(payload, PAYWALLZ_TARGET_ORIGIN); } } } function isPageProtected() { // TODO add alternate_domain var host = PAYWALLZ_COMPARE_DOMAIN.substring(2, PAYWALLZ_COMPARE_DOMAIN.length); if (PAYWALLZ_COMPARE_DOMAIN.substring(0, 2) === '*.' ? window.location.host.lastIndexOf(host) === window.location.host.length - host.length : PAYWALLZ_COMPARE_DOMAIN === window.location.host) { for (var i = 0; i < PAYWALLZ_PAGES.length; i++) { var page = PAYWALLZ_PAGES[i]; let is_protected_subpage = false; let is_protected_page = false; if (page.path === '/') { is_protected_subpage = page.includes_subpages && PAYWALLZ_CURRENT_PATH.indexOf(page.path) === 0 && PAYWALLZ_CURRENT_PATH.length > 1; is_protected_page = page.includes_page && (PAYWALLZ_CURRENT_PATH === '' || PAYWALLZ_CURRENT_PATH === '/'); } else { // the page exactly matches the start of the current path and the character immediately after is a slash and the path continues // ie. /videos should match /videos/2 but not /videos, /videos-2, or /videos/ is_protected_subpage = page.includes_subpages && (PAYWALLZ_CURRENT_PATH.lastIndexOf(page.path, 0) === 0 && PAYWALLZ_CURRENT_PATH[page.path.length] === '/' && PAYWALLZ_CURRENT_PATH.length > page.path.length + 1); // exact match or last character of current path === / and the path without it is an exact match (ie. /videos should match /videos/) is_protected_page = page.includes_page && (PAYWALLZ_CURRENT_PATH === page.path || (PAYWALLZ_CURRENT_PATH.slice(-1) === '/' && PAYWALLZ_CURRENT_PATH.length === page.path.length + 1 && PAYWALLZ_CURRENT_PATH.indexOf(page.path) === 0)); } if (is_protected_subpage || is_protected_page) { return true; } } return false; } return; } function isUserAllowed() { return PAYWALLZ_USER.has_access; } var paywallObserver; function addPaywall() { let existing = document.getElementById('paywallz-iframe'); if (existing) { return } var iframe = document.createElement('iframe'); iframe.src = PAYWALLZ_SERVER_PAINTER + '/paywall?key=pw_bOZOFHUYvuAA4KWMsEUS&protocol=' + encodeURIComponent(window.location.protocol); iframe.name = 'paywallz-paywall'; iframe.id = 'paywallz-iframe'; iframe.style.width = '189px'; iframe.style.height = '80px'; iframe.style.position = 'fixed'; iframe.style.border = 'none'; iframe.style.zIndex = 100000; for (var p in PAYWALLZ_HUD_POSITION) { iframe.style[p] = PAYWALLZ_HUD_POSITION[p]; } document.body.appendChild(iframe); return iframe; } function addCurtain() { var curtain = document.createElement('div'); var image = document.createElement('img'); curtain.id = 'paywallz-overlay'; curtain.setAttribute('style', 'position:fixed;height:100%;width:100%;top:0;left:0;z-index:99999;background-color:rgba(38, 50, 56, 0.95);'); image.setAttribute('style', 'position:absolute;height:200px;width:200px;top:0;right:0;bottom:0;left:0;margin:auto;border-radius:100px;border:2px solid #FAFAFA;'); image.setAttribute('src', 'https://pwlz-assets.s3.us-west-2.amazonaws.com/images/sites/1560522116702_u1_978-3-10-397246-7.66536937.jpg'); curtain.appendChild(image); document.body.appendChild(curtain); curtain.addEventListener('contextmenu', function(e) { e.preventDefault() }, false); if (MutationObserver) { if (paywallObserver) { paywallObserver.disconnect(); paywallObserver = null; } paywallObserver = new MutationObserver(function(mutations) { var curtainRemoved = false; for (var i = 0; i < mutations.length; i++) { var mutation = mutations[i];; if (mutation.removedNodes.length > 0) { for (var x = 0; x < mutation.removedNodes.length; x++) { if (mutation.removedNodes[x].id === 'paywallz-overlay') { curtainRemoved = true; break; } } } if (curtainRemoved) { addPaywall(); break; } } }); paywallObserver.observe(document.body, { childList: true }); } return curtain; } })();