const NSYS_BB = "https://bb.nsystools.com"; const RESOURCES = { JS: '/js/nbw.min.js', CSS: '/css/nbw.min.css', FONTS: '/css/font-faces.css', }; function makeUrl(path) { return NSYS_BB + path; } async function addNodeToShadow(node) { let head = document.getElementById('nsys_buyback_widget').shadowRoot; head.appendChild(node); } function loadScript(url) { const scriptNode = document.createElement('script'); scriptNode.type = 'text/javascript'; scriptNode.src = makeUrl(url); addNodeToShadow(scriptNode); } function loadStyles(url) { const styleNode = document.createElement('link'); styleNode.type = 'text/css'; styleNode.rel = 'stylesheet'; styleNode.href = makeUrl(url); addNodeToShadow(styleNode); } function loadFonts(url) { const styleNode = document.createElement('link'); styleNode.type = 'text/css'; styleNode.rel = 'stylesheet'; styleNode.href = makeUrl(url); document.head.appendChild(styleNode); } function entryPoint() { loadStyles(RESOURCES.CSS); loadScript(RESOURCES.JS); loadFonts(RESOURCES.FONTS); } const treeHead = document.getElementById('nsys_buyback_widget'); const widget_base = document.createElement('widget-base'); widget_base.setAttribute('id', 'widget-base'); localStorage.setItem('NSYS_CLIENT_ID', treeHead.dataset['clientId']); localStorage.setItem('NSYS_BASE_URL', NSYS_BB); const shadow = treeHead.attachShadow({ mode: 'open' }); shadow.appendChild(widget_base); entryPoint();