diff --git a/package.json b/package.json
index d6ab976..04df5c4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "period-countdown",
- "version": "2.1.3",
+ "version": "2.1.4",
"description": "A simple way to keep track of the remaining time in class",
"main": "server.js",
"scripts": {
diff --git a/public/js/extras.js b/public/js/extras.js
new file mode 100644
index 0000000..096d76a
--- /dev/null
+++ b/public/js/extras.js
@@ -0,0 +1,72 @@
+import Logger from './Logger.js';
+
+export function addServiceWorker(path) {
+ if (navigator.serviceWorker) {
+ navigator.serviceWorker.register(path).then((reg) => {
+ Logger.log('main', 'service worker registered');
+ }).catch(err => {
+ Logger.log('main', 'service worker registration failed');
+ console.error(err);
+ })
+ return true;
+ }
+ return false;
+}
+
+export function googleApiDidLoad(render) {
+ return () => gapi.load('auth2', () => {
+ gapi.auth2.init({
+ client_id: '770077939711-hbanoschq9p65gr8st8grsfbku4bsnhl.apps.googleusercontent.com',
+ cookiepolicy: 'single_host_origin',
+ scope: 'profile email'
+ }).then(GoogleAuth => {
+ let gSuccess = user => {
+ if (view.modal.open) view.closeModal();
+
+ let data = user.getBasicProfile();
+
+ let account = {
+ email: data.U3,
+ first_name: data.ofa,
+ last_name: data.wea,
+ profile_pic: data.Paa
+ }
+
+ RequestManager.login(account).then(res => {
+ if (res.data.status === 'returning_user') {
+ prefManager.setGoogleAccount(res.data.user_data);
+ view.settingChangesSaved();
+ } else if (res.data.status === 'new_user') {
+ prefManager.setGoogleAccount(res.data.user_data);
+ } else {
+ view.showModal('modal-server-down');
+ }
+
+ render.showPrefs();
+ }).catch(err => {
+ view.showModal('modal-server-down');
+ });
+ }
+
+ let gFail = () => window.alert('Google had trouble signing you in. Please try again later.');
+
+ document.querySelector('#modal-body .modal-login').innerHTML = 'After logging in with Google, you will gain a whole host of new features including the ability to have personalized period names and custom themes.
Click here to log in with your Google Account.';
+
+ for (let element of document.getElementsByClassName('google-login-button'))
+ GoogleAuth.attachClickHandler(element, {}, gSuccess, gFail);
+ });
+ });
+}
+
+export function greeting() {
+ let greeting = ['Welcome', '欢迎', 'स्वागत हे', 'Bienvenido', 'خوش آمدی', 'Bienvenue', 'желанный', 'Bem vinda', 'Benvenuto', 'Gratus mihi venis', 'Welkom', 'ברוך הבא', 'ようこそ'][Math.floor(Math.random() * 13)];
+ console.log(`%c${greeting}`, 'background: #fccb0b; color: #000; font-size: 34px; padding: 6px 20px; font-family: \'sans-serif\'; border-radius: 4px;');
+ console.log('https://github.com/arjunpat/period-countdown');
+}
+
+export function getVersion() {
+ for (let node of document.querySelectorAll('script')) {
+ if (node.src.includes('/js/bundle.js?v='))
+ return node.src.substring(node.src.indexOf('?v=') + 3);
+ }
+}
\ No newline at end of file
diff --git a/public/js/main.js b/public/js/main.js
index b96b6a0..557e023 100644
--- a/public/js/main.js
+++ b/public/js/main.js
@@ -7,15 +7,20 @@ import Storage from './Storage.js';
import ScheduleBuilder from './ScheduleBuilder.js';
import TimingEngine from './TimingEngine.js';
-import {render, load} from './render.js';
+import { render, load } from './render.js';
+import { addServiceWorker, googleApiDidLoad, greeting, getVersion } from './extras.js';
+
window.timingEngine = new TimingEngine();
window.view = new View();
-window.analytics = new Analytics;
-window.prefManager = new PrefManager;
+window.analytics = new Analytics();
+window.prefManager = new PrefManager();
window.scheduleBuilder = new ScheduleBuilder();
window.RequestManager = RequestManager;
+// has to global fro google
+window.googleApiDidLoad = googleApiDidLoad(render);
+
// inital page render
load(window.location.pathname);
@@ -60,23 +65,11 @@ window.onbeforeunload = () => {
analytics.leaving();
}
-// gets version
-for (let node of document.querySelectorAll('script')) {
- if (node.src.includes('/js/bundle.js?v='))
- analytics.setVersion(node.src.substring(node.src.indexOf('?v=') + 3));
-}
+analytics.setVersion(getVersion());
analytics.setPathname(window.location.pathname);
-// add service workers
-/*if (navigator.serviceWorker) {
- navigator.serviceWorker.register('/sw.js').then((reg) => {
- Logger.log('main', 'service worker registered');
- }).catch(err => {
- Logger.log('main', 'service worker registration failed');
- console.error(err);
- })
-}*/
+//addServiceWorker('/sw.js');
if (window.chrome && !window.localStorage.chrome_extension_installed) {
setTimeout(() => {
@@ -97,55 +90,4 @@ window.setInterval(() => {
}, 5 * 60 * 1000 /* five minutes */);
// welcome, cause what else is the computer going to do?
-let greeting = ['Welcome', '欢迎', 'स्वागत हे', 'Bienvenido', 'خوش آمدی', 'Bienvenue', 'желанный', 'Bem vinda', 'Benvenuto', 'Gratus mihi venis', 'Welkom', 'ברוך הבא', 'ようこそ'][Math.floor(Math.random() * 13)];
-console.log(`%c${greeting}`, 'background: #fccb0b; color: #000; font-size: 34px; padding: 6px 20px; font-family: \'sans-serif\'; border-radius: 4px;');
-console.log('https://github.com/arjunpat/period-countdown');
-
-
-// has to be global for google api
-window.googleApiDidLoad = () => {
-
- gapi.load('auth2', () => {
- gapi.auth2.init({
- client_id: '770077939711-hbanoschq9p65gr8st8grsfbku4bsnhl.apps.googleusercontent.com',
- cookiepolicy: 'single_host_origin',
- scope: 'profile email'
- }).then(GoogleAuth => {
- let gSuccess = user => {
- if (view.modal.open) view.closeModal();
-
- let data = user.getBasicProfile();
-
- let account = {
- email: data.U3,
- first_name: data.ofa,
- last_name: data.wea,
- profile_pic: data.Paa
- }
-
- RequestManager.login(account).then(res => {
- if (res.data.status === 'returning_user') {
- prefManager.setGoogleAccount(res.data.user_data);
- view.settingChangesSaved();
- } else if (res.data.status === 'new_user') {
- prefManager.setGoogleAccount(res.data.user_data);
- } else {
- view.showModal('modal-server-down');
- }
-
- render.showPrefs();
- }).catch(err => {
- view.showModal('modal-server-down');
- });
- }
-
- let gFail = () => window.alert('Google had trouble signing you in. Please try again later.');
-
- document.querySelector('#modal-body .modal-login').innerHTML = 'After logging in with Google, you will gain a whole host of new features including the ability to have personalized period names and custom themes.
Click here to log in with your Google Account.';
-
- for (let element of document.getElementsByClassName('google-login-button'))
- GoogleAuth.attachClickHandler(element, {}, gSuccess, gFail);
- });
- });
-
-}
\ No newline at end of file
+greeting();
\ No newline at end of file
diff --git a/public/js/render.js b/public/js/render.js
index 4a3e9af..2b35ae9 100644
--- a/public/js/render.js
+++ b/public/js/render.js
@@ -110,7 +110,6 @@ render.index = () => {
}
window.onresize = resizeScreen;
- window.screen.orientation.onchange = resizeScreen;
view.index.settingsButton.querySelector('div').onclick = () => {
load('/settings', true);