diff --git a/absences/absences.js b/absences/absences.js index 76f5783..3a0fbf5 100644 --- a/absences/absences.js +++ b/absences/absences.js @@ -1,65 +1,14 @@ -function getCookie(name) { - const cookieName = `${name}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const cookieArray = decodedCookie.split(';'); - - for(let i = 0; i < cookieArray.length; i++) { - let cookie = cookieArray[i]; - while (cookie.charAt(0) === ' ') { - cookie = cookie.substring(1); - } - if (cookie.indexOf(cookieName) === 0) { - return cookie.substring(cookieName.length, cookie.length); - } - } - return null; -} - -function shortenSchoolName(name, maxLength = 50) { - if (!name) return ''; - if (name.length <= maxLength) return name; - - const parts = name.split(' - '); - if (parts.length === 2) { - const [code, fullName] = parts; - if (fullName.length > maxLength - code.length - 3) { - return `${code} - ${fullName.substring(0, maxLength - code.length - 6)}...`; - } - } - return name.substring(0, maxLength - 3) + '...'; -} - -async function waitForElement(selector) { - return new Promise(resolve => { - if (document.querySelector(selector)) { - return resolve(document.querySelector(selector)); - } - - const observer = new MutationObserver(mutations => { - if (document.querySelector(selector)) { - observer.disconnect(); - resolve(document.querySelector(selector)); - } - }); - - observer.observe(document.body, { - childList: true, - subtree: true - }); - }); -} - async function collectAbsencesData() { - await waitForElement('#HianyzasGrid'); + await helper.waitForElement('#HianyzasGrid'); await new Promise(resolve => setTimeout(resolve, 1000)); const basicData = { schoolInfo: { - name: getCookie('schoolName') || 'Iskola', - id: getCookie('schoolCode') || '' + name: cookieManager.get('schoolName') || 'Iskola', + id: cookieManager.get('schoolCode') || '' }, userData: { - name: getCookie('userName') || 'Felhasználó', + name: cookieManager.get('userName') || 'Felhasználó', time: document.querySelector('.usermenu_timer')?.textContent?.trim() || '45:00' } }; @@ -95,98 +44,12 @@ async function collectAbsencesData() { return { basicData, absences, groupedAbsences }; } -function showLoadingScreen() { - const loadingHTML = ` -
-
- -
Betöltés alatt...
-

Kis türelmet

-
-
- `; - - document.body.insertAdjacentHTML('beforeend', loadingHTML); -} - -function hideLoadingScreen() { - const loadingOverlay = document.querySelector('.loading-overlay'); - if (loadingOverlay) { - loadingOverlay.style.opacity = '0'; - loadingOverlay.style.transition = 'opacity 0.3s ease'; - setTimeout(() => loadingOverlay.remove(), 300); - } -} - async function transformAbsencesPage() { - showLoadingScreen(); const { basicData, absences, groupedAbsences } = await collectAbsencesData(); - - const schoolNameFull = `${basicData.schoolInfo.id} - ${basicData.schoolInfo.name}`; - const shortenedSchoolName = shortenSchoolName(schoolNameFull); - document.body.innerHTML = `
-
-
-

- - Firka -

-
- ${shortenedSchoolName} -
-
- - - - -
+ ${createTemplate.header()}
@@ -266,29 +129,15 @@ async function transformAbsencesPage() {
`; - - const links = [ - { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, - { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: true }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap' }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/icon?family=Material+Icons+Round' } - ]; - - links.forEach(link => { - const linkElement = document.createElement('link'); - Object.entries(link).forEach(([key, value]) => { - linkElement[key] = value; - }); - document.head.appendChild(linkElement); - }); + createTemplate.importFonts(); setupEventListeners(); setupFilters(); - hideLoadingScreen(); + loadingScreen.hide(); } -function setupEventListeners(data) { +function setupEventListeners() { const userBtn = document.querySelector('.user-dropdown-btn'); const userDropdown = document.querySelector('.user-dropdown'); @@ -300,35 +149,6 @@ function setupEventListeners(data) { document.addEventListener('click', () => { userDropdown?.classList.remove('show'); }); - - const timerEl = document.getElementById('logoutTimer'); - if (timerEl) { - const startTime = parseInt(timerEl.textContent?.match(/\d+/)?.[0] || "30"); - let timeLeft = startTime * 60; - - const updateTimer = () => { - const minutes = Math.floor(timeLeft / 60); - const seconds = timeLeft % 60; - timerEl.textContent = `${minutes}:${seconds.toString().padStart(2, '0')}`; - - if (timeLeft <= 0) { - window.location.href = '/Home/Logout'; - } else { - timeLeft--; - } - }; - - updateTimer(); - setInterval(updateTimer, 1000); - } - - - document.getElementById('settingsBtn')?.addEventListener('click', (e) => { - e.preventDefault(); - e.stopPropagation(); - const url = chrome.runtime.getURL('settings/index.html'); - window.open(url, '_blank', 'width=400,height=600'); - }); } function setupFilters() { diff --git a/dashboard/dashboard.js b/dashboard/dashboard.js index 93ad8de..1d235d7 100644 --- a/dashboard/dashboard.js +++ b/dashboard/dashboard.js @@ -1,17 +1,4 @@ const utils = { - shortenSchoolName(name, maxLength = 50) { - if (!name || name.length <= maxLength) return name || ''; - - const [code, fullName] = name.split(' - '); - if (fullName) { - const maxFullNameLength = maxLength - code.length - 3; - if (fullName.length > maxFullNameLength) { - return `${code} - ${fullName.substring(0, maxFullNameLength)}...`; - } - } - return `${name.substring(0, maxLength - 3)}...`; - }, - formatGradeValue(value) { return value?.trim() || ''; }, @@ -26,11 +13,9 @@ const utils = { const dateParts = dateStr.trim().split('.'); if (dateParts.length < 3) return dateStr; - const month = parseInt(dateParts[1], 10); const day = parseInt(dateParts[2], 10); - if (isNaN(month) || month < 1 || month > 12) return dateStr; const hungarianMonths = [ @@ -38,7 +23,6 @@ const utils = { 'július', 'augusztus', 'szeptember', 'október', 'november', 'december' ]; - return `${hungarianMonths[month - 1]} ${day}.`; } }; @@ -192,82 +176,18 @@ class DashboardUI { this.data = { ...data, schoolInfo: { - name: cookies.getCookie(COOKIE_KEYS.SCHOOL_NAME) || DEFAULT_VALUES.SCHOOL, - id: cookies.getCookie(COOKIE_KEYS.SCHOOL_CODE) || '' + name: cookieManager.get(COOKIE_KEYS.SCHOOL_NAME) || DEFAULT_VALUES.SCHOOL, + id: cookieManager.get(COOKIE_KEYS.SCHOOL_CODE) || '' }, userData: { - name: cookies.getCookie(COOKIE_KEYS.USER_NAME) || DEFAULT_VALUES.USER, + name: cookieManager.get(COOKIE_KEYS.USER_NAME) || DEFAULT_VALUES.USER, time: document.querySelector('.usermenu_timer')?.textContent?.trim() || DEFAULT_VALUES.TIMER } }; this.schoolNameFull = `${this.data.schoolInfo.id} - ${this.data.schoolInfo.name}`; - this.shortenedSchoolName = utils.shortenSchoolName(this.schoolNameFull); + this.shortenedSchoolName = helper.shortenSchoolName(this.schoolNameFull); } - - static generateHeaderHTML(data, schoolNameFull, shortenedSchoolName) { - return ` -
-
-

- - Firka -

-
- ${shortenedSchoolName} -
-
- - - - -
- `; - } generateMainContentHTML() { return `
@@ -369,59 +289,14 @@ class DashboardUI { render() { document.body.innerHTML = `
- ${DashboardUI.generateHeaderHTML(this.data, this.schoolNameFull, this.shortenedSchoolName)} + ${createTemplate.header()} ${this.generateMainContentHTML()}
`; setupUserDropdown(); - setupLogoutTimer(); } } - -function setupLogoutTimer() { - const timerElement = document.querySelector('.nav-logout-timer'); - if (!timerElement) return; - - const timeString = timerElement.textContent; - const startTime = parseInt(timeString?.match(/\d+/)?.[0] || "45"); - let timeLeft = startTime * 60; - - const updateTimer = () => { - const minutes = Math.floor(timeLeft / 60); - const seconds = timeLeft % 60; - timerElement.textContent = `${minutes}:${seconds.toString().padStart(2, '0')}`; - - if (timeLeft <= 0) { - window.location.href = '/Home/Logout'; - } - timeLeft--; - }; - - updateTimer(); - setInterval(updateTimer, 1000); -} - -class FontLoader { - static loadFonts() { - const links = [ - { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, - { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: true }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap' }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/icon?family=Material+Icons+Round' } - ]; - - links.forEach(link => { - const linkElement = document.createElement('link'); - Object.entries(link).forEach(([key, value]) => { - linkElement[key] = value; - }); - document.head.appendChild(linkElement); - }); - } -} - - class DashboardApp { constructor() { this.initialize(); @@ -433,7 +308,7 @@ class DashboardApp { try { const dataExtractor = new DashboardDataExtractor(); const dashboardData = dataExtractor.extractAll(); - FontLoader.loadFonts(); + createTemplate.importFonts(); const ui = new DashboardUI(dashboardData); ui.render(); } catch (error) { diff --git a/forgotpassword/forgotpassword.js b/forgotpassword/forgotpassword.js index 212a130..d87dbfe 100644 --- a/forgotpassword/forgotpassword.js +++ b/forgotpassword/forgotpassword.js @@ -1,9 +1,7 @@ (() => { const transformForgotPasswordPage = () => { - const isDarkMode = localStorage.getItem('darkMode') === 'true'; document.documentElement.setAttribute('data-theme', isDarkMode ? 'dark' : 'light'); - chrome.runtime.onMessage.addListener((message) => { if (message.action === 'toggleTheme') { @@ -11,7 +9,6 @@ localStorage.setItem('darkMode', message.darkMode); } }); - document.body.innerHTML = `
@@ -103,7 +100,6 @@ const form = event.target; const inputs = form.querySelectorAll('.form-control[required]'); let isValid = true; - inputs.forEach(input => { if (!validateInput(input, true)) { @@ -144,7 +140,6 @@ submitButton.disabled = false; } }; - if (window.location.href.includes('/Adminisztracio/ElfelejtettJelszo')) { transformForgotPasswordPage(); diff --git a/global/navigation.js b/global/navigation.js index f4c4c24..c1bccf2 100644 --- a/global/navigation.js +++ b/global/navigation.js @@ -11,26 +11,15 @@ const DEFAULT_VALUES = { TIMER: '45:00' }; -const cookies = { - getCookie(name) { - const value = `; ${document.cookie}`; - const parts = value.split(`; ${name}=`); - return parts.length === 2 ? parts.pop().split(';').shift() : null; - } -}; - - - - function updateHeaderInfo() { const schoolName = document.querySelector('.nav-school-name'); const userName = document.querySelector('.nav-user-name'); const logoutTimer = document.querySelector('.nav-logout-timer'); const userData = { - schoolName: cookies.getCookie(COOKIE_KEYS.SCHOOL_NAME) || DEFAULT_VALUES.SCHOOL, - schoolId: cookies.getCookie(COOKIE_KEYS.SCHOOL_CODE) || '', - name: cookies.getCookie(COOKIE_KEYS.USER_NAME) || DEFAULT_VALUES.USER, + schoolName: cookieManager.get(COOKIE_KEYS.SCHOOL_NAME) || DEFAULT_VALUES.SCHOOL, + schoolId: cookieManager.get(COOKIE_KEYS.SCHOOL_CODE) || '', + name: cookieManager.get(COOKIE_KEYS.USER_NAME) || DEFAULT_VALUES.USER, time: document.querySelector('.usermenu_timer')?.textContent?.trim() || DEFAULT_VALUES.TIMER }; @@ -95,7 +84,6 @@ function setupSettingsButton() { }); } - document.addEventListener('DOMContentLoaded', () => { updateHeaderInfo(); setupUserDropdown(); diff --git a/global/theme.js b/global/theme.js index c207134..a3b7d6a 100644 --- a/global/theme.js +++ b/global/theme.js @@ -1,40 +1,12 @@ (() => { - - function setCookie(name, value, days = 365) { - const date = new Date(); - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - const expires = `expires=${date.toUTCString()}`; - document.cookie = `${name}=${value}; ${expires}; path=/; domain=.e-kreta.hu`; - } - - function getCookie(name) { - const cookieName = `${name}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const cookieArray = decodedCookie.split(';'); - - for(let i = 0; i < cookieArray.length; i++) { - let cookie = cookieArray[i]; - while (cookie.charAt(0) === ' ') { - cookie = cookie.substring(1); - } - if (cookie.indexOf(cookieName) === 0) { - return cookie.substring(cookieName.length, cookie.length); - } - } - return null; - } - - function setTheme(theme) { try { - const actualTheme = theme === 'default' ? 'light-blue' : theme; document.documentElement.setAttribute('data-theme', actualTheme); - setCookie('themePreference', actualTheme); + cookieManager.set('themePreference', actualTheme); localStorage.setItem('themePreference', actualTheme); - chrome.runtime.sendMessage({ action: 'themeChanged', theme: actualTheme @@ -48,40 +20,31 @@ console.error('Error setting theme:', error); } } - function initializeTheme() { - - const cookieTheme = getCookie('themePreference'); + const cookieTheme = cookieManager.get('themePreference'); const localStorageTheme = localStorage.getItem('themePreference'); - const theme = cookieTheme || localStorageTheme || 'light-blue'; - setTheme(theme); - if (cookieTheme !== localStorageTheme) { if (cookieTheme) { localStorage.setItem('themePreference', cookieTheme); } else if (localStorageTheme) { - setCookie('themePreference', localStorageTheme); + cookieManager.set('themePreference', localStorageTheme); } } } - if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', () => { initializeTheme(); }); - initializeTheme(); } else { - initializeTheme(); } @@ -103,7 +66,7 @@ const observer = new MutationObserver((mutations) => { const currentTheme = document.documentElement.getAttribute('data-theme'); - const savedTheme = getCookie('themePreference') || localStorage.getItem('themePreference'); + const savedTheme = cookieManager.get('themePreference') || localStorage.getItem('themePreference'); if ((!currentTheme && savedTheme) || (currentTheme !== savedTheme && savedTheme)) { setTheme(savedTheme); diff --git a/grades/grades.css b/grades/grades.css index fd0e27e..e8153a2 100644 --- a/grades/grades.css +++ b/grades/grades.css @@ -60,6 +60,7 @@ body { background: var(--card-card); border-radius: 24px; box-shadow: 0px 1px var(--shadow-blur) 0px var(--accent-shadow); + width: calc(995px + 50px); } .average-details { display: flex; @@ -406,54 +407,6 @@ body { } } -.loading-screen { - position: fixed; - top: 0; - left: 0; - right: 0; - bottom: 0; - background-color: var(--background); - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - z-index: 9999; -} - -.loading-content { - display: flex; - flex-direction: column; - align-items: center; - gap: 1rem; -} - -.loading-logo { - width: 48px; - height: 48px; - border-radius: 16px; -} - -.loading-text { - color: var(--text-primary); - text-align: center; - font-family: Montserrat; - font-size: 20px; - font-style: normal; - font-weight: 700; - line-height: normal; -} - -.loading-text2 { - align-self: stretch; - color: var(--text-secondary); - text-align: center; - font-family: Figtree; - font-size: 16px; - font-style: normal; - font-weight: 500; - line-height: 130%; -} - .material-icons-round { font-size: 20px; vertical-align: middle; @@ -715,4 +668,8 @@ body { .semester-grades { width: 100%; } + + .overall-averages { + width: 100%; + } } \ No newline at end of file diff --git a/grades/grades.js b/grades/grades.js index ffbefe2..e42b048 100644 --- a/grades/grades.js +++ b/grades/grades.js @@ -1,52 +1,7 @@ (() => { - function getCookie(name) { - const cookieName = `${name}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const cookieArray = decodedCookie.split(';'); - - for(let i = 0; i < cookieArray.length; i++) { - let cookie = cookieArray[i]; - while (cookie.charAt(0) === ' ') { - cookie = cookie.substring(1); - } - if (cookie.indexOf(cookieName) === 0) { - return cookie.substring(cookieName.length, cookie.length); - } - } - return null; - } - - function showLoadingScreen() { - const existingLoadingScreen = document.querySelector('.loading-screen'); - if (existingLoadingScreen) return; - - const loadingScreen = document.createElement('div'); - loadingScreen.className = 'loading-screen'; - loadingScreen.innerHTML = ` -
- -
Betöltés alatt...
-
Kis türelmet!
-
- `; - document.body.appendChild(loadingScreen); - } - - function hideLoadingScreen() { - const loadingScreen = document.querySelector('.loading-screen'); - if (loadingScreen) { - loadingScreen.style.opacity = '0'; - loadingScreen.addEventListener('transitionend', () => { - loadingScreen.remove(); - }); - } - } - async function transformGradesPage() { try { - showLoadingScreen(); - - await waitForElement('#Osztalyzatok_7895TanuloErtekelesByTanuloGrid'); + await helper.waitForElement('#Osztalyzatok_7895TanuloErtekelesByTanuloGrid'); await new Promise(resolve => setTimeout(resolve, 1000)); const gradesData = extractGradesData(); @@ -55,36 +10,22 @@ document.body.innerHTML = generatePageHTML(gradesData, studentAverage, classAverage); - const links = [ - { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, - { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: true }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap' }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/icon?family=Material+Icons+Round' } - ]; - + createTemplate.importFonts(); const script = document.createElement('script'); script.src = chrome.runtime.getURL('grades/chart.js'); document.head.appendChild(script); - links.forEach(link => { - const linkElement = document.createElement('link'); - Object.entries(link).forEach(([key, value]) => { - linkElement[key] = value; - }); - document.head.appendChild(linkElement); - }); - script.onload = () => { setupGradesChart(gradesData.subjects); }; setupEventListeners(); - hideLoadingScreen(); + loadingScreen.hide(); } catch (error) { console.error('Error transforming grades page:', error); - hideLoadingScreen(); + loadingScreen.hide(); } } @@ -142,11 +83,11 @@ return { schoolInfo: { - id: getCookie('schoolCode') || '', - name: getCookie('schoolName') || 'Iskola' + id: cookieManager.get('schoolCode') || '', + name: cookieManager.get('schoolName') || 'Iskola' }, userData: { - name: getCookie('userName') || 'Felhasználó', + name: cookieManager.get('userName') || 'Felhasználó', time: document.querySelector('.usermenu_timer')?.textContent?.trim() || '45:00' }, subjects: subjects @@ -225,69 +166,15 @@ const gradeDistribution = calculateGradeDistribution(data.subjects); const semesterGrades = extractSemesterGrades(data.subjects); - const studentGradeLevel = Math.floor(studentAverage) || 0; const classGradeLevel = Math.floor(classAverage) || 0; + schoolNameFull = `${data.schoolInfo.id} - ${data.schoolInfo.name}`; + shortenedSchoolName = helper.shortenSchoolName(schoolNameFull); + return `
-
-
-

- - Firka -

-
- ${data.schoolInfo.id} - ${data.schoolInfo.name} -
-
- - -
+ ${createTemplate.header()}
@@ -561,27 +448,6 @@ } } - function waitForElement(selector) { - return new Promise(resolve => { - if (document.querySelector(selector)) { - return resolve(document.querySelector(selector)); - } - - const observer = new MutationObserver(mutations => { - if (document.querySelector(selector)) { - observer.disconnect(); - resolve(document.querySelector(selector)); - } - }); - - observer.observe(document.body, { - childList: true, - subtree: true - }); - }); - } - - if (window.location.href.includes('/TanuloErtekeles/Osztalyzatok')) { transformGradesPage(); } diff --git a/homework/homework.js b/homework/homework.js index cf86424..54e581b 100644 --- a/homework/homework.js +++ b/homework/homework.js @@ -1,65 +1,14 @@ -function getCookie(name) { - const cookieName = `${name}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const cookieArray = decodedCookie.split(';'); - - for(let i = 0; i < cookieArray.length; i++) { - let cookie = cookieArray[i]; - while (cookie.charAt(0) === ' ') { - cookie = cookie.substring(1); - } - if (cookie.indexOf(cookieName) === 0) { - return cookie.substring(cookieName.length, cookie.length); - } - } - return null; -} - -function shortenSchoolName(name, maxLength = 50) { - if (!name) return ''; - if (name.length <= maxLength) return name; - - const parts = name.split(' - '); - if (parts.length === 2) { - const [code, fullName] = parts; - if (fullName.length > maxLength - code.length - 3) { - return `${code} - ${fullName.substring(0, maxLength - code.length - 6)}...`; - } - } - return name.substring(0, maxLength - 3) + '...'; -} - -async function waitForElement(selector) { - return new Promise(resolve => { - if (document.querySelector(selector)) { - return resolve(document.querySelector(selector)); - } - - const observer = new MutationObserver(mutations => { - if (document.querySelector(selector)) { - observer.disconnect(); - resolve(document.querySelector(selector)); - } - }); - - observer.observe(document.body, { - childList: true, - subtree: true - }); - }); -} - async function collectHomeworkData() { - await waitForElement('#TanulotHaziFeladatkGrid'); + await helper.waitForElement('#TanulotHaziFeladatkGrid'); await new Promise(resolve => setTimeout(resolve, 1000)); const basicData = { schoolInfo: { - name: getCookie('schoolName') || 'Iskola', - id: getCookie('schoolCode') || '' + name: cookieManager.get('schoolName') || 'Iskola', + id: cookieManager.get('schoolCode') || '' }, userData: { - name: getCookie('userName') || 'Felhasználó', + name: cookieManager.get('userName') || 'Felhasználó', time: document.querySelector('.usermenu_timer')?.textContent?.trim() || '45:00' } }; @@ -93,29 +42,6 @@ async function collectHomeworkData() { return { basicData, homeworkItems, groupedHomework }; } -function showLoadingScreen() { - const loadingHTML = ` -
-
- -
Betöltés alatt...
-

Kis türelmet

-
-
- `; - - document.body.insertAdjacentHTML('beforeend', loadingHTML); -} - -function hideLoadingScreen() { - const loadingOverlay = document.querySelector('.loading-overlay'); - if (loadingOverlay) { - loadingOverlay.style.opacity = '0'; - loadingOverlay.style.transition = 'opacity 0.3s ease'; - setTimeout(() => loadingOverlay.remove(), 300); - } -} - function isTomorrow(dateStr) { if (!dateStr) return false; @@ -143,74 +69,16 @@ function isTomorrow(dateStr) { } async function transformHomeworkPage() { - showLoadingScreen(); + //loadingScreen.show(); const { basicData, homeworkItems, groupedHomework } = await collectHomeworkData(); const schoolNameFull = `${basicData.schoolInfo.id} - ${basicData.schoolInfo.name}`; - const shortenedSchoolName = shortenSchoolName(schoolNameFull); + const shortenedSchoolName = helper.shortenSchoolName(schoolNameFull); document.body.innerHTML = `
-
-
-

- - Firka -

-
- ${shortenedSchoolName} -
-
- - - - -
+ ${createTemplate.header()}
@@ -268,8 +136,7 @@ async function transformHomeworkPage() { setupFilters(homeworkItems, groupedHomework); setupUserDropdown(); - setupLogoutTimer(); - hideLoadingScreen(); + loadingScreen.hide(); } function renderHomeworkList(groupedHomework) { @@ -531,40 +398,8 @@ function setupUserDropdown() { document.addEventListener('click', () => { userDropdown?.classList.remove('show'); }); - - - document.getElementById('settingsBtn')?.addEventListener('click', (e) => { - e.preventDefault(); - e.stopPropagation(); - const url = chrome.runtime.getURL('settings/index.html'); - window.open(url, '_blank', 'width=400,height=600'); - }); } -function setupLogoutTimer() { - const timerElement = document.querySelector('.nav-logout-timer'); - if (!timerElement) return; - - const timeString = timerElement.textContent; - const startTime = parseInt(timeString?.match(/\d+/)?.[0] || "45"); - let timeLeft = startTime * 60; - - const updateTimer = () => { - const minutes = Math.floor(timeLeft / 60); - const seconds = timeLeft % 60; - timerElement.textContent = `${minutes}:${seconds.toString().padStart(2, '0')}`; - - if (timeLeft <= 0) { - window.location.href = '/Home/Logout'; - } - timeLeft--; - }; - - updateTimer(); - setInterval(updateTimer, 1000); -} - - if (window.location.href.includes('/Tanulo/TanuloHaziFeladat')) { transformHomeworkPage().catch(error => { console.error('Error transforming homework page:', error); diff --git a/login/login.js b/login/login.js index 6d49112..69b4c13 100644 --- a/login/login.js +++ b/login/login.js @@ -1,13 +1,11 @@ async function transformLoginPage() { try { - if (document.readyState !== 'complete') { await new Promise(resolve => { window.addEventListener('load', resolve); }); } - const existingForm = document.querySelector('form'); const formData = { action: existingForm?.getAttribute('action') || '', @@ -15,7 +13,6 @@ async function transformLoginPage() { instituteCode: document.querySelector('#instituteCode')?.value || '', requestToken: document.querySelector('input[name="__RequestVerificationToken"]')?.value || '' }; - const titleElement = document.querySelector('.page-title'); const schoolInfo = { @@ -23,7 +20,6 @@ async function transformLoginPage() { kretaId: '', omCode: '' }; - const spanElement = titleElement?.querySelector('span'); if (spanElement) { @@ -31,11 +27,9 @@ async function transformLoginPage() { schoolInfo.kretaId = lines[0] || ''; schoolInfo.omCode = (lines[1] || '').replace('KRÉTA azonosító: ', ''); } - const rawSystemMessage = document.querySelector('.alert-primary')?.textContent?.trim() || ''; const systemMessage = rawSystemMessage.replace('Rendszerértesítés', '').trim(); - const newHTML = ` `; - document.body.innerHTML = newHTML; - setupEventListeners(); @@ -117,7 +109,6 @@ function setupEventListeners() { const passwordInput = document.getElementById('Password'); const togglePasswordBtn = document.querySelector('.show-password'); const formInputs = document.querySelectorAll('.form-control'); - if (togglePasswordBtn && passwordInput) { togglePasswordBtn.addEventListener('click', () => { diff --git a/logout/logout.js b/logout/logout.js index 08048f3..78a3fee 100644 --- a/logout/logout.js +++ b/logout/logout.js @@ -1,21 +1,4 @@ (() => { - function getCookie(name) { - const cookieName = `${name}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const cookieArray = decodedCookie.split(';'); - - for(let i = 0; i < cookieArray.length; i++) { - let cookie = cookieArray[i]; - while (cookie.charAt(0) === ' ') { - cookie = cookie.substring(1); - } - if (cookie.indexOf(cookieName) === 0) { - return cookie.substring(cookieName.length, cookie.length); - } - } - return null; - } - function loadFonts() { // Create a new style element const style = document.createElement('style'); @@ -27,8 +10,8 @@ } function transformLogoutPage() { // Get current theme and school ID from cookies - const theme = getCookie('themePreference') || localStorage.getItem('themePreference') || 'light-blue'; - const instituteCode = getCookie('schoolSubdomain'); + const theme = cookieManager.get('themePreference') || localStorage.getItem('themePreference') || 'light-blue'; + const instituteCode = cookieManager.get('schoolSubdomain'); document.documentElement.setAttribute('data-theme', theme); // Create new HTML structure diff --git a/manifest.json b/manifest.json index 4b285af..1052048 100644 --- a/manifest.json +++ b/manifest.json @@ -27,8 +27,9 @@ "matches": [ "https://*.e-kreta.hu/*" ], - "js": ["global/maintenance.js", "global/theme.js", "global/navigation.js"], - "css": ["global/theme.css", "global/navigation.css"], + "js": ["tools/cookieManager.js", "tools/helper.js", "tools/loadingScreen.js", "tools/createTemplate.js", + "global/maintenance.js", "global/theme.js", "global/navigation.js"], + "css": ["tools/loadingScreen.css", "global/theme.css", "global/navigation.css"], "run_at": "document_start" }, { diff --git a/profile/profile.js b/profile/profile.js index 49820da..9802f5b 100644 --- a/profile/profile.js +++ b/profile/profile.js @@ -1,34 +1,4 @@ -(() => { - function getCookie(name) { - const cookieName = `${name}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const cookieArray = decodedCookie.split(';'); - - for(let i = 0; i < cookieArray.length; i++) { - let cookie = cookieArray[i]; - while (cookie.charAt(0) === ' ') { - cookie = cookie.substring(1); - } - if (cookie.indexOf(cookieName) === 0) { - return cookie.substring(cookieName.length, cookie.length); - } - } - return null; - } - - function shortenSchoolName(name) { - if (!name) return ''; - const maxLength = 30; - if (name.length <= maxLength) return name; - - const parts = name.split(' - '); - if (parts.length === 2) { - const [code, fullName] = parts; - return `${code} - ${fullName.substring(0, maxLength - code.length - 5)}...`; - } - return name.substring(0, maxLength - 3) + '...'; - } - +(() => { function createSecurityTab() { return `
@@ -196,8 +166,8 @@ const saveButton = form.querySelector('#saveContacts'); - emailInput.value = getCookie('userEmail') || ''; - phoneInput.value = getCookie('userPhone') || ''; + emailInput.value = cookieManager.get('userEmail') || ''; + phoneInput.value = cookieManager.get('userPhone') || ''; saveButton?.addEventListener('click', async () => { const email = emailInput.value.trim(); @@ -371,67 +341,10 @@ } } - function createProfileHTML(data) { - const schoolNameFull = `${data.schoolInfo.id} - ${data.schoolInfo.name}`; - const shortenedSchoolName = shortenSchoolName(schoolNameFull); - + function createProfileHTML() { return `
-
-
-

- - Firka -

-
- ${shortenedSchoolName} -
-
- - - - -
+ ${createTemplate.header()}
@@ -469,34 +382,9 @@ async function init() { if (window.location.pathname.includes('/Adminisztracio/Profil')) { - const links = [ - { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, - { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: true }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap' }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/icon?family=Material+Icons+Round' } - ]; + createTemplate.importFonts(); - links.forEach(link => { - const linkElement = document.createElement('link'); - Object.entries(link).forEach(([key, value]) => { - linkElement[key] = value; - }); - document.head.appendChild(linkElement); - }); - - const userData = { - schoolInfo: { - name: getCookie('schoolName') || 'Iskola', - id: getCookie('schoolCode') || '' - }, - userData: { - name: getCookie('userName') || 'Felhasználó', - time: document.querySelector('.usermenu_timer')?.textContent?.trim() || '45:00', - email: getCookie('userEmail') || '' - } - }; - - document.body.innerHTML = createProfileHTML(userData); + document.body.innerHTML = createProfileHTML(); setupEventListeners(); setupContactForm(); } diff --git a/roleselect/roleselect.js b/roleselect/roleselect.js index 17fbe65..02c1f53 100644 --- a/roleselect/roleselect.js +++ b/roleselect/roleselect.js @@ -1,11 +1,4 @@ (() => { - - const setCookie = (name, value, days = 365) => { - const date = new Date(); - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - document.cookie = `${name}=${value}; expires=${date.toUTCString()}; path=/; domain=.e-kreta.hu`; - }; - const startLogoutTimer = () => { let timeLeft = 45 * 60; const timerElement = document.getElementById('logoutTimer'); @@ -124,30 +117,18 @@ if (schoolCode && fullSchoolName) { - setCookie('schoolCode', schoolCode); - setCookie('schoolName', fullSchoolName); - setCookie('schoolSubdomain', schoolSubdomain); + cookieManager.set('schoolCode', schoolCode); + cookieManager.set('schoolName', fullSchoolName); + cookieManager.set('schoolSubdomain', schoolSubdomain); } if (userName) { - setCookie('userName', userName); + cookieManager.set('userName', userName); } document.body.innerHTML = createHTML(schoolCode, fullSchoolName, userName); - - const links = [ - { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, - { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: true }, - { href: 'https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&family=Figtree:wght@300..900&display=swap', rel: 'stylesheet' } - ]; - - links.forEach(link => { - const linkElement = document.createElement('link'); - Object.entries(link).forEach(([key, value]) => linkElement[key] = value); - document.head.appendChild(linkElement); - }); - + createTemplate.importFonts(); const timerInterval = startLogoutTimer(); diff --git a/timetable/timetable.css b/timetable/timetable.css index 3094560..372e198 100644 --- a/timetable/timetable.css +++ b/timetable/timetable.css @@ -43,57 +43,6 @@ body { font-size: 16px; } -/* Loading Screen */ -.loading-screen { - position: fixed; - top: 0; - left: 0; - right: 0; - bottom: 0; - background-color: var(--background); - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - z-index: 9999; -} - -.loading-logo { - width: 48px; - height: 48px; - border-radius: 16px; -} - -.loading-text { - color: var(--text-primary); - text-align: center; - font-family: Montserrat; - font-size: 20px; - font-style: normal; - font-weight: 700; - line-height: normal; -} - -.loading-text2 { - align-self: stretch; - color: var(--text-secondary); - text-align: center; - font-family: Figtree; - font-size: 16px; - font-style: normal; - font-weight: 500; - line-height: 130%; -} - -@keyframes spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} - @media (max-width: 768px) { body { font-size: 14px; diff --git a/timetable/timetable.js b/timetable/timetable.js index febd155..f012e09 100644 --- a/timetable/timetable.js +++ b/timetable/timetable.js @@ -1,85 +1,8 @@ (() => { - // Segédfüggvények - function convertTimeToMinutes(timeStr) { - const [hours, minutes] = timeStr.split(':').map(Number); - return hours * 60 + minutes; - } - function getCookie(name) { - const cookieName = `${name}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const cookieArray = decodedCookie.split(';'); - - for(let i = 0; i < cookieArray.length; i++) { - let cookie = cookieArray[i]; - while (cookie.charAt(0) === ' ') { - cookie = cookie.substring(1); - } - if (cookie.indexOf(cookieName) === 0) { - return cookie.substring(cookieName.length, cookie.length); - } - } - return null; - } - - function shortenSchoolName(name, maxLength = 50) { - if (!name) return ''; - if (name.length <= maxLength) return name; - - const parts = name.split(' - '); - if (parts.length === 2) { - const [code, fullName] = parts; - if (fullName.length > maxLength - code.length - 3) { - return `${code} - ${fullName.substring(0, maxLength - code.length - 6)}...`; - } - } - return name.substring(0, maxLength - 3) + '...'; - } - - function showLoadingScreen() { - const loadingScreen = document.createElement('div'); - loadingScreen.className = 'loading-screen'; - loadingScreen.innerHTML = ` - -
Betöltés alatt...
-

Kis türelmet!

- `; - document.body.appendChild(loadingScreen); - } - - function hideLoadingScreen() { - const loadingScreen = document.querySelector('.loading-screen'); - if (loadingScreen) { - loadingScreen.style.opacity = '0'; - loadingScreen.style.transition = 'opacity 0.3s ease'; - setTimeout(() => loadingScreen.remove(), 300); - } - } - - // DOM elemek várása - function waitForElement(selector) { - return new Promise(resolve => { - if (document.querySelector(selector)) { - return resolve(document.querySelector(selector)); - } - - const observer = new MutationObserver(mutations => { - if (document.querySelector(selector)) { - observer.disconnect(); - resolve(document.querySelector(selector)); - } - }); - - observer.observe(document.body, { - childList: true, - subtree: true - }); - }); - } - // Órarendi adatok gyűjtése async function collectTimetableData() { - await waitForElement('#Calendar'); - await new Promise(resolve => setTimeout(resolve, 1000)); + await helper.waitForElement('#Calendar'); + await helper.waitForElement('.modalBckgroundMain:not(.isOverlayActiv)'); const calendar = document.querySelector('#Calendar'); const dates = Array.from(document.querySelectorAll('.fc-day-header')).map(header => { @@ -121,11 +44,11 @@ } const timetableData = { schoolInfo: { - name: getCookie('schoolName') || 'Iskola', - id: getCookie('schoolCode') || '' + name: cookieManager.get('schoolName') || 'Iskola', + id: cookieManager.get('schoolCode') || '' }, userData: { - name: getCookie('userName') || 'Felhasználó', + name: cookieManager.get('userName') || 'Felhasználó', time: document.querySelector('.usermenu_timer')?.textContent?.trim() || '45:00' }, weekInfo: { @@ -154,7 +77,7 @@ let originalTeacher = ''; if (teacher.startsWith('Helyettesítő:')) { event.click(); - originalTeacher = await waitForElement("#OraAdatokDetailTabStrip-1 > div > div:nth-child(3) > div:nth-child(2)"); + originalTeacher = await helper.waitForElement("#OraAdatokDetailTabStrip-1 > div > div:nth-child(3) > div:nth-child(2)"); originalTeacher = originalTeacher.innerText; document.querySelector("body > div.k-widget.k-window > div.k-window-titlebar.k-header > div > a:nth-child(2)").click(); } @@ -181,8 +104,8 @@ // Grid generálása function generateTimeGrid(lessons, weekDates) { const times = [...new Set(lessons.map(l => l.startTime))].sort((a, b) => { - const timeA = convertTimeToMinutes(a); - const timeB = convertTimeToMinutes(b); + const timeA = helper.convertTimeToMinutes(a); + const timeB = helper.convertTimeToMinutes(b); return timeA - timeB; }); const days = ['Hétfő', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek']; @@ -361,7 +284,7 @@ const weekSelect = document.querySelector('.week-select'); prevBtn?.addEventListener('click', async () => { - showLoadingScreen(); + loadingScreen.show(); const kendoCalendar = document.querySelector('#Calendar')?.__kendoWidget; if (kendoCalendar) { kendoCalendar.prev(); @@ -371,7 +294,7 @@ }); nextBtn?.addEventListener('click', async () => { - showLoadingScreen(); + loadingScreen.show(); const kendoCalendar = document.querySelector('#Calendar')?.__kendoWidget; if (kendoCalendar) { kendoCalendar.next(); @@ -381,7 +304,6 @@ }); weekSelect?.addEventListener('change', async function() { - showLoadingScreen(); const kendoCombo = document.querySelector('#Calendar_tanevHetek')?.__kendoWidget; if (kendoCombo) { kendoCombo.value(this.value); @@ -390,105 +312,23 @@ await transformTimetablePage(); } }); - - // Kijelentkezés időzítő - const startTime = parseInt(data.userData.time?.match(/\d+/)?.[0] || "45"); - let timeLeft = startTime * 60; - - const updateTimer = () => { - const minutes = Math.floor(timeLeft / 60); - const seconds = timeLeft % 60; - const timerEl = document.getElementById('logoutTimer'); - if (timerEl) { - timerEl.textContent = `${minutes}:${seconds.toString().padStart(2, '0')}`; - } - - if (timeLeft <= 0) { - window.location.href = '/Home/Logout'; - } else { - timeLeft--; - } - }; - - updateTimer(); - setInterval(updateTimer, 1000); } // Oldal transzformáció async function transformTimetablePage() { try { - showLoadingScreen(); - const data = await collectTimetableData(); if (!data) { - hideLoadingScreen(); + loadingScreen.hide(); return; } const schoolNameFull = `${data.schoolInfo.id} - ${data.schoolInfo.name}`; - const shortenedSchoolName = shortenSchoolName(schoolNameFull); + const shortenedSchoolName = helper.shortenSchoolName(schoolNameFull); document.body.innerHTML = `
-
-
-

- - Firka -

-
- ${shortenedSchoolName} -
-
- - - - -
+ ${createTemplate.header()}
@@ -516,39 +356,17 @@
`; - // Szükséges fontok hozzáadása - const links = [ - { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, - { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: true }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap' }, - { rel: 'stylesheet', href: 'https://fonts.googleapis.com/icon?family=Material+Icons+Round' } - ]; - - links.forEach(link => { - const linkElement = document.createElement('link'); - Object.entries(link).forEach(([key, value]) => { - linkElement[key] = value; - }); - document.head.appendChild(linkElement); - }); + createTemplate.importFonts(); setupEventListeners(data); - hideLoadingScreen(); + loadingScreen.hide(); } catch (error) { console.error('Hiba az oldal átalakítása során:', error); - hideLoadingScreen(); + loadingScreen.hide(); } } - // Beállítások gomb kezelése - document.getElementById('settingsBtn')?.addEventListener('click', (e) => { - e.preventDefault(); - e.stopPropagation(); - const url = chrome.runtime.getURL('settings/index.html'); - window.open(url, '_blank', 'width=400,height=600'); - }); - if (window.location.href.includes('/Orarend/')) { transformTimetablePage(); } diff --git a/tools/cookieManager.js b/tools/cookieManager.js new file mode 100644 index 0000000..a4a3832 --- /dev/null +++ b/tools/cookieManager.js @@ -0,0 +1,25 @@ +const cookieManager = { + get(name) { + const cookieName = `${name}=`; + const decodedCookie = decodeURIComponent(document.cookie); + const cookieArray = decodedCookie.split(';'); + + for(let i = 0; i < cookieArray.length; i++) { + let cookie = cookieArray[i]; + while (cookie.charAt(0) === ' ') { + cookie = cookie.substring(1); + } + if (cookie.indexOf(cookieName) === 0) { + return cookie.substring(cookieName.length, cookie.length); + } + } + return null; + }, + + set(name, value, days = 365) { + const date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + const expires = `expires=${date.toUTCString()}`; + document.cookie = `${name}=${value}; ${expires}; path=/; domain=.e-kreta.hu`; + } +} \ No newline at end of file diff --git a/tools/createTemplate.js b/tools/createTemplate.js new file mode 100644 index 0000000..47e91ad --- /dev/null +++ b/tools/createTemplate.js @@ -0,0 +1,130 @@ +const createTemplate = { + header() { + const data = { + schoolInfo: { + name: cookieManager.get('schoolName') || 'Iskola', + id: cookieManager.get('schoolCode') || '' + }, + userData: { + name: cookieManager.get('userName') || 'Felhasználó', + time: document.querySelector('.usermenu_timer')?.textContent?.trim() || '45:00', + email: cookieManager.get('userEmail') || '' + } + }; + + const schoolNameFull = `${data.schoolInfo.id} - ${data.schoolInfo.name}`; + const shortenedSchoolName = helper.shortenSchoolName(schoolNameFull); + + + + const element = `
+
+

+ + Firka +

+
+ ${shortenedSchoolName} +
+
+ + + + +
` + + // Kijelentkezés időzítő + const startTime = parseInt(data.userData.time?.match(/\d+/)?.[0] || "45"); + let timeLeft = startTime * 60; + + const updateTimer = () => { + const minutes = Math.floor(timeLeft / 60); + const seconds = timeLeft % 60; + const timerEl = document.getElementById('logoutTimer'); + if (timerEl) { + timerEl.textContent = `${minutes}:${seconds.toString().padStart(2, '0')}`; + } + + if (timeLeft <= 0) { + window.location.href = '/Home/Logout'; + } else { + timeLeft--; + } + }; + + setInterval(updateTimer, 1000); + + return element; + }, + + importFonts() { + const links = [ + { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, + { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: true }, + { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap' }, + { rel: 'stylesheet', href: 'https://fonts.googleapis.com/icon?family=Material+Icons+Round' } + ]; + + links.forEach(link => { + const linkElement = document.createElement('link'); + Object.entries(link).forEach(([key, value]) => { + linkElement[key] = value; + }); + document.head.appendChild(linkElement); + }); + } +} + +document.addEventListener("DOMContentLoaded", async () => { + await helper.waitForElement('#settingsBtn'); + document.querySelector('#settingsBtn').addEventListener('click', (e) => { + e.preventDefault(); + e.stopPropagation(); + const url = chrome.runtime.getURL('settings/index.html'); + window.open(url, '_blank', 'width=400,height=600'); + }); +}); \ No newline at end of file diff --git a/tools/helper.js b/tools/helper.js new file mode 100644 index 0000000..bb738ec --- /dev/null +++ b/tools/helper.js @@ -0,0 +1,40 @@ +const helper = { + shortenSchoolName(name, maxLength = 50) { + if (!name) return ''; + if (name.length <= maxLength) return name; + + const parts = name.split(' - '); + if (parts.length === 2) { + const [code, fullName] = parts; + if (fullName.length > maxLength - code.length - 3) { + return `${code} - ${fullName.substring(0, maxLength - code.length - 6)}...`; + } + } + return name.substring(0, maxLength - 3) + '...'; + }, + + async waitForElement(selector) { + return new Promise(resolve => { + if (document.querySelector(selector)) { + return resolve(document.querySelector(selector)); + } + + const observer = new MutationObserver(mutations => { + if (document.querySelector(selector)) { + observer.disconnect(); + resolve(document.querySelector(selector)); + } + }); + + observer.observe(document.body, { + childList: true, + subtree: true + }); + }); + }, + + convertTimeToMinutes(timeStr) { + const [hours, minutes] = timeStr.split(':').map(Number); + return hours * 60 + minutes; + } +} \ No newline at end of file diff --git a/tools/loadingScreen.css b/tools/loadingScreen.css new file mode 100644 index 0000000..5a2703b --- /dev/null +++ b/tools/loadingScreen.css @@ -0,0 +1,59 @@ +.modalBckgroundMain { + display: none !important; +} + +body:not(.loaded) { + opacity: 0 !important; + visibility: hidden !important; + height: 100vh !important; + overflow: hidden !important; +} + +.loading-screen { + position: fixed; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + background-color: var(--background); + z-index: 9999; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + transition: opacity 0.3s ease; +} + +.loading-content { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; +} + +.loading-logo { + width: 48px; + height: 48px; + border-radius: 16px; +} + +.loading-text { + color: var(--text-primary); + text-align: center; + font-family: Montserrat; + font-size: 20px; + font-style: normal; + font-weight: 700; + line-height: normal; +} + +.loading-text2 { + align-self: stretch; + color: var(--text-secondary); + text-align: center; + font-family: Figtree; + font-size: 16px; + font-style: normal; + font-weight: 500; + line-height: 130%; +} diff --git a/tools/loadingScreen.js b/tools/loadingScreen.js new file mode 100644 index 0000000..12f4469 --- /dev/null +++ b/tools/loadingScreen.js @@ -0,0 +1,47 @@ +const loadingScreen = { + show() { + document.body.classList.remove('loaded'); + const existingLoadingScreen = document.querySelector('.loading-screen'); + if (existingLoadingScreen) return; + + const loadingScreen = document.createElement('div'); + loadingScreen.className = 'loading-screen'; + loadingScreen.innerHTML = ` +
+ +
Betöltés alatt...
+
Kis türelmet!
+
+ `; + document.body.appendChild(loadingScreen); + document.body.classList.add('loaded'); + }, + + hide() { + document.body.classList.add('loaded'); + const loadingScreen = document.querySelector('.loading-screen'); + if (loadingScreen) { + loadingScreen.style.opacity = '0'; + loadingScreen.addEventListener('transitionend', () => { + loadingScreen.remove(); + }); + } + } +} + +window.addEventListener('DOMContentLoaded', () => { + const manifest = chrome.runtime.getManifest(); + const urls = []; + + if (manifest.content_scripts) { + manifest.content_scripts.forEach(script => { + if (script.matches) { + urls.push(...script.matches); + } + }); + } + + if (urls.some(url => url.includes(location.pathname))) { + loadingScreen.show(); + } +}); \ No newline at end of file