Files
BetterSEQTA-Plus/package/background.js
T
2023-11-24 17:19:11 +11:00

1 line
3.0 KiB
JavaScript

(()=>{"use strict";function e(t){const o=new Date;let a=`https://newsapi.org/v2/everything?domains=abc.net.au&from=${o.getFullYear()+"-"+(o.getMonth()+1)+"-"+(o.getDate()-1)}&apiKey=17c0da766ba347c89d094449504e3080`;fetch(a).then((e=>e.json())).then((o=>{"rateLimited"==o.code?(a+="%00",e()):t({news:o})}))}chrome.runtime.onMessage.addListener(((a,n,s)=>{switch(a.type){case"reloadTabs":chrome.tabs.query({},(function(e){for(let t of e)t.title.includes("SEQTA Learn")&&chrome.tabs.reload(t.id)}));break;case"currentTab":return chrome.tabs.query({active:!0,currentWindow:!0},(function(e){chrome.tabs.sendMessage(e[0].id,a,(function(e){s(e)}))})),!0;case"githubTab":chrome.tabs.create({url:"github.com/SethBurkart123/EvenBetterSEQTA"});break;case"setDefaultStorage":o(t);break;case"addPermissions":void 0!==chrome.declarativeContent&&chrome.declarativeContent.onPageChanged.removeRules(void 0,(()=>{})),chrome.permissions.request({permissions:["declarativeContent"],origins:["*://*/*"]},(e=>{e&&([].forEach((e=>{chrome.declarativeContent.onPageChanged.addRules([e])})),alert("Permissions granted. Reload SEQTA pages to see changes. If this workaround doesn't work, please contact the developer. It will be an easy fix"))}));break;case"sendNews":return e(s),!0;default:console.log("Unknown request type")}}));const t={onoff:!0,animatedbk:!0,bksliderinput:50,transparencyEffects:!1,lessonalert:!0,notificationcollector:!0,defaultmenuorder:[],menuitems:{},menuorder:[],subjectfilters:{},selectedColor:"linear-gradient(40deg, rgba(201,61,0,1) 0%, RGBA(170, 5, 58, 1) 100%)",DarkMode:!0,shortcuts:[{name:"YouTube",enabled:!1},{name:"Outlook",enabled:!0},{name:"Office",enabled:!0},{name:"Spotify",enabled:!1},{name:"Google",enabled:!0},{name:"DuckDuckGo",enabled:!1},{name:"Cool Math Games",enabled:!1},{name:"SACE",enabled:!1},{name:"Google Scholar",enabled:!1},{name:"Gmail",enabled:!1},{name:"Netflix",enabled:!1},{name:"Education Perfect",enabled:!1}],customshortcuts:[]};function o(e){for(var t in e)chrome.storage.local.set({[t]:e[t]})}chrome.runtime.onInstalled.addListener((function(e){chrome.storage.local.remove(["justupdated"]),chrome.storage.local.get(null,(function(e){var a=e;const n=Object.assign({},t,a);!function(e){for(let o in e)if("object"==typeof e[o])if(void 0===t[o].length)n[o]=Object.assign({},t[o],a[o]);else{let e=t[o].length;n[o]=Object.assign({},t[o],a[o]);let s=[];for(let t=0;t<e;t++)s.push(n[o][t]);n[o]=s}}(t),e.customshortcuts&&(n.customshortcuts=e.customshortcuts),o(n)})),e.reason,"update"==e.reason&&(chrome.storage.local.set({justupdated:!0}),chrome.storage.local.get(null,(function(e){let t=!1;if(e.shortcuts&&e.shortcuts.length>0&&"Name"in e.shortcuts[0]&&(t=!0,e.shortcuts=e.shortcuts.map((e=>({name:e.Name,enabled:e.enabled})))),e.shortcuts&&e.shortcuts.length>0)for(let o of e.shortcuts)"educationperfect"!==o.name&&"Education Perfect"!==o.name||(t=!0,o.name="Education Perfect");t&&chrome.storage.local.set({shortcuts:e.shortcuts},(function(){console.log("Migration completed.")}))})))}))})();