class DOM { static toggleEl ( el ) { el . style . display = el . style . display === 'block' ? 'none' : 'block' ; } static insertToHead < T extends Element > ( el ) { const insertPoint = document . body . querySelector ( '#root' ) ; if ( insertPoint ) { insertPoint . insertAdjacentElement ( 'afterbegin' , el ) ; } return el ; } static getUserId ( ) { const Reg = /creator\/(\d*)?/ ; const testString = [ location . href , document . head . innerHTML ] ; for ( const string of testString ) { const result = Reg . exec ( string ) ; if ( result && result . length > 1 ) { return result [ 1 ] ; } } throw new Error ( 'getUserId failed!' ) ; } static addStyle ( css ) { const e = document . createElement ( 'style' ) ; e . innerHTML = css ; document . body . append ( e ) ; } static findSlot ( name ) { const slot = document . querySelector ( `slot[data-name=${ name }]` ) ; if ( ! slot ) { throw new Error ( `No such slot: ${ name }` ) ; } return slot ; } static useSlot ( name , element ) { const slot = this . findSlot ( name ) ; if ( typeof element === 'string' ) { const wrap = document . createElement ( 'div' ) ; wrap . innerHTML = element ; const el = wrap . children [ 0 ] ; slot . appendChild ( el ) ; return el ; } else { slot . appendChild ( element ) ; return element ; } } static clearSlot ( name ) { this . findSlot ( name ) . innerHTML = '' ; } static addBtn ( slot , bg = '' , text = '' , attr = [ ] ) { const e = document . createElement ( 'button' ) ; e . type = 'button' ; e . style . backgroundColor = bg ; e . textContent = text ; for ( const [ key , value ] of attr ) { e . setAttribute ( key , value ) ; } this . useSlot ( slot , e ) ; return e ; } } export { DOM } ;