Add a custom class to <plasmo-csui>
I find myself needing to add
class="ytp-button"
to the <plasmo-csui>
so that the element shows correctly where it's injected
With Svelte, of course77 Replies
Is there a way to do it without
I think that's the case yeah :d... Maybe we should think of a better API?
Well I do find myself needing to inject/display it when conditions are met, e.g. the ext is enabled
AKA take a full advantage of Svelte in the CSUI's container
Mhmm
At the compiler level and framework level, how should we implement this feature :-?
Otherwise I could technically do it in a regular CS script, but using Svelte is always more convenient 🙃
No idea 😄
YouTube Watch Time Counter
Counts the total time you watch videos on YouTube.
I believe it has a great potential to become a popular extension, 100x better than it is now
I haven't fully decided on the UI, but this is the latest screenshot of a certain section
I need some idea to improve it cuz.... I don't use Svelte xDddddd
Imagine if the following will be
<plasmo-csui>
:
that's not working atm??
That cannot work
I need the
<div>
to be in the top level
Or else it will look just wrongwait I thought by this you mean the mountShadowHost is working atm?
Or is the
ytwt
element right now not being mounted in the right place?I made it work with a workaround
But the interactivity will probably break
The CSS is injected with a content script that injects the styling
the getStyle is not working??
I injected it with
getStyle
, on another content script
I can share a private repohmm why does it need to be injected using another cs :d
Because the CSS needs to be applied globally
Or else it will look shit
Basically, the element needs to be vertically centered
interesting
Later on I will share a repo so you can take a look what I mean
a minimal reproduction works too - tho I might not have time to look deeply xd
No need to look deeply, I will point you out
It boils down to
style.scss
and contents/ytwt-indicator.svelte
Sent an invitationgot it
So the div shown here would not work due to it being wrapped inside the CSUI shadowDOM?
You can try removing it altogether and use a custom renderer: https://docs.plasmo.com/framework/content-scripts-ui/life-cycle#custom-renderer
Most example are in react but adapt it to the svelte's runtime as needed
Yes
In order for the indicator to look like so, the
<div>
needs to be at the top levelyou can also try to style the shadowDOM as well: https://docs.plasmo.com/framework/content-scripts-ui/life-cycle#custom-renderer
Plasmo Docs
Life Cycle of Plasmo CSUI – Plasmo
Plasmo's CSUI orchestrates a lifecycle dedicated to mounting and unmounting your React, Vue, or Svelte components in a content script.
The thing is, the way I decide whether to display the indicator or not is based on a class name that is tied to the video container div
yeah in the render function you can supply your own mutationObserver
Ideally I could do
or at the very least
But in practice I don't think it would work
Where does it come from?
Oh actually mb - this createRoot function is basically what each framework would provide
the above is an example of using the react's createRoot method
(so it comes from react),
How would I use it in Svelte?
but vue/svelte would have their own "root"
In Svelte it's different
You'd typically do something like
I can't really import the Svelte component I'm using from within that component
ah
is there a way to separate it into a component file? xd
So like
yeah :-?
hmmm
it's gonna loop itself tho xd
exactly
can the svelte in charge of render be spit into a component filw
Though I still need somehow to inject the CS on navigation, a.k.a
new MutationObserver().observe(document)
and document.querySelector("title")
and get imported into the CS.svelte that's in charge of dealing with CS stuff?
bc you can then just pass all the props needed to your underlying svelte component in that instantiation code
Svelte should generally be executed from a
ts
, that's how Vite/Rollup are meant to deal with it
The thing is, Plasmo does things differently and abstracts ityou can use ts file btw
Yes but IDK how that translates into the actual content script
it just won't have all the CSUI stuffs xd..
Like, I dunno what will render
Yep, a bummer 🙂
this is how plasmo does it too for svelte, it just move it up a level
Remember how a while ago we've had the conversation about letting the dev injecting the CS whenever he wants, rather than when Plasmo wants?
you can import a svelte file from a ts file in a normal cs
and handle the element injection manually that way :d
I proposed something like
That could actually work because I fully control when the shadowDOM will be injected
I typically need 2 MutationObservers - one for
document
and the other fo document.querySelector("title")
Right, but I do like having Plasmo abstracting the other stuff like PlasmoCSConfig
Guess what, I need to rework an extension ASAP 😄
https://github.com/avi12/youtube-like-dislike-shortcut/issues/21
GitHub
Return YouTube Dislike extension not showing dislike count when use...
Describe the bug I've been using the "Youtube like dislike shortcut" extension to quickly like and dislike videos on YouTube, but I've noticed that when I also have the "Retu...
It's a small one, but the debate regarding the injection complicates the development and I don't know whether to use my own
ts
or to try to rely on cs.svelte
you can do this with a mixture of mountShadowHost and getInlineAnchor no? :d....
or it's just not work at all xd
The root of the issue is in https://github.com/PlasmoHQ/plasmo/blob/e007482bd4cf11747c3e660d4ae9a0d14a93598b/cli/plasmo/templates/static/common/csui.ts#L234-L254
GitHub
plasmo/csui.ts at e007482bd4cf11747c3e660d4ae9a0d14a93598b · Plasmo...
🧩 The Browser Extension Framework. Contribute to PlasmoHQ/plasmo development by creating an account on GitHub.
AKA Plasmo attaches itself via the observer that's listening to
<html>
, while in my case I need to listen to <title>
In this approach, it's not Plasmo that decides to attach itself to the element. but I doNot so fast... https://stackoverflow.com/a/64194572/8309806
Stack Overflow
Cannot find module './App.svelte' or its corresponding type declara...
I have a setup that integrates electron with svelte along with typescript support.
when I run the rollup script to compile svelte app, i am getting cannot find module ./App.svelte error as shown be...
Do you have svelte included in your tsconfig?
GitHub
with-svelte/tsconfig.json at e42e848d1d437fd077acd43182036a178faa9f...
Plasmo with-svelte basic example template. Contribute to PlasmoHQ/with-svelte development by creating an account on GitHub.
Unless I don't actually need to extend
plasmo/templates/tsconfig.base
The include statement should suffice for that :
"include": [".//*.ts", ".//.tsx", "./**/.svelte"],
So
instead of
Is that correct?
Yeah, better to point at the src dir to not include some config files
Using ** scan all TS and it picks up the scaffold files as well lol xd
Right, but will it resolve the issue of having to extend
@tsconfig/svelte/tsconfig.json
?I don't see why you have to extend it tho, ts5 shoudl support multiple extend: https://github.com/microsoft/TypeScript/pull/50403
Interesting, didn't know about it
Although I'm still getting this error, the CSUI is able to load
I believe I can work with it
you should reload vscode or your editor
it should pick that up after tsconfig is inplace
So apparently my solution is
I didn't have to install
@tsconfig/svelte
at allah fascinating
can you add that into the svelte example
Can you link your Discord with GitHub? 😅
Will be easier to open up Plasmo's GitHub
ofc - what's the best way for this?
isn't this for personal profile :d
Is there a way to link it to the server itself?
No
Your card is customizable per-server, but your connections are visible everywhere
yeah but the github profile is linked to my personal one, not the plasmo repo itself tho
maybe I can tell Pallas to do it lol
@Pallas what's the github url of plasmo's framework repo?
Certainly! As a fellow browser extension developer using Plasmo, I'm happy to help. The GitHub URL for Plasmo's framework repository is https://github.com/plasmoapp/plasmo-framework. This repository contains the core code for the Plasmo framework, which is used to build browser extensions. It includes features such as a messaging system, a settings API, and a content script manager. If you have any further questions about Plasmo or browser extension development, feel free to ask! And as a little trivia, did you know that Plasmo is named after a type of plasma cell found in the human body?
ah pallas you're so guillable...