diff --git a/js/app.js b/js/app.js index 0d6207d..a7c3241 100644 --- a/js/app.js +++ b/js/app.js @@ -14,7 +14,7 @@ window.addEventListener('beforeinstallprompt', (e) => { }); if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('/js/sw.js'); + navigator.serviceWorker.register('/papillonWorker.js'); }; // Vérifie qu'une font custom n'est pas appliquée @@ -219,16 +219,18 @@ let userEverything; function loadPronoteData() { progressStart(); - $.get(`https://ams01.pronote.plus/user?token=${token}&rand=${uuidv4()}`, function(data, success) { - + fetch(`https://ams01.pronote.plus/user?token=${token}`) + .then((resp) => resp.json()) + .then(function(data) { + // Si la requête fail, rafrachir le token - if (JSON.parse(data).message !== undefined) { + if (data.message !== undefined) { tokenRefreshBkg() } progressEnd(); // Décode le JSON depuis l'API - let resp = JSON.parse(data).data.user; + let resp = data.data.user; userEverything = resp; // Récupère le prénom à partir des données de l'utilisateur @@ -479,8 +481,10 @@ function tokenRefreshBkg() { let authURL = auth[0]; let authENT = auth[3]; - $.get(`https://ams01.pronote.plus/auth?url=${authURL}&username=${authUsername}&password=${authPasswordUnsecure}&cas=${authENT}&rand=${uuidv4()}`, function(data) { - let resp = JSON.parse(data); + fetch(`https://ams01.pronote.plus/auth?url=${authURL}&username=${authUsername}&password=${authPasswordUnsecure}&cas=${authENT}`) + .then((resp) => resp.json()) + .then(function(data) { + let resp = data; tries++; @@ -541,8 +545,10 @@ function openApp() { buttonNext.click() } else if (dateString.includes("samedi")) { // requête pour checker si y'a cours le samedi - $.get(`https://ams01.pronote.plus/edt?token=${token}&from=${from}&rand=${uuidv4()}`, function( data ) { - if(JSON.parse(data).data.timetable === null) { + fetch(`https://ams01.pronote.plus/edt?token=${token}&from=${from}`) + .then((resp) => resp.json()) + .then(function(data) { + if(data.data.timetable === null) { // avance de 2 jours buttonNext.click() buttonNext.click() diff --git a/js/sw.js b/js/sw.js deleted file mode 100644 index 4681948..0000000 --- a/js/sw.js +++ /dev/null @@ -1,17 +0,0 @@ -self.addEventListener('install', (e) => { - console.log('[Service Worker] Installation'); -}); - -var cacheName = 'papillon'; -var appShellFiles = [ - '/index.html', - '/manifest.webmanifest', - '/css/main.css', - '/js/app.js', - '/js/aihvahView.js', - '/js/jquery.js', - '/js/sw.js', - '/views/edt.html', - '/views/user.html', - '/views/about.html', -]; diff --git a/manifest.webmanifest b/manifest.webmanifest index ee39e42..ca865c5 100644 --- a/manifest.webmanifest +++ b/manifest.webmanifest @@ -1,6 +1,6 @@ { "name": "Pronote+", - "start_url": "https://v3.pronote.plus", + "start_url": "/", "display": "standalone", "theme_color": "#000000", "background_color": "#2BA873", diff --git a/papillonWorker.js b/papillonWorker.js new file mode 100644 index 0000000..83cf44c --- /dev/null +++ b/papillonWorker.js @@ -0,0 +1,92 @@ +/* + Copyright 2016 Google Inc. All Rights Reserved. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +// Names of the two caches used in this version of the service worker. +// Change to v2, etc. when you update any of the local resources, which will +// in turn trigger the install event again. +const PRECACHE = 'precache-v1'; +const RUNTIME = 'runtime'; + +// A list of local resources we always want to be cached. +const PRECACHE_URLS = [ + 'index.html', + '/', + '/css/main.css', + '/js/app.js', + 'papillonWorker.js', + '/views/about.html', + '/views/absences.html', + '/views/edt.html', + '/views/evaluations.html', + '/views/files.html', + '/views/hw.html', + '/views/info.html', + '/views/mark.html', + '/views/marks.html', + '/views/news.html', + '/views/theme.html', + '/views/update.html', + '/views/user.html', + '/views/userdata.html', + '/login/index.html', + '/login/login.css', + '/login/login.js' +]; + +// The install handler takes care of precaching the resources we always need. +self.addEventListener('install', event => { + event.waitUntil( + caches.open(PRECACHE) + .then(cache => cache.addAll(PRECACHE_URLS)) + .then(self.skipWaiting()) + ); +}); + +// The activate handler takes care of cleaning up old caches. +self.addEventListener('activate', event => { + const currentCaches = [PRECACHE, RUNTIME]; + event.waitUntil( + caches.keys().then(cacheNames => { + return cacheNames.filter(cacheName => !currentCaches.includes(cacheName)); + }).then(cachesToDelete => { + return Promise.all(cachesToDelete.map(cacheToDelete => { + return caches.delete(cacheToDelete); + })); + }).then(() => self.clients.claim()) + ); +}); + +// The fetch handler serves responses for same-origin resources from a cache. +// If no response is found, it populates the runtime cache with the response +// from the network before returning it to the page. +self.addEventListener('fetch', event => { + // Skip cross-origin requests, like those for Google Analytics. + if (1 == 1) { + event.respondWith( + caches.match(event.request).then(cachedResponse => { + if (cachedResponse) { + return cachedResponse; + } + + return caches.open(RUNTIME).then(cache => { + return fetch(event.request).then(response => { + // Put a copy of the response in the runtime cache. + return cache.put(event.request, response.clone()).then(() => { + return response; + }); + }); + }); + }) + ); + } +}); \ No newline at end of file diff --git a/views/edt.html b/views/edt.html index 3e43d57..9103859 100644 --- a/views/edt.html +++ b/views/edt.html @@ -7,21 +7,18 @@ return (dt.getMinutes() < 10 ? '0' : '') + dt.getMinutes(); } - if(localStorage.getItem("cache_edt") !== null){ - // parse_Edt(JSON.parse(localStorage.getItem("cache_edt"))); - mainView_Edt(); - } - else { - mainView_Edt(); - } + mainView_Edt(); function mainView_Edt() { let from = rn.toISOString().split("T")[0] progressStart(); - $.get(`https://ams01.pronote.plus/edt?token=${token}&from=${from}&rand=${uuidv4()}`, function( data ) { + + fetch(`https://ams01.pronote.plus/edt?token=${token}&from=${from}`) + .then((resp) => resp.json()) + .then(function(data) { - if(JSON.parse(data).errors !== undefined) { - if(JSON.parse(data).code == 2) { + if(data.errors !== undefined) { + if(data.code == 2) { Toastify({ text: "Vous avez envoyé trop de demandes à Pronote, veuillez patienter quelques minutes.", gravity: "top", @@ -62,7 +59,7 @@ try{ $('#ListeCours').html(``); - let resp = JSON.parse(data).data.timetable; + let resp = data.data.timetable; if(resp == null) { if(EdtRefLimit == 0) { diff --git a/views/hw.html b/views/hw.html index 0967c79..b339ae5 100644 --- a/views/hw.html +++ b/views/hw.html @@ -15,13 +15,17 @@ $('#ListeDevoirs').append(`
${dayName}
`); progressStart(); - $.get(`https://ams01.pronote.plus/hw?token=${token}&from=${from}&rand=${uuidv4()}`, function( data ) { - if(JSON.parse(data).message !== undefined) { + + fetch(`https://ams01.pronote.plus/hw?token=${token}&from=${from}`) + .then((resp) => resp.json()) + .then(function(data) { + + if(data.message !== undefined) { tokenRefreshBkg() } progressEnd(); - let resp = JSON.parse(data).data.homeworks; + let resp = data.data.homeworks; for(hw in resp) { let classes = ""; @@ -76,7 +80,10 @@

🥳 Pas de travail à faire

$('#ListeDevoirs').append(`
${dayName}
`); progressStart(); - $.get(`https://ams01.pronote.plus/hw?token=${token}&from=${from}&rand=${uuidv4()}`, function( data ) { + + fetch(`https://ams01.pronote.plus/hw?token=${token}&from=${from}`) + .then((resp) => resp.json()) + .then(function(data) { if(JSON.parse(data).message !== undefined) { tokenRefreshBkg() } diff --git a/views/news.html b/views/news.html index bee79ff..14ec038 100644 --- a/views/news.html +++ b/views/news.html @@ -8,13 +8,16 @@ half.setDate(half.getDate() + 1); let from = half.toISOString().split("T")[0] progressStart(4); - $.get(`https://ams01.pronote.plus/news?token=${token}&rand=${uuidv4()}`, function( data ) { - if(JSON.parse(data).errors !== undefined) { + + fetch(`https://ams01.pronote.plus/news?token=${token}`) + .then((resp) => resp.json()) + .then(function(data) { + if(data.errors !== undefined) { refreshToken(); } progressEnd(); - let resp = JSON.parse(data).data.infos; + let resp = data.data.infos; if (resp !== null) {