Skip to content

Instantly share code, notes, and snippets.

@andresbravog
Last active June 25, 2020 12:13
Show Gist options
  • Save andresbravog/8e2e2366b1796c2be3d7dac9b0328810 to your computer and use it in GitHub Desktop.
Save andresbravog/8e2e2366b1796c2be3d7dac9b0328810 to your computer and use it in GitHub Desktop.
Do not allow to play video player unless user is logged in
(() => {
const intellumStopIframe = () => {
function getCookie(name) {
if (!name) { return false; }
if (!document.cookie) { return false; }
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) { return parts.pop().split(';').shift(); }
}
function openLogin() {
const loginButton = document.querySelector('button.button--appheader');
if (!loginButton) { return false; }
loginButton.click();
return false;
}
if (!getCookie('user_id_for_loggin')) {
// User is not logged in
const videoIframe = document.querySelector('.pgpost iframe[data-lock-until-loging]');
if (videoIframe) {
const iframeWrapper = videoIframe.parentElement;
iframeWrapper.style = 'position: relative; margin: auto;';
const tribeRenderEl = document.createElement('div');
tribeRenderEl.classList.add('exceed-iframe-click-stopper');
tribeRenderEl.style = 'position: absolute; z-index: 150; width: 100%; height: 100%; top: 0;';
iframeWrapper.appendChild(tribeRenderEl);
tribeRenderEl.addEventListener('click', (event) => {
event.preventDefault();
event.stopPropagation();
openLogin();
return false;
});
}
}
}
if (document.readyState && document.readyState === 'complete') {
intellumStopIframe();
} else {
window.addEventListener('load', intellumStopIframe);
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment