[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧩 logseq.provideStyle #26

Open
utterances-bot opened this issue Jul 13, 2024 · 1 comment
Open

🧩 logseq.provideStyle #26

utterances-bot opened this issue Jul 13, 2024 · 1 comment

Comments

@utterances-bot
Copy link

https://plugins-doc.logseq.com/logseq/provideStyle

Copy link
YU000jp commented Jul 13, 2024

How to toggle CSS in plugin settings

import { LSPluginBaseInfo } from '@logseq/libs/dist/LSPlugin.user'

const keyCssA = "cssA"

// first load
if(logseq.settings!.configBooleanA === true) provideCssA()

// Changed
logseq.onSettingsChanged(async (newSet: LSPluginBaseInfo['settings'], oldSet: LSPluginBaseInfo['settings']) => {

    if(newSet.configBooleanA === true && oldSet.configBooleanA === false){
   provideCssA()
   } else
       if (newSet.configBooleanA === false && oldSet.configBooleanA === true){
   removeProvideCss(keyCssA)
   }

}

// Set <style>
const provideCssA = () => {
logseq.provideStyle({
key: keyCssA, // A plugin-specific key is added to this keyword.
style: `
/* CSS here */

`})
}

// Remove <style>
const removeProvideCss = (className: string) => {
  const doc = parent.document.head.querySelector(`style[data-injected-style^="${className}"]`) as HTMLStyleElement | null
  if (doc) doc.remove()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants