Skip to content

Commit

Permalink
Merge pull request #108 from TUfast-TUD/CustomLogin/WarnOption
Browse files Browse the repository at this point in the history
CustomInput  - warn option
  • Loading branch information
OliEfr authored Oct 18, 2022
2 parents 9ad892f + 9d55ada commit cf4b593
Show file tree
Hide file tree
Showing 16 changed files with 726 additions and 778 deletions.
28 changes: 14 additions & 14 deletions src/contentScripts/owa.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
chrome.storage.local.get(['isEnabled', 'loggedOutOwa'], function (result) {
chrome.storage.local.get(['isEnabled', 'loggedOutOwa'], (result) => {
if (result.isEnabled && !result.loggedOutOwa) {
if (document.readyState !== 'loading') {
loginOWA(result.loggedOutOwa)
} else {
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', () => {
loginOWA(result.loggedOutOwa)
})
}
Expand All @@ -19,26 +19,26 @@ chrome.storage.local.get(['isEnabled', 'loggedOutOwa'], function (result) {
})

// detecting logout
document.addEventListener('DOMNodeInserted', function (e) {
document.addEventListener('DOMNodeInserted', (e) => {
// old owa version
if (document.querySelectorAll('[aria-label="Abmelden"]')[0]) {
document.querySelectorAll('[aria-label="Abmelden"]')[0].addEventListener('click', function () {
console.log("OLD LOGOUT DETECTED")
document.querySelectorAll('[aria-label="Abmelden"]')[0].addEventListener('click', () => {
console.log('OLD LOGOUT DETECTED')
chrome.runtime.sendMessage({ cmd: 'logged_out', portal: 'loggedOutOwa' })
})
}
// new owa version
if (document.querySelectorAll("[autoid='_ho2_2']")[1] && document.querySelectorAll("[autoid='_ho2_2']")[1].innerHTML === 'Abmelden') {
document.querySelectorAll("[autoid='_ho2_2']")[1].addEventListener('click', function () {
console.log("LOGOUT DETECTED")
document.querySelectorAll("[autoid='_ho2_2']")[1].addEventListener('click', () => {
console.log('LOGOUT DETECTED')
chrome.runtime.sendMessage({ cmd: 'logged_out', portal: 'loggedOutOwa' })
})
}
}, false)

function loginOWA(loggedOutOwa) {
function loginOWA (loggedOutOwa) {
if (document.getElementById('username') && document.getElementById('password') && !loggedOutOwa) {
chrome.runtime.sendMessage({ cmd: 'get_user_data' }, function (result) {
chrome.runtime.sendMessage({ cmd: 'get_user_data' }, (result) => {
if (!(result.asdf === undefined || result.fdsa === undefined)) {
chrome.runtime.sendMessage({ cmd: 'show_ok_badge', timeout: 2000 })
chrome.runtime.sendMessage({ cmd: 'save_clicks', click_count: 1 })
Expand All @@ -55,16 +55,16 @@ function loginOWA(loggedOutOwa) {
// detecting logout
// old owa version
if (document.querySelectorAll('[aria-label="Abmelden"]')[0]) {
document.querySelectorAll('[aria-label="Abmelden"]')[0].addEventListener('click', function () {
console.log("OLD LOGOUT DETECTED")
document.querySelectorAll('[aria-label="Abmelden"]')[0].addEventListener('click', () => {
console.log('OLD LOGOUT DETECTED')
chrome.runtime.sendMessage({ cmd: 'logged_out', portal: 'loggedOutOwa' })
})
}
// new owa version
if (document.querySelectorAll("[autoid='_ho2_2']")[1] && document.querySelectorAll("[autoid='_ho2_2']")[1].innerHTML === 'Abmelden') {
document.querySelectorAll("[autoid='_ho2_2']")[1].addEventListener('click', function () {
document.querySelectorAll("[autoid='_ho2_2']")[1].addEventListener('click', () => {
chrome.runtime.sendMessage({ cmd: 'logged_out', portal: 'loggedOutOwa' })
console.log("LOGOUT DETECTED")
console.log('LOGOUT DETECTED')
})
}
}
Expand All @@ -85,7 +85,7 @@ window.onload = function () {
})
}

function readMailObserver() {
function readMailObserver () {
// use mutation observer to detect page changes
const config = { attributes: true, childList: true, subtree: true, characterData: true }
let nrUnreadMails
Expand Down
771 changes: 385 additions & 386 deletions src/freshContent/popup/popup.js

Large diffs are not rendered by default.

161 changes: 83 additions & 78 deletions src/freshContent/settings/Settings.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<div class="main-grid">
<header class="main-grid__header">
<h1 class="upper txt-bold main-grid__title">Willkommen bei TUfast 🚀</h1>
<h1 class="upper txt-bold main-grid__title">
Willkommen bei TUfast 🚀
</h1>
<h3 class="txt-bold main-grid__subtitle">
Hier kannst du alle Funktionen entdecken und Einstellungen vornehmen.
</h3>
Expand Down Expand Up @@ -36,7 +38,10 @@
<component :is="currentSetting.settingsPage" />
</template>
</Card>
<teleport v-if="!hideWelcome" to="body">
<teleport
v-if="!hideWelcome"
to="body"
>
<Onboarding
:current-step="currentOnboardingStep"
:h1="onboardingSteps[currentOnboardingStep - 1].h1"
Expand All @@ -50,47 +55,47 @@
</template>

<script lang="ts">
import { defineComponent, onBeforeMount, ref } from "vue";
import { defineComponent, onBeforeMount, ref } from 'vue'
// types
import type { Setting } from "./types/Setting";
import type { Setting } from './types/Setting'
// Components
import ColorSwitch from "./components/ColorSwitch.vue";
import LanguageSelect from "./components/LanguageSelect.vue";
import Statistics from "./components/Statistics.vue";
import Dropdown from "./components/Dropdown.vue";
import SettingTile from "./components/SettingTile.vue";
import Onboarding from "./components/Onboarding.vue";
import Card from "./components/Card.vue";
import Toggle from "./components/Toggle.vue";
import ColorSwitch from './components/ColorSwitch.vue'
import LanguageSelect from './components/LanguageSelect.vue'
import Statistics from './components/Statistics.vue'
import Dropdown from './components/Dropdown.vue'
import SettingTile from './components/SettingTile.vue'
import Onboarding from './components/Onboarding.vue'
import Card from './components/Card.vue'
import Toggle from './components/Toggle.vue'
// Settings Page Components
import AutoLogin from "./settingPages/AutoLogin.vue";
import Email from "./settingPages/Email.vue";
import OpalCourses from "./settingPages/OpalCourses.vue";
import ImproveOpal from "./settingPages/ImproveOpal.vue";
import Shortcuts from "./settingPages/Shortcuts.vue";
import SearchEngines from "./settingPages/SearchEngines.vue";
import Rockets from "./settingPages/Rockets.vue";
import Contact from "./settingPages/Contact.vue";
import AutoLogin from './settingPages/AutoLogin.vue'
import Email from './settingPages/Email.vue'
import OpalCourses from './settingPages/OpalCourses.vue'
import ImproveOpal from './settingPages/ImproveOpal.vue'
import Shortcuts from './settingPages/Shortcuts.vue'
import SearchEngines from './settingPages/SearchEngines.vue'
import Rockets from './settingPages/Rockets.vue'
import Contact from './settingPages/Contact.vue'
// Onboarding Page Components
import Welcome from "./onboardingPages/01_Welcome.vue";
import SearchSetup from "./onboardingPages/02_SearchSetup.vue";
import LoginSetup from "./onboardingPages/03_LoginSetup.vue";
import LoginAccept from "./onboardingPages/04_LoginAccept.vue";
import EMailSetup from "./onboardingPages/05_EMailSetup.vue";
import OpalSetup from "./onboardingPages/06_OpalSetup.vue";
import DoneSetup from "./onboardingPages/07_DoneSetup.vue";
import Welcome from './onboardingPages/01_Welcome.vue'
import SearchSetup from './onboardingPages/02_SearchSetup.vue'
import LoginSetup from './onboardingPages/03_LoginSetup.vue'
import LoginAccept from './onboardingPages/04_LoginAccept.vue'
import EMailSetup from './onboardingPages/05_EMailSetup.vue'
import OpalSetup from './onboardingPages/06_OpalSetup.vue'
import DoneSetup from './onboardingPages/07_DoneSetup.vue'
// configurations
import settings from "./settings.json";
import onboardingSteps from "./onboarding.json";
import settings from './settings.json'
import onboardingSteps from './onboarding.json'
// composables
import { useChrome } from "./composables/chrome";
import { useStepper } from "./composables/stepper";
import { useChrome } from './composables/chrome'
import { useStepper } from './composables/stepper'
// Temporary fix: We need to import the Components for the icons manually as no global usage is possible
// But we need to do this in SettingsTile.
Expand Down Expand Up @@ -118,76 +123,76 @@ export default defineComponent({
LoginAccept,
EMailSetup,
OpalSetup,
DoneSetup,
DoneSetup
},
setup() {
const { getChromeLocalStorage, setChromeLocalStorage } = useChrome();
const { hideWelcome, currentOnboardingStep } = useStepper();
const showCard = ref(false);
const currentSetting = ref(settings[0]);
const animState = ref<"dark" | "light">("dark");
setup () {
const { getChromeLocalStorage, setChromeLocalStorage } = useChrome()
const { hideWelcome, currentOnboardingStep } = useStepper()
const showCard = ref(false)
const currentSetting = ref(settings[0])
const animState = ref<'dark' | 'light'>('dark')
// handles the opening of a setting card
const openSetting = (setting: Setting) => {
showCard.value = true;
currentSetting.value = setting;
};
showCard.value = true
currentSetting.value = setting
}
// toggles the theme setting inside local storage
const toggleTheme = async () => {
const theme = (await getChromeLocalStorage("theme")) as "light" | "dark";
if (animState.value === "dark") {
await setChromeLocalStorage({ theme: "light" });
const theme = (await getChromeLocalStorage('theme')) as 'light' | 'dark'
if (animState.value === 'dark') {
await setChromeLocalStorage({ theme: 'light' })
}
if (animState.value === "light") {
await setChromeLocalStorage({ theme: "dark" });
if (animState.value === 'light') {
await setChromeLocalStorage({ theme: 'dark' })
}
updateTheme(theme === "dark" ? "light" : "dark");
};
updateTheme(theme === 'dark' ? 'light' : 'dark')
}
// updates the theme classes on the <html> element
const updateTheme = (theme: string) => {
// shortening the rest of the logic
const setClass = (className: string) =>
document.documentElement.classList.add(className);
document.documentElement.classList.add(className)
const unsetClass = (className: string) =>
document.documentElement.classList.remove(className);
if (theme === "dark") {
animState.value = "dark";
setClass("dark");
unsetClass("light");
} else if (theme === "light") {
animState.value = "light";
setClass("light");
unsetClass("dark");
document.documentElement.classList.remove(className)
if (theme === 'dark') {
animState.value = 'dark'
setClass('dark')
unsetClass('light')
} else if (theme === 'light') {
animState.value = 'light'
setClass('light')
unsetClass('dark')
}
};
}
// sets the right theme on initial load
const themeSetup = async () => {
let selectedTheme = (await getChromeLocalStorage("theme")) as
| "dark"
| "light"
| "system";
if (selectedTheme === "system") {
let selectedTheme = (await getChromeLocalStorage('theme')) as
| 'dark'
| 'light'
| 'system'
if (selectedTheme === 'system') {
// check if user prefers some color theme
selectedTheme = window.matchMedia("(prefers-color-scheme: light)")
selectedTheme = window.matchMedia('(prefers-color-scheme: light)')
.matches
? "light"
: "dark";
await setChromeLocalStorage({ theme: selectedTheme });
? 'light'
: 'dark'
await setChromeLocalStorage({ theme: selectedTheme })
}
updateTheme(selectedTheme);
};
updateTheme(selectedTheme)
}
// lifecycle hook - runs some startup logic before load of settings page
onBeforeMount(async () => {
hideWelcome.value = (await getChromeLocalStorage(
"hideWelcome"
)) as boolean;
themeSetup();
});
'hideWelcome'
)) as boolean
themeSetup()
})
return {
hideWelcome,
Expand All @@ -198,10 +203,10 @@ export default defineComponent({
currentSetting,
openSetting,
toggleTheme,
animState,
};
},
});
animState
}
}
})
</script>

<style lang="sass" scoped>
Expand Down
Loading

0 comments on commit cf4b593

Please sign in to comment.