(() => { const NONE_ACCESS_ID_TRAININGS = 123; const NONE_ACCESS_ID_COURSE = 123; const CLASS_USER_AUTH = 'gc-user-user'; const CLASS_USER_ADMIN = 'gc-user-admin'; const checkAccessUrl = () => { const noneAccessPath = [ '/sales/control/userProduct/my', '/sales/control/participant/me/part/deals', '/sales/control/participant/me/part/referrals', '/sales/control/participant/me/part/ad-offers', '/pl/webinar/show', '/pl/webinar/show/index' ]; const path = location.pathname; if (noneAccessPath.indexOf(path) === -1) { return true; } else { return false; } }; const checkSourceCourse = () => { const sourceCoursePath = [ '/src-main', '/src-library', '/src-library/cases', '/src-library/faq', '/teach/control/stream/view/id/657010886' ]; const sourceCourseSearch = [ '?id=257877913', '?id=257877920', '?id=257877934', '?id=257877932', '?id=257877936', '?id=257877927', '?id=257876968', '?id=257877939', '?id=257877941' ]; const path = location.pathname; const search = location.search; if (sourceCoursePath.indexOf(path) !== -1) { return true; } else { if (path === '/pl/teach/control/lesson/view' && sourceCourseSearch.indexOf(search) !== -1) { return true; } else { return false; } } }; const tmpStyleFonts = () => { return (``); }; const tmpStyles = () => { return (``); }; const tmpMenu = () => { const avatar = window.accountUserThumbnail; const name = window.accountSafeUserName.split(' ')[0]; const isCheckSourceCourse = checkSourceCourse(); return (`
`); }; const hiddenDefaultMenu = () => { return (``); }; const getIdURL = () => { const collection = location.pathname.split('/'); let lastElement = collection[collection.length - 1]; if (lastElement === '') { lastElement = collection[collection.length - 2]; } return Number(lastElement); }; const getMail = (elements) => { return elements[0].nextSibling.data.trim().split(':\n\t\t')[1].trim(); }; const getCollectionRefferals = (cb) => { const url = 'https://5-quantum.com/user/my/profile'; const selector = '[action="/user/my/profile"] > div > .row > strong'; fetch(url) .then(function (response) { return response.text() }) .then(function (html) { let parser = new DOMParser(); let doc = parser.parseFromString(html, "text/html"); let docArticle = doc.querySelectorAll(selector); let countRefferals = cb(docArticle); const profileEmail = document.querySelector('.cst-lk-menu-header__profile-email'); if (profileEmail !== undefined) { profileEmail.textContent = countRefferals; } else { profileEmail.textContent = ''; } return countRefferals; }) .catch(function (err) { console.log('Failed to fetch page: ', err); }); }; const renderMenu = (tmp, styles) => { const defaultLeftBar = document.querySelector('.gc-account-leftbar'); defaultLeftBar.style.display = 'none'; document.body.insertAdjacentHTML('beforeend', styles()); document.body.insertAdjacentHTML('beforeend', tmp()); }; const initToggleMobileMenu = () => { const CLASS_OVERFLOW_HIDDEN = 'body-overflow-hidden'; const CLASS_CLOSE_NAV_BTN = 'cst-lk-menu-mobile-toggle__btn--close'; const CLASS_OPEN_NAV = 'cst-lk-menu--open'; const btn = document.querySelector('.cst-lk-menu-mobile-toggle__btn'); const navInner = document.querySelector('.cst-lk-menu'); btn.addEventListener('click', () => { btn.classList.toggle(CLASS_CLOSE_NAV_BTN); navInner.classList.toggle(CLASS_OPEN_NAV); document.body.classList.toggle(CLASS_OVERFLOW_HIDDEN); }); }; const initMenu = () => { document.body.insertAdjacentHTML('beforeend', hiddenDefaultMenu()); let checkDEFAULTNav = setInterval(function () { if (document.querySelector('.gc-account-leftbar')) { renderMenu(tmpMenu, tmpStyles); clearInterval(checkDEFAULTNav); } }, 50); let checkCSTNav = setInterval(function () { if (document.querySelector('.cst-lk-menu-mobile-toggle__btn')) { initToggleMobileMenu(); getCollectionRefferals(getMail) clearInterval(checkCSTNav); } }, 100); }; const renderLessonInterface = (pageHeaderLink, pageBreacrumb) => { const collectionPageHeaderLink = pageHeaderLink.href.split('/'); let lastElementPageHeaderLink = Number(collectionPageHeaderLink[collectionPageHeaderLink.length - 1]); if (lastElementPageHeaderLink === '') { lastElementPageHeaderLink = Number(collectionPageHeaderLink[collectionPageHeaderLink.length - 2]); } const arrPageBreadcrumb = Array.from(pageBreacrumb); // const collectionBreacrumb = arrPageBreadcrumb[pageBreacrumb.length - 1].href.split('&editMode=0')[0].split('view?id='); const collectionBreacrumb = arrPageBreadcrumb[pageBreacrumb.length - 1].href.split('view?id='); let lastElementCollectionBreacrumb = Number(collectionBreacrumb[collectionBreacrumb.length - 1]); if (lastElementCollectionBreacrumb === '') { lastElementCollectionBreacrumb = Number(collectionBreacrumb[collectionBreacrumb.length - 2]); } if (lastElementPageHeaderLink === NONE_ACCESS_ID_TRAININGS || lastElementCollectionBreacrumb === NONE_ACCESS_ID_TRAININGS) { } else { document.body.insertAdjacentHTML('beforeend', hiddenDefaultMenu()); let checkDEFAULTNav = setInterval(function () { if (document.querySelector('.gc-account-leftbar')) { renderMenu(tmpMenu, tmpStyles); clearInterval(checkDEFAULTNav); } }, 50); let checkCSTNav = setInterval(function () { if (document.querySelector('.cst-lk-menu-mobile-toggle__btn')) { initToggleMobileMenu(); getCollectionRefferals(getMail) clearInterval(checkCSTNav); } }, 100); } }; const renderNoneAccessLessonInterface = () => { const firstBreadcrumb = document.querySelectorAll('.breadcrumbs a')[0]; if (firstBreadcrumb) { const firstBreadcrumbLink = firstBreadcrumb.href; const collectionPaths = firstBreadcrumbLink.split('/'); const idTraining = Number(collectionPaths[collectionPaths.length - 1]); if (idTraining !== NONE_ACCESS_ID_COURSE && accessLessonTitle.textContent === 'Нет доступа') { initMenu(); } } }; const renderTrainingInterface = () => { initMenu(); }; const initApp = () => { const pageHeaderLink = document.querySelector('.page-header h1 a'); const pageBreacrumb = document.querySelectorAll('.breadcrumb a'); const gcMainContent = document.querySelector('.gc-main-content'); const accessLessonTitle = document.querySelector('.main-page-block .container h3'); // gcMainContent.classList.remove(CLASS_USER_ADMIN); // gcMainContent.classList.add(CLASS_USER_AUTH); let isUser = gcMainContent.classList.contains(CLASS_USER_AUTH); const isNoneAccessPage = checkAccessUrl(); if (isNoneAccessPage) { if (isUser) { const currentID = getIdURL(); document.body.insertAdjacentHTML('afterbegin', tmpStyleFonts()); if (currentID !== NONE_ACCESS_ID_TRAININGS && !pageHeaderLink) { renderTrainingInterface(); } else if (pageHeaderLink) { renderLessonInterface(pageHeaderLink, pageBreacrumb); } else if (accessLessonTitle) { renderNoneAccessLessonInterface(); } } } }; initApp(); })();