-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from riskycase/vitefy
Vitefy
- Loading branch information
Showing
25 changed files
with
4,034 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + Preact + TS</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
{ | ||
"name": "auto-campnet-gui", | ||
"version": "0.2.1", | ||
"scripts": { | ||
"tauri": "tauri", | ||
"dev": "tauri dev", | ||
"build": "tauri build", | ||
"tauricon": "tauricon" | ||
}, | ||
"dependencies": { | ||
"@tauri-apps/api": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@tauri-apps/cli": "^1.1.1" | ||
} | ||
"name": "auto-campnet-gui", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"tauri": "tauri", | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"tauricon": "tauricon" | ||
}, | ||
"dependencies": { | ||
"@cred/neopop-web": "^1.0.0", | ||
"@tauri-apps/api": "^1.1.0", | ||
"axios": "^1.1.3", | ||
"preact": "^10.11.2", | ||
"querystring": "^0.2.1", | ||
"sass": "^1.55.0" | ||
}, | ||
"devDependencies": { | ||
"@preact/preset-vite": "^2.4.0", | ||
"@tauri-apps/cli": "^1.1.1", | ||
"@types/node": "^18.11.7", | ||
"typescript": "^4.8.4", | ||
"vite": "^3.2.0" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.mainContainer { | ||
display: flex; | ||
padding: 1rem; | ||
align-items: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import styles from "./app.module.scss"; | ||
import { emit, listen, Event } from "@tauri-apps/api/event"; | ||
import { Login } from "./components/login/login"; | ||
import { ElevatedCard, ToastContainer } from "@cred/neopop-web/lib/components"; | ||
import { useEffect, useState } from "preact/hooks"; | ||
import { DataBalance } from "./components/dataBalance/dataBalance"; | ||
import { Credentials } from "./types"; | ||
|
||
export function App() { | ||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
|
||
useEffect(() => { | ||
listen("credentials", (creds: Event<Credentials>) => { | ||
setUsername(creds.payload.username); | ||
setPassword(creds.payload.password); | ||
}); | ||
}, []); | ||
|
||
document.addEventListener("visibilitychange", () => { | ||
if (document.visibilityState === "hidden") emit("minimise"); | ||
}); | ||
|
||
return ( | ||
<div> | ||
<ToastContainer /> | ||
<ElevatedCard | ||
backgroundColor="#0D0D0D" | ||
edgeColors={{ | ||
bottom: "#161616", | ||
right: "#121212", | ||
}} | ||
> | ||
<div class={styles.mainContainer}> | ||
<Login | ||
username={username} | ||
password={password} | ||
setUsername={setUsername} | ||
setPassword={setPassword} | ||
/> | ||
<DataBalance username={username} password={password} /> | ||
</div> | ||
</ElevatedCard> | ||
</div> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.dataContainer { | ||
padding: 1rem; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-family: 'Times New Roman', Times, serif; | ||
@media screen and (max-width: 640px) { | ||
display: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { ScoreMeter } from "@cred/neopop-web/lib/components"; | ||
import { fetch, getClient, Body, ResponseType } from "@tauri-apps/api/http"; | ||
import { useEffect, useState } from "preact/hooks"; | ||
|
||
import styles from "./dataBalance.module.scss"; | ||
|
||
export function DataBalance(props: { username: string; password: string }) { | ||
const [datas, setDatas] = useState<Array<number>>([1, 0, 0, 1, 0]); | ||
const [units, setUnits] = useState<Array<string>>(["", "", "", "", ""]); | ||
const [balanceTimeout, setBalanceTimeOut] = useState<NodeJS.Timeout>(); | ||
|
||
useEffect(() => { | ||
clearTimeout(balanceTimeout); | ||
getBalance(); | ||
}, [props]); | ||
console.log(datas); | ||
|
||
function getBalance() { | ||
let cookie = ""; | ||
let csrf = ""; | ||
getClient({ maxRedirections: 1 }).then((client) => | ||
client | ||
.post( | ||
"https://campnet.bits-goa.ac.in:8093/userportal/Controller", | ||
Body.form({ | ||
mode: "451", | ||
json: JSON.stringify({ | ||
username: props.username, | ||
password: props.password, | ||
languageid: 1, | ||
browser: "Chrome_106", | ||
}), | ||
}) | ||
) | ||
.then( | ||
(res) => (cookie = res.headers["set-cookie"].split(";")[0]) | ||
) | ||
.then(() => | ||
fetch( | ||
"https://campnet.bits-goa.ac.in:8093/userportal/webpages/myaccount/index.jsp", | ||
{ | ||
method: "GET", | ||
headers: { | ||
Cookie: cookie, | ||
}, | ||
responseType: ResponseType.Text, | ||
} | ||
) | ||
) | ||
.then((res) => { | ||
//@ts-ignore | ||
csrf = String(res.data).match(/k3n = '(.+)'/)[1]; | ||
}) | ||
.then(() => | ||
client.get( | ||
"https://campnet.bits-goa.ac.in:8093/userportal/webpages/myaccount/AccountStatus.jsp", | ||
{ | ||
headers: { | ||
Cookie: cookie, | ||
"X-CSRF-Token": csrf, | ||
Referer: | ||
"https://campnet.bits-goa.ac.in:8093/userportal/webpages/myaccount/login.jsp", | ||
}, | ||
query: { | ||
popup: `${0}`, | ||
t: `${Date.now()}`, | ||
}, | ||
responseType: ResponseType.Text, | ||
} | ||
) | ||
) | ||
.then((res: any) => { | ||
const nodes = new DOMParser().parseFromString( | ||
res.data, | ||
"text/html" | ||
); | ||
const trimmedNodes = [ | ||
...nodes | ||
.querySelector("#content3") | ||
?.querySelectorAll("td.tabletext")!! | ||
].slice(-5); | ||
setDatas( | ||
trimmedNodes.map((iter: any) => | ||
Number( | ||
( | ||
iter.childNodes[0].nodeValue as string | ||
).trim() | ||
) | ||
) | ||
); | ||
setUnits( | ||
trimmedNodes.map((iter: any) => | ||
iter.children[0].id.replace(/Language./, "") | ||
) | ||
); | ||
}) | ||
.then(() => setBalanceTimeOut(setTimeout(getBalance, 15000))) | ||
.catch((err) => console.error(err)) | ||
); | ||
} | ||
|
||
return ( | ||
<div class={styles.dataContainer}> | ||
<ScoreMeter | ||
key={datas[4]} | ||
reading={Math.round(datas[4])} | ||
oldReading={0} | ||
lowerLimit={0} | ||
upperLimit={datas[0]} | ||
scoreDesc={units[4]} | ||
type={ | ||
datas[4] < datas[0] / 5 | ||
? "poor" | ||
: datas[4] < datas[0] / 3 | ||
? "average" | ||
: "excellent" | ||
} | ||
/> | ||
<span>Data Limit: {`${datas[0]} ${units[0]}`}</span> | ||
<span>Data Used: {`${datas[3]} ${units[3]}`}</span> | ||
<span>Data Left: {`${datas[4]} ${units[4]}`}</span> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.loginContainer { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
max-width: 20rem; | ||
padding: 1rem; | ||
} | ||
|
||
.loginContainer > * { | ||
margin: 0.5rem 0; | ||
} | ||
|
||
.bitsLogo { | ||
margin: 1rem 0; | ||
height: 6.5rem; | ||
width: 100%; | ||
} |
Oops, something went wrong.