// Copyright 2018 The Distill Template Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. import { Template } from '../mixins/template'; // This overlay is not secure. // It is only meant as a social deterrent. const productionHostname = 'distill.pub'; const T = Template('d-interstitial', `

This article is in review.

Do not share this URL or the contents of this article. Thank you!

Enter the password we shared with you as part of the review process to view the article.

`); export class Interstitial extends T(HTMLElement) { connectedCallback() { if (this.shouldRemoveSelf()) { this.parentElement.removeChild(this); } else { const passwordInput = this.root.querySelector('#interstitial-password-input'); passwordInput.oninput = (event) => this.passwordChanged(event); } } passwordChanged(event) { const entered = event.target.value; if (entered === this.password) { console.log('Correct password entered.'); this.parentElement.removeChild(this); if (typeof(Storage) !== 'undefined') { console.log('Saved that correct password was entered.'); localStorage.setItem(this.localStorageIdentifier(), 'true'); } } } shouldRemoveSelf() { // should never be visible in production if (window && window.location.hostname === productionHostname) { console.warn('Interstitial found on production, hiding it.'); return true } // should only have to enter password once if (typeof(Storage) !== 'undefined') { if (localStorage.getItem(this.localStorageIdentifier()) === 'true') { console.log('Loaded that correct password was entered before; skipping interstitial.'); return true; } } // otherwise, leave visible return false; } localStorageIdentifier() { const prefix = 'distill-drafts' const suffix = 'interstitial-password-correct'; return prefix + (window ? window.location.pathname : '-') + suffix } }