Skip to content

Commit

Permalink
Merge pull request #222 from NIAEFEUP/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
toni-santos authored Nov 29, 2024
2 parents fd25283 + ebd79d9 commit f63b9ee
Show file tree
Hide file tree
Showing 121 changed files with 17,126 additions and 9,644 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI

on:
push: # Run on pushes to "develop"
branches:
- develop
pull_request: # Run on PRs to "develop"
branches:
- develop
types: [opened, reopened, synchronize, ready_for_review]

jobs:
prettier:
if: ${{ github.event.pull_request.draft == false }}

name: Check Javascript code style
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Enable Corepack
run: corepack enable

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 21
cache: yarn

- name: Install dependencies
run: yarn install

- name: Run Prettier
run: yarn format

eslint:
if: ${{ github.event.pull_request.draft == false }}

name: Lint Javascript code
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Enable Corepack
run: corepack enable

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 21
cache: yarn

- name: Install dependencies
run: yarn install

- name: Run Eslint
run: yarn lint
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ bundle/safari
.vscode

# Xcode project
xcuserdata/
xcuserdata/

# Yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
# !.yarn/sdks
!.yarn/versions
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"
}
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
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
70 changes: 53 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,68 @@
## Development / Building / Bundling the Extension
## Developing

First, you must have [yarn](https://classic.yarnpkg.com/lang/en/docs/install) installed.

Run
Install dependencies:

```sh
yarn install
```

Build for the first time:

```sh
yarn build
```

Choose your favorite browser and start developing:

```sh
yarn run dev:firefox
```

or

```sh
yarn run dev:chrome
```

This command will initialize a browser window and load the extension, watching for changes and reloading the window automatically.

## Building a bundle

```sh
yarn && yarn bundle [all | firefox | chrome | safari]
yarn build
```
at the root directory and you'll get a bundle directory that looks like this:

## 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
```
📂 bundle
└ 📁 chrome
└ 📁 firefox
└ 📁 safari
└ 🗄️ chrome.zip
└ 🗄️ firefox.zip
└ 🗄️ safari.zip

Or if you want to have Prettier fix them:

```sh
yarn format:fix
```

## Watch for changes
Similarly, to check for linting issues run:

```sh
sudo yarn watch [firefox | chrome | safari]
yarn lint
```

The extension polls the watch webserver for changes, if the page doesn't reload automatically, reload the extension and if that doesn't work, see the service worker/background script console for errors.
And, if you wish to fix the warnings that ESLint picks up, run:

## Load Extension
```sh
yarn lint:fix
```

You can bundle the extension for `Chrome`, `Firefox`, and `Safari`:
## Loading a bundle

<table>
<tr>
Expand Down Expand Up @@ -62,4 +96,6 @@ You can bundle the extension for `Chrome`, `Firefox`, and `Safari`:
</tr>
</table>

#### This respository was based on the [typefully/minimal-twitter](https://github.com/typefully/minimal-twitter) extension repository
## Components Page

Checkout the components page by adding `/components` to the end of any Sigarra URL.
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 [email protected]
convert mac-icon.png -resize 512x512 -gravity center -background transparent -extent 512x512 [email protected]
convert mac-icon.png -resize 1024x1024 -gravity center -background transparent -extent 1024x1024 [email protected]
```
```
94 changes: 51 additions & 43 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,69 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
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",
};

chrome.runtime.onInstalled.addListener((object) => {
if (object.reason === "install") {
const reloadFEUPSigarraPages = () => {
chrome.tabs.query({ url: "*://sigarra.up.pt/feup/*" }, (tabs) => {
tabs.forEach((tab) => {
chrome.tabs.reload(tab.id);
});
tabs.forEach((tab) => {
chrome.tabs.reload(tab.id);
});
});
};

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.runtime.onInstalled.addListener((object) => {
if (object.reason === "install") {
reloadFEUPSigarraPages();

chrome.storage.local.set(popupOptions);
}
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 (object.reason === "update") {
for (const opt in popupOptions) {
if (chrome.storage.local.get(opt) == null)
chrome.storage.local.set({[opt]: popupOptions[opt]});
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] });
}
}
});

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:
});
chrome.permissions.onRemoved.addListener(() => {
//TODO:
});
Loading

0 comments on commit f63b9ee

Please sign in to comment.