Skip to content

Commit

Permalink
Merge pull request #189 from NIAEFEUP/feat/linter-formatter
Browse files Browse the repository at this point in the history
Added linter and formatter
  • Loading branch information
toni-santos authored Sep 25, 2024
2 parents 5c0af44 + deca226 commit 24ebe74
Show file tree
Hide file tree
Showing 83 changed files with 7,428 additions and 6,765 deletions.
13 changes: 13 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
/node_modules
/dist
/.yarn
/.github
/popup/.next
/popup/.yarn
/popup/.node_modules
/popup/out

.changes.json
package-lock.json
yarn.lock
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"useTabs": false,
"tabWidth": 4,
"printWidth": 80,
"singleQuote": false,
"endOfLine": "auto",
"trailingComma": "all"
}
14 changes: 7 additions & 7 deletions Develop for Safari.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
From [developer.apple.com](https://developer.apple.com/documentation/safariservices/safari_app_extensions/building_a_safari_app_extension#2957927):

>To develop without a certificate, each time you launch Safari, you need to tell it to load unsigned extensions using the Develop menu:
> To develop without a certificate, each time you launch Safari, you need to tell it to load unsigned extensions using the Develop menu:
>
> Open Safari and choose Safari > Preferences.
> Open Safari and choose Safari > Preferences.
>
> Select the Advanced tab, then select the “Show Develop menu in menu bar” checkbox.
> Select the Advanced tab, then select the “Show Develop menu in menu bar” checkbox.
>
> Choose Develop > Allow Unsigned Extensions, enter your password, and click OK. The Allow Unsigned Extensions setting resets when a user quits Safari, so you need to set it again the next time you launch Safari.
> Choose Develop > Allow Unsigned Extensions, enter your password, and click OK. The Allow Unsigned Extensions setting resets when a user quits Safari, so you need to set it again the next time you launch Safari.
>
> Choose Safari > Preferences and click the Extensions tab. This tab shows the localized description, display name, and version number for the selected Safari app extension. It also provides a more nuanced message about the permissions for the extension.
> Choose Safari > Preferences and click the Extensions tab. This tab shows the localized description, display name, and version number for the selected Safari app extension. It also provides a more nuanced message about the permissions for the extension.
>
> Find your new extension in the list on the left, and enable it by selecting its checkbox.
> Find your new extension in the list on the left, and enable it by selecting its checkbox.
>
> Close Safari Preferences.
> Close Safari Preferences.
1 change: 1 addition & 0 deletions PRIVACY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TODO:

# Privacy Policy

NitSig does not store or collect any personal information. All user prefences are stored on the user's device in local storage.
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Choose your favorite browser and start developing:
```sh
yarn run dev:firefox
```

or

```sh
yarn run dev:chrome
```
Expand All @@ -32,6 +34,34 @@ This command will initialize a browser window and load the extension, watching f
yarn build
```

## Linting and formatting

In order to maintain our codebase we are using [Prettier](https://prettier.io/) for formatting and [ESLint](https://eslint.org/) for linting.

If you only want to check for formatting issues run:

```sh
yarn format
```

Or if you want to have Prettier fix them:

```sh
yarn format:fix
```

Similarly, to check for linting issues run:

```sh
yarn lint
```

And, if you wish to fix the warnings that ESLint picks up, run:

```sh
yarn lint:fix
```

## Loading a bundle

<table>
Expand Down Expand Up @@ -64,4 +94,4 @@ yarn build
</ol>
</td>
</tr>
</table>
</table>
2 changes: 1 addition & 1 deletion assets/mac-icon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ convert mac-icon.png -resize 64x64 -gravity center -background transparent -exte
convert mac-icon.png -resize 256x256 -gravity center -background transparent -extent 256x256 mac-icon-128@2x.png
convert mac-icon.png -resize 512x512 -gravity center -background transparent -extent 512x512 mac-icon-256@2x.png
convert mac-icon.png -resize 1024x1024 -gravity center -background transparent -extent 1024x1024 mac-icon-512@2x.png
```
```
92 changes: 47 additions & 45 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,67 @@ const sigarraRegex = /.*:\/\/sigarra\.up\.pt\/feup\/.*/;

// Add default values for each option here
const popupOptions = {
navbar: "on",
shortcuts: "on",
autoLogin: "off",
font: "on",
navbar: "on",
shortcuts: "on",
autoLogin: "off",
font: "on",
};

const reloadFEUPSigarraPages = () => {
chrome.tabs.query({ url: "*://sigarra.up.pt/feup/*" }, (tabs) => {
tabs.forEach((tab) => {
chrome.tabs.reload(tab.id);
chrome.tabs.query({ url: "*://sigarra.up.pt/feup/*" }, (tabs) => {
tabs.forEach((tab) => {
chrome.tabs.reload(tab.id);
});
});
});
}
};

chrome.runtime.onInstalled.addListener((object) => {
if (object.reason === "install") {
reloadFEUPSigarraPages()
if (object.reason === "install") {
reloadFEUPSigarraPages();

if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
chrome.tabs.create({
url: chrome.runtime.getURL("html/autorize.html")
});
}else{
chrome.tabs.create({
url: chrome.runtime.getURL("html/installed.html")
});
}
if (navigator.userAgent.toLowerCase().indexOf("firefox") > -1) {
chrome.tabs.create({
url: chrome.runtime.getURL("html/autorize.html"),
});
} else {
chrome.tabs.create({
url: chrome.runtime.getURL("html/installed.html"),
});
}

chrome.storage.local.set(popupOptions);
}
chrome.storage.local.set(popupOptions);
}

if (object.reason === "update") {
reloadFEUPSigarraPages();
for (const opt in popupOptions) {
if (chrome.storage.local.get(opt) == null)
chrome.storage.local.set({[opt]: popupOptions[opt]});
if (object.reason === "update") {
reloadFEUPSigarraPages();
for (const opt in popupOptions) {
if (chrome.storage.local.get(opt) == null)
chrome.storage.local.set({ [opt]: popupOptions[opt] });
}
}
}
});


chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
if(!sender.tab.active){
console.log("tab not active skipping message...")
return;
}
if (message.type == "login") {
const cookie = await chrome.cookies.get({ name: "SI_SESSION", url: sender.tab.url })
console.log(cookie)
if(cookie == null || cookie.value === "0"){
sendResponse(false);
return;
if (!sender.tab.active) {
console.log("tab not active skipping message...");
return;
}
if (message.type == "login") {
const cookie = await chrome.cookies.get({
name: "SI_SESSION",
url: sender.tab.url,
});
console.log(cookie);
if (cookie == null || cookie.value === "0") {
sendResponse(false);
return;
}
message.auto_login.verifed = true;
await chrome.storage.local.set({ auto_login: message.auto_login });
sendResponse(true);
}
message.auto_login.verifed = true;
await chrome.storage.local.set({ auto_login: message.auto_login });
sendResponse(true);
}
});

chrome.permissions.onRemoved.addListener((permissions) => {
//TODO:
});
//TODO:
});
19 changes: 15 additions & 4 deletions content-scripts/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import jsx from "texsaur";
import Icon from "./Icon";

Expand All @@ -9,13 +10,23 @@ interface ButtonProps {
onclick?: (e: Event) => void;
}

const Button: JSX.Component<ButtonProps> = ({ title, icon, id, className, onclick }) => {
const Button: JSX.Component<ButtonProps> = ({
title,
icon,
id,
className,
onclick,
}) => {
return (
<button id={id ? id : ""} className={className ? className : ""} onclick={onclick}>
<button
id={id ? id : ""}
className={className ? className : ""}
onclick={onclick}
>
{icon ? <Icon name={icon} /> : ""}
{title ? <span>{title}</span> : ""}
</button>
);
}
};

export default Button;
export default Button;
90 changes: 47 additions & 43 deletions content-scripts/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import jsx from "texsaur";

import HeaderLinks from "./HeaderLinks";
import Authentication from "./HeaderAuthentication";
import { AuthSession } from "../types";

const HEADER_LINKS = {
Estudantes: {
Bolsas: "web_base.gera_pagina?p_pagina=242366",
"Escolher turmas": "it_geral.ver_insc",
"Estatutos especiais": "web_base.gera_pagina?p_pagina=242322",
Exames: "web_base.gera_pagina?p_pagina=242382",
Matrículas: "web_base.gera_pagina?p_pagina=31583",
Propinas: "web_base.gera_pagina?p_pagina=propinas ano corrente",
"Mais opções": "web_base.gera_pagina?p_pagina=ESTUDANTES",
},
Faculdade: {
Alumni: "web_base.gera_pagina?p_pagina=243186",
"Calendário escolar":
"web_base.gera_pagina?p_pagina=página estática genérica 106",
Cursos: "cur_geral.cur_inicio",
Departamentos: "uni_geral.nivel_list?pv_nivel_id=1",
Empresas: "web_base.gera_pagina?p_pagina=242380",
Governo: "web_base.gera_pagina?p_pagina=31715",
Notícias: "noticias_geral.lista_noticias",
"Serviços/Gabinetes": "uni_geral.nivel_list?pv_nivel_id=4",
},
Pesquisa: {
Edifícios: "instal_geral.edificio_query",
Estudantes: "fest_geral.fest_query",
Horários: "hor_geral.pesquisa_form",
Notícias: "noticias_geral.pesquisa",
Pessoal: "func_geral.formquery",
"Projetos de investigação": "projectos_geral.pesquisa_projectos",
Publicações: "pub_geral.pub_pesquisa",
Salas: "instal_geral.espaco_query",
Turmas: "it_turmas_geral.formquery",
"Unidades Curriculares": "ucurr_geral.pesquisa_ucs",
"Mais opções": "web_base.gera_pagina?p_pagina=1831",
},
Estudantes: {
Bolsas: "web_base.gera_pagina?p_pagina=242366",
"Escolher turmas": "it_geral.ver_insc",
"Estatutos especiais": "web_base.gera_pagina?p_pagina=242322",
Exames: "web_base.gera_pagina?p_pagina=242382",
Matrículas: "web_base.gera_pagina?p_pagina=31583",
Propinas: "web_base.gera_pagina?p_pagina=propinas ano corrente",
"Mais opções": "web_base.gera_pagina?p_pagina=ESTUDANTES",
},
Faculdade: {
Alumni: "web_base.gera_pagina?p_pagina=243186",
"Calendário escolar":
"web_base.gera_pagina?p_pagina=página estática genérica 106",
Cursos: "cur_geral.cur_inicio",
Departamentos: "uni_geral.nivel_list?pv_nivel_id=1",
Empresas: "web_base.gera_pagina?p_pagina=242380",
Governo: "web_base.gera_pagina?p_pagina=31715",
Notícias: "noticias_geral.lista_noticias",
"Serviços/Gabinetes": "uni_geral.nivel_list?pv_nivel_id=4",
},
Pesquisa: {
Edifícios: "instal_geral.edificio_query",
Estudantes: "fest_geral.fest_query",
Horários: "hor_geral.pesquisa_form",
Notícias: "noticias_geral.pesquisa",
Pessoal: "func_geral.formquery",
"Projetos de investigação": "projectos_geral.pesquisa_projectos",
Publicações: "pub_geral.pub_pesquisa",
Salas: "instal_geral.espaco_query",
Turmas: "it_turmas_geral.formquery",
"Unidades Curriculares": "ucurr_geral.pesquisa_ucs",
"Mais opções": "web_base.gera_pagina?p_pagina=1831",
},
};

interface Props {
auth?: AuthSession | null;
auth?: AuthSession | null;
}

const Header = ({ auth = null }: Props) => {
return (
<header id="se-header">
<a id="se-logo" href="/feup">
<img src={chrome.runtime.getURL("images/FEUP.svg")} alt="FEUP Logo" />
</a>
<HeaderLinks links={HEADER_LINKS} />
<Authentication auth={auth} />
</header>
);
return (
<header id="se-header">
<a id="se-logo" href="/feup">
<img
src={chrome.runtime.getURL("images/FEUP.svg")}
alt="FEUP Logo"
/>
</a>
<HeaderLinks links={HEADER_LINKS} />
<Authentication auth={auth} />
</header>
);
};

export default Header;
Loading

0 comments on commit 24ebe74

Please sign in to comment.