Skip to content

Commit b12ff1a

Browse files
committed
login
1 parent c076712 commit b12ff1a

File tree

5 files changed

+148
-12
lines changed

5 files changed

+148
-12
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@jetbrains/logos": "^2.2.7",
1414
"@plasmohq/storage": "^0.12.2",
1515
"antd": "^4.23.5",
16+
"crypto-js": "^4.1.1",
1617
"react": "18.2.0",
1718
"react-dom": "18.2.0"
1819
},
@@ -23,7 +24,7 @@
2324
"@types/node": "18.8.3",
2425
"@types/react": "18.0.21",
2526
"@types/react-dom": "18.0.6",
26-
"plasmo": "0.57.1",
27+
"plasmo": "0.57.2",
2728
"prettier": "2.7.1",
2829
"typescript": "4.8.4"
2930
},
@@ -34,6 +35,8 @@
3435
"https://leetcode.com/*",
3536
"https://codetop.cc/*"
3637
],
37-
"permissions": []
38+
"permissions": [
39+
"cookies"
40+
]
3841
}
3942
}

pnpm-lock.yaml

Lines changed: 16 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/background.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import CryptoJS from 'crypto-js'
2+
console.log("HELLO WORLD")
3+
4+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
5+
if (message === 'get-user-data') {
6+
chrome.cookies.getAll({domain: sender.origin.replace("https://", "")}).then((cookies) => {
7+
const cookieString = cookies.map(c => c.name + "=" + c.value).join(';');
8+
console.log(cookieString);
9+
const encodedWord = CryptoJS.enc.Utf8.parse(cookieString);
10+
const encoded = CryptoJS.enc.Base64.stringify(encodedWord);
11+
sendResponse(encoded);
12+
});
13+
}
14+
return true
15+
});

src/contents/leetcode-cn-login.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type {PlasmoContentScript, PlasmoGetInlineAnchor} from "plasmo"
2+
import {Button, Tooltip} from 'antd';
3+
import cssText from "data-text:~/src/index.less"
4+
5+
import {useStorage} from "@plasmohq/storage/hook"
6+
7+
import {GetLogoSize} from "~logo"
8+
9+
export const config: PlasmoContentScript = {
10+
matches: ["https://leetcode.cn/*"]
11+
}
12+
13+
export const getStyle = () => {
14+
const style = document.createElement("style")
15+
style.textContent = cssText
16+
return style
17+
}
18+
19+
// Use this to optimize unmount lookups
20+
export const getShadowHostId = () => "leetcode-editor-login-id"
21+
22+
export const getInlineAnchor: PlasmoGetInlineAnchor = () =>
23+
document.querySelector("a[href='/accounts/logout/']")
24+
25+
26+
const LeetcodeCnLogin = () => {
27+
28+
const [showIcon] = useStorage("ShowIcon", true)
29+
const logo = GetLogoSize(14)
30+
const url = GetUrl()
31+
32+
function click() {
33+
chrome.runtime.sendMessage('get-user-data', (response) => {
34+
window.open(url+response)
35+
});
36+
37+
}
38+
39+
return (
40+
<Tooltip title="IDE Login">
41+
<Button hidden={!showIcon} type="text" onClick={click} icon={logo} target='_blank'> Login </Button>
42+
</Tooltip>
43+
44+
)
45+
}
46+
47+
48+
const GetUrl = () => {
49+
const [editor] = useStorage("Editor", "leetcode-editor-pro")
50+
const [product] = useStorage("Product", "idea")
51+
const [project] = useStorage("Project", "")
52+
53+
return "jetbrains://" + product + "/" + editor + "/login?project=" + project + "&token="
54+
}
55+
56+
export default LeetcodeCnLogin

src/contents/leetcode-com-login.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type {PlasmoContentScript, PlasmoGetInlineAnchor} from "plasmo"
2+
import {Button, Tooltip} from 'antd';
3+
import cssText from "data-text:~/src/index.less"
4+
5+
import {useStorage} from "@plasmohq/storage/hook"
6+
7+
import {GetLogoSize} from "~logo"
8+
9+
export const config: PlasmoContentScript = {
10+
matches: ["https://leetcode.com/*"]
11+
}
12+
13+
export const getStyle = () => {
14+
const style = document.createElement("style")
15+
style.textContent = cssText
16+
return style
17+
}
18+
19+
// Use this to optimize unmount lookups
20+
export const getShadowHostId = () => "leetcode-editor-login-id"
21+
22+
export const getInlineAnchor: PlasmoGetInlineAnchor = () =>
23+
document.querySelector(".user-menu__JejQ > li:last-child ")
24+
25+
26+
const LeetcodeComLogin = () => {
27+
28+
const [showIcon] = useStorage("ShowIcon", true)
29+
const logo = GetLogoSize(14)
30+
const url = GetUrl()
31+
32+
function click() {
33+
chrome.runtime.sendMessage('get-user-data', (response) => {
34+
window.open(url+response)
35+
});
36+
37+
}
38+
39+
return (
40+
<Tooltip title="IDE Login">
41+
<Button hidden={!showIcon} type="text" onClick={click} icon={logo} target='_blank'> Login </Button>
42+
</Tooltip>
43+
44+
)
45+
}
46+
47+
48+
const GetUrl = () => {
49+
const [editor] = useStorage("Editor", "leetcode-editor-pro")
50+
const [product] = useStorage("Product", "idea")
51+
const [project] = useStorage("Project", "")
52+
53+
return "jetbrains://" + product + "/" + editor + "/login?project=" + project + "&token="
54+
}
55+
56+
export default LeetcodeComLogin

0 commit comments

Comments
 (0)