Skip to content

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Feb 21, 2024
0 parents commit c982966
Show file tree
Hide file tree
Showing 20 changed files with 7,115 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/submit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Submit to Web Store"
on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/[email protected]
with:
version: latest
run_install: true
- name: Use Node.js 16.x
uses: actions/[email protected]
with:
node-version: 16.x
cache: "pnpm"
- name: Build the extension
run: pnpm build
- name: Package the extension into a zip artifact
run: pnpm package
- name: Browser Platform Publish
uses: PlasmoHQ/bpp@v3
with:
keys: ${{ secrets.SUBMIT_KEYS }}
artifact: build/chrome-mv3-prod.zip
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

#cache
.turbo
.next
.vercel

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*


# local env files
.env*

out/
build/
dist/

# plasmo - https://www.plasmo.com
.plasmo

# bpp - http://bpp.browser.market/
keys.json

# typescript
.tsbuildinfo
26 changes: 26 additions & 0 deletions .prettierrc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @type {import('prettier').Options}
*/
export default {
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: false,
singleQuote: false,
trailingComma: "none",
bracketSpacing: true,
bracketSameLine: true,
plugins: ["@ianvs/prettier-plugin-sort-imports"],
importOrder: [
"<BUILTIN_MODULES>", // Node.js built-in modules
"<THIRD_PARTY_MODULES>", // Imports not matched by other special words or groups.
"", // Empty line
"^@plasmo/(.*)$",
"",
"^@plasmohq/(.*)$",
"",
"^~(.*)$",
"",
"^[./]"
]
}
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
This is a [Plasmo extension](https://docs.plasmo.com/) project bootstrapped with [`plasmo init`](https://www.npmjs.com/package/plasmo).

## Getting Started

First, run the development server:

```bash
pnpm dev
# or
npm run dev
```

Open your browser and load the appropriate development build. For example, if you are developing for the chrome browser, using manifest v3, use: `build/chrome-mv3-dev`.

You can start editing the popup by modifying `popup.tsx`. It should auto-update as you make changes. To add an options page, simply add a `options.tsx` file to the root of the project, with a react component default exported. Likewise to add a content page, add a `content.ts` file to the root of the project, importing some module and do some logic, then reload the extension on your browser.

For further guidance, [visit our Documentation](https://docs.plasmo.com/)

## Making production build

Run the following:

```bash
pnpm build
# or
npm run build
```

This should create a production bundle for your extension, ready to be zipped and published to the stores.

## Submit to the webstores

The easiest way to deploy your Plasmo extension is to use the built-in [bpp](https://bpp.browser.market) GitHub action. Prior to using this action however, make sure to build your extension and upload the first version to the store to establish the basic credentials. Then, simply follow [this setup instruction](https://docs.plasmo.com/framework/workflows/submit) and you should be on your way for automated submission!
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions background/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Storage } from "@plasmohq/storage"

import { STORAGE_SERVER_STATUS, STORAGE_SERVERS } from "~constants"
import { getSelectedServer } from "~util"

export {}

async function checkServer(server: Server) {
try {
await fetch(server.url)
return true
} catch (e) {
return false
}
}

;(async function () {
const storage = new Storage()

async function checkAllServers() {
const servers = await storage.get<Server[]>(STORAGE_SERVERS)
if (!servers || servers.length === 0) return
await Promise.all(
servers.map(async (server) => {
const status = await checkServer(server)
const prev = await storage.get<Record<string, boolean>>(
STORAGE_SERVER_STATUS
)
await storage.set(STORAGE_SERVER_STATUS, {
...prev,
[server.url]: status
})
})
)
}
checkAllServers()
setInterval(checkAllServers, 3000)
})()

chrome.downloads.onDeterminingFilename.addListener(async function (item) {
const server = await getSelectedServer()
if (!server) return

await chrome.downloads.cancel(item.id)
if (item.state === "complete") {
await chrome.downloads.removeFile(item.id)
}

chrome.system.display.getInfo({ singleUnified: true }, (info) => {
const wDimension = info[0].workArea
const { top, left, height, width } = wDimension
const w = 480
const h = 600
const l = width / 2 - w / 2 + left
const t = height / 2 - h / 2 + top
const asset = <Asset>{
filename: item.filename,
filesize: item.fileSize,
finalUrl: item.finalUrl
}

chrome.windows.create({
url: `tabs/create.html?asset=${encodeURIComponent(
JSON.stringify(asset)
)}`,
type: "popup",
width: w,
height: h,
left: Math.round(l),
top: Math.round(t)
})
})
})
18 changes: 18 additions & 0 deletions background/messages/api/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Client from "@gopeed/rest"
import type { CreateTaskWithRequest } from "@gopeed/types"

import type { PlasmoMessaging } from "@plasmohq/messaging"

import { getSelectedServer } from "~util"

const handler: PlasmoMessaging.MessageHandler<
CreateTaskWithRequest,
void
> = async (req, res) => {
const server = await getSelectedServer()
const client = new Client({ host: server.url, token: server.token })
await client.createTask(req.body)
res.send()
}

export default handler
17 changes: 17 additions & 0 deletions components/theme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CssBaseline } from "@mui/material"
import { createTheme, ThemeProvider } from "@mui/material/styles"

const darkTheme = createTheme({
palette: {
mode: "dark"
}
})

export default function Theme(props: { children: React.ReactNode }) {
return (
<ThemeProvider theme={darkTheme}>
<CssBaseline />
{props.children}
</ThemeProvider>
)
}
3 changes: 3 additions & 0 deletions constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const STORAGE_SERVER_SELECTED = "serverSelected"
export const STORAGE_SERVERS = "servers"
export const STORAGE_SERVER_STATUS = "serverStatus"
52 changes: 52 additions & 0 deletions contents/sniffer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import createCache from "@emotion/cache"
import { CacheProvider } from "@emotion/react"
import { Alert } from "@mui/material"
import Button from "@mui/material/Button"
import Input from "@mui/material/Input"
import Link from "@mui/material/Link"
import Stack from "@mui/material/Stack"
import Typography from "@mui/material/Typography"
import type { PlasmoGetInlineAnchor, PlasmoGetOverlayAnchor } from "plasmo"
import { useEffect, useState } from "react"

// export const getInlineAnchor: PlasmoGetInlineAnchor = async () =>
// document.querySelector("div.TimelineItem-avatar")

// export const getOverlayAnchor: PlasmoGetOverlayAnchor = async () =>
// document.querySelector("a.TimelineItem-avatar")

const styleElement = document.createElement("style")

const styleCache = createCache({
key: "plasmo-mui-cache",
prepend: true,
container: styleElement
})

export const getStyle = () => styleElement

function PlasmoOverlay() {
const [data, setData] = useState("")

return (
{/* <CacheProvider value={styleCache}>
<Stack minWidth={240} bgcolor={"white"} padding={2}>
<Alert severity="error">This is an error alert — check it out!</Alert>
<Typography variant="h6">
Welcome to your{" "}
<Link href="https://www.plasmo.com" target="_blank">
Plasmo 123
</Link>{" "}
Extension!
</Typography>
<Input onChange={(e) => setData(e.target.value)} value={data} />
<Button href="https://docs.plasmo.com" target="_blank">
View Docs 2313
</Button>
<Button variant="contained">Hello world</Button>;
</Stack>
</CacheProvider> */}
)
}

export default PlasmoOverlay
35 changes: 35 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"download": {
"message": "DOWNLOAD"
},
"cancel": {
"message": "CANCEL"
},
"server": {
"message": "SERVER"
},
"create": {
"message": "CREATE"
},
"title": {
"message": "Title"
},
"scheme": {
"message": "Scheme"
},
"host": {
"message": "Host"
},
"port": {
"message": "Port"
},
"token": {
"message": "Token"
},
"deleteTip": {
"message": "Are you sure to delete this configuration?"
},
"delete": {
"message": "DELETE"
}
}
35 changes: 35 additions & 0 deletions locales/zh/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"download": {
"message": "下载"
},
"cancel": {
"message": "取消"
},
"server": {
"message": "服务器"
},
"create": {
"message": "创建"
},
"title": {
"message": "标题"
},
"scheme": {
"message": "协议"
},
"host": {
"message": "服务器"
},
"port": {
"message": "端口"
},
"token": {
"message": "接口令牌"
},
"deleteTip": {
"message": "确定要删除此配置吗?"
},
"delete": {
"message": "删除"
}
}
Loading

0 comments on commit c982966

Please sign in to comment.