Rewrite Fetch & Add Inline Component

This commit is contained in:
Paul
2023-08-23 18:01:54 +08:00
parent bf62f2a297
commit 65b2b86b78
8 changed files with 142 additions and 2 deletions
+27
View File
@@ -0,0 +1,27 @@
import type { PlasmoCSConfig, PlasmoGetInlineAnchor } from "plasmo"
export const config: PlasmoCSConfig = {
matches: ["<all_urls>"]
}
export const getInlineAnchor: PlasmoGetInlineAnchor = () =>
// document.querySelector(`[href="/#pricing"]`)
document.querySelector(`.text-secondly`);
// Use this to optimize unmount lookups
// export const getShadowHostId = () => "plasmo-inline-example-unique-id"
const PlasmoInline = () => {
return (
<div
style={{
borderRadius: 4,
padding: 4,
background: "pink"
}}>
CSUI INLINE
</div>
)
}
export default PlasmoInline
+41
View File
@@ -0,0 +1,41 @@
import type { PlasmoCSConfig, PlasmoGetInlineAnchor } from "plasmo"
import { sendToBackground } from "@plasmohq/messaging"
export const config: PlasmoCSConfig = {
matches: ["<all_urls>"]
}
export const getInlineAnchor: PlasmoGetInlineAnchor = () =>
// document.querySelector(`[href="/#pricing"]`)
document.querySelector(`.pgc-space-follow-page`);
// Use this to optimize unmount lookups
// export const getShadowHostId = () => "plasmo-inline-example-unique-id"
const PlasmoInline = () => {
const onClick = () => {
const resp = sendToBackground({
name: "test",
body: {
id: 123
}
}).then((res) => {
console.log(res);
})
}
return (
<div
style={{
borderRadius: 4,
padding: 4,
background: "pink"
}}
onClick={onClick}
>
CSUI INLINE
</div>
)
}
export default PlasmoInline
+22
View File
@@ -0,0 +1,22 @@
import type { PlasmoCSConfig } from "plasmo"
export const config: PlasmoCSConfig = {
matches: ["<all_urls>"],
world: "MAIN"
}
// export {}
console.log(
"You may find that having is not so pleasing a thing as wanting. This is not logical, but it is often true."
)
const defaultFetch = window.fetch;
window.fetch = (...args) => {
console.log(args);
return defaultFetch(...args);
}
console.log(fetch);