import './styles.scss' ; import { App , Plugin , PluginManifest , MarkdownView } from "obsidian" ; const excludeLangs = [ "todoist" ] ; export default class CMSyntaxHighlightPlugin extends Plugin { constructor ( app , pluginManifest ) { super ( app , pluginManifest ) ; } async onload ( ) { this . registerInterval ( window . setInterval ( this . injectButtons . bind ( this ) , 1000 ) ) ; } injectButtons ( ) { this . addCopyButtons ( navigator . clipboard ) ; } addCopyButtons ( clipboard ) { document . querySelectorAll ( 'pre > code' ) . forEach ( function ( codeBlock ) { var pre = codeBlock . parentNode ; for ( let lang of excludeLangs ) { if ( pre . classList . contains ( `language-${ lang }` ) ) return ; } if ( pre . parentNode . classList . contains ( 'has-copy-button' ) ) { return ; } pre . parentNode . classList . add ( 'has-copy-button' ) ; var button = document . createElement ( 'button' ) ; button . className = 'copy-code-button' ; button . type = 'button' ; button . innerText = 'Copy' ; button . addEventListener ( 'click' , function ( ) { clipboard . writeText ( codeBlock . innerText ) . then ( function ( ) { button . blur ( ) ; button . innerText = 'copied!' ; setTimeout ( function ( ) { button . innerText = 'copy' ; } , 2000 ) ; } , function ( error ) { button . innerText = 'Error' ; } ) ; } ) ; pre . appendChild ( button ) ; } ) ; } }