// ==UserScript== // @name Tabview Youtube // @namespace http://tampermonkey.net/ // @version 0.4 // @description Make comments and lists into tabs // @author CY Fung // @match https://www.youtube.com/watch?v=* // @resource contentCSS https://github.com/cyfung1031/Tabview-Youtube/raw/main/css/style_content.css?v20210701b // @icon https://github.com/cyfung1031/Tabview-Youtube/raw/main/images/icon128p.png // @require https://code.jquery.com/jquery-3.6.0.slim.min.js // @grant GM_getResourceText // @run-at document-start // @license MIT https://github.com/cyfung1031/Tabview-Youtube/blob/main/LICENSE // @downloadURL none // ==/UserScript== function main($){ // MIT License // https://github.com/cyfung1031/Tabview-Youtube/raw/main/js/content.js /** * SVG resources: *
Icons made by Smashicons from www.flaticon.com
*/ const svgComments = ` ` const svgVideos = `` const svgInfo = `` const svgPlayList = ` ` const svgElm = (w, h, vw, vh, p) => `${p}` let settings = { toggleSettings: { tabs: 1, tInfo: 1, tComments: 1, tVideos: 1, }, defaultTab: "videos" }; function isVideoPlaying(video) { return video.currentTime > 0 && !video.paused && !video.ended && video.readyState > video.HAVE_CURRENT_DATA; } const Q={} function chatFrameElement(cssSelector){ let iframe = document.querySelector('iframe#chatframe'); if(!iframe) return null; let elm = null; try{ elm = iframe.contentDocument.querySelector(cssSelector) }catch(e){ console.log('iframe error', e) } return elm; } function mtf_ChatExist(){ //iframe can be not mutation triggering //collaseped might help const elmChat = document.querySelector('ytd-live-chat-frame#chat') let elmCont = null; if(elmChat){ elmCont=chatFrameElement('yt-live-chat-renderer #continuations') } const chatBlockR = (elmChat?1:0)+(elmCont?2:0) if(Q.mtf_chatBlockQ!==chatBlockR){ //console.log(897, Q.mtf_chatBlockQ, chatBlockR) Q.mtf_chatBlockQ=chatBlockR const cssElm = document.querySelector('ytd-watch-flexy') if(elmChat){ let s=0; if(elmCont){ //not found if it is collasped. s |= elmCont.querySelector('yt-timed-continuation')?1:0; s |= elmCont.querySelector('yt-live-chat-replay-continuation, yt-player-seek-continuation')?2:0; //s |= elmCont.querySelector('yt-live-chat-restricted-participation-renderer')?4:0; if(s==1) cssElm.setAttribute('userscript-chatblock', 'chat-live') if(s==2) cssElm.setAttribute('userscript-chatblock', 'chat-playback') //if(s==5) cssElm.setAttribute('userscript-chatblock', 'chat-live-paid') if(s==1){ $("span#tab3-txt-loader").text('') } } //keep unknown as original if( !cssElm.hasAttribute) cssElm.setAttribute('userscript-chatblock', '') }else{ cssElm.removeAttribute('userscript-chatblock') cssElm.removeAttribute('userscript-chat-collapsed') } } } let lastScrollAt = 0; function makeBodyScroll() { // avoid over triggering scroll event if (+new Date - lastScrollAt < 30) return; lastScrollAt = +new Date; //required for youtube content display requestAnimationFrame(()=>{ window.dispatchEvent(new Event("scroll")); }) } function scrollForComments(){ let comments = document.querySelector('ytd-comments#comments') function f(){ if( comments.hasAttribute('hidden')) makeBodyScroll(); } setTimeout(f,80) setTimeout(f,240) setTimeout(f,870) } let mtoIgnoreTo = 0 let mtoNav = null; function initObserver(){ var lastRelocate = 0 function mtf_commentRelocate() { let elm1, elm2; if (+new Date - lastRelocate > 350) { if ((elm1 = document.querySelector("ytd-watch-metadata ~ #info")) && (elm2 = document.querySelector('ytd-watch-metadata ~ #info ~ ytd-comments#comments'))) { lastRelocate = +new Date; window.requestAnimationFrame(() => { $(elm2).appendTo('#tab-comments') elm1 = null; elm2 = null; }) } } } function mtf_liveChatBtnF() { let button = document.querySelector('ytd-live-chat-frame#chat>.ytd-live-chat-frame#show-hide-button:nth-child(n+2)') if(button){ requestAnimationFrame(()=> button.parentNode.insertBefore(button, button.parentNode.firstChild) ) } } function mtf_fixInfo() { const content = document.querySelector('#meta-contents ytd-expander>#content, #tab-info ytd-expander>#content') if (content) { const expander = content.parentNode; if (expander.hasAttribute('collapsed')) expander.removeAttribute('collapsed'); let btn1 = expander.querySelector('tp-yt-paper-button#less:not([hidden])'); let btn2 = expander.querySelector('tp-yt-paper-button#more:not([hidden])'); if (btn1) btn1.setAttribute('hidden', ''); if (btn2) btn2.setAttribute('hidden', ''); } const playlist = document.querySelector('#tab-list ytd-playlist-panel-renderer#playlist') if(playlist){ if(playlist.hasAttribute('collapsed')) playlist.removeAttribute('collapsed'); if(playlist.hasAttribute('collapsible')) playlist.removeAttribute('collapsible'); } } function mtf_appendPlayList(){ let ple1 = document.querySelector("#secondary>ytd-playlist-panel-renderer#playlist, #secondary-inner>ytd-playlist-panel-renderer#playlist"); if(ple1){ let $wrapper = $('#ytd-userscript-playlist'); if(!$wrapper[0]) $wrapper=$('
') $wrapper.append(ple1).appendTo("#tab-list"); } } let mtoNav_delayedC = 0; let mtoNav_delayedF = () => { mtoNav_delayedC = 0; let addP=Q.addP; let removeP=Q.removeP; Q.addP=0;Q.removeP=0; if(!addP||!removeP) return; //console.log(999,++wwx) (async()=>{ mtf_fixInfo(); })(); (async()=>{ mtf_ChatExist(); })(); if(addP>0){ (async()=>{ mtf_commentRelocate(); })(); (async()=>{ mtf_liveChatBtnF(); })(); (async()=>{ mtf_appendPlayList(); })(); (async()=>{ if (Q.mtf_advancedComments && Q.mtf_advancedComments() === false) Q.mtf_advancedComments = null })(); (async()=>{ if (Q.mtf_checkDescriptionLoaded && Q.mtf_checkDescriptionLoaded() === false) Q.mtf_checkDescriptionLoaded = null })(); (async()=>{ if (Q.mtf_related && Q.mtf_related() === false) Q.mtf_related = null; })(); (async()=>{ if (Q.mtf_checkPlayList && Q.mtf_checkPlayList() === false) Q.mtf_checkPlayList = null; })(); (async()=>{ if (Q.mtf_checkCommentsLoaded && Q.mtf_checkCommentsLoaded() === false) Q.mtf_checkCommentsLoaded = null; })(); (async()=>{ if(Q.mtf_checkTabStatus_comments&&Q.mtf_checkTabStatus_comments()===false)Q.mtf_checkTabStatus_comments=null; })(); (async()=>{ if(Q.mtf_checkTabStatus_playlist&&Q.mtf_checkTabStatus_playlist()===false)Q.mtf_checkTabStatus_playlist=null; })(); (async()=>{ if(Q.mtf_checkStatus_chatroom&&Q.mtf_checkStatus_chatroom()===false)Q.mtf_checkStatus_chatroom=null; })(); (async()=>{ if(Q.mtf_forceCheckLiveVideo&&Q.mtf_forceCheckLiveVideo()===false)Q.mtf_forceCheckLiveVideo=null; })(); (async()=>{ if(Q.mtf_commentsScroll&&Q.mtf_commentsScroll()===false)Q.mtf_commentsScroll=null; })(); (async()=>{ if(Q.mtf_commentRendering&&Q.mtf_commentRendering()===false)Q.mtf_commentRendering=null; })(); } } Q.addP=0; Q.removeP=0; const mtoNavF=(mutations, observer) => { if (mtoIgnoreTo > +new Date) return; let ch = false; for (const mutation of mutations) { for (const addedNode of mutation.addedNodes) if (addedNode.nodeType === 1) { Q.addP++ ch = true; } for (const removedNode of mutation.removedNodes) if (removedNode.nodeType === 1) { Q.removeP++; ch = true; } } if (!ch) return; if (mtoNav_delayedC) return; mtoNav_delayedC=setTimeout(mtoNav_delayedF,30+((+new Date)%300)>>1) } mtoNav = new MutationObserver(mtoNavF); mtoNav.observe(document.querySelector('ytd-watch-flexy'), { subtree: true, childList: true }) 1;1&&(async()=>{ mtoNav_delayedF(); })(); } function resetAtNav(){ if (mtoNav) { mtoNav.takeRecords(); mtoNav.disconnect(); mtoNav = null; Q.mtf_checkDescriptionLoaded = null Q.mtf_related = null; Q.mtf_checkPlayList = null; Q.mtf_checkCommentsLoaded = null; mtoIgnoreTo = 0; Q.mtf_checkTabStatus_playlist=null; Q.mtf_checkTabStatus_comments=null; Q.mtf_checkStatus_chatroom=null; Q.mtf_chatBlockQ=null; } $("ytd-watch-flexy").removeAttr("userscript-chatblock").removeAttr("userscript-chat-collapsed") $('#tab-comments').attr('lazy-loading','') $('span#tab3-txt-loader').text('') //removed any cache of comments header if(document.querySelector('ytd-comments#comments ytd-comments-header-renderer')){ var p=document.querySelector('ytd-comments#comments ytd-comments-header-renderer'); p.parentNode.removeChild(p) } //force to [hidden] if(document.querySelector('ytd-comments#comments')){ document.querySelector('ytd-comments#comments').setAttribute('hidden','') scrollForComments(); } } function getTabsHTML(){ let ts = settings.toggleSettings; if (!ts.tabs) return; const sTabBtnVideos = `${svgElm(16,16,298,298,svgVideos)}Videos` const sTabBtnInfo = `${svgElm(16,16,23.625,23.625,svgInfo)}Info` const sTabBtnPlayList = `${svgElm(16,16,426.667,426.667,svgPlayList)}Playlist` const str1 = `
`; const str_tabs = [ ts.tInfo ? `${sTabBtnInfo}${str1}` : '', `Chat${str1}`, ts.tComments ? `${svgElm(16,16,60,60,svgComments)}${str1}` : '', ts.tVideos ? `${sTabBtnVideos}${str1}` : '', `${sTabBtnPlayList}${str1}` ].join('') var addHTML = `
${str_tabs}
`; return addHTML } function AddTabPanel() { if (window.location.href.indexOf("www.youtube.com/watch?v=") < 0) return; resetAtNav(); initObserver(); if (document.querySelector("#right-tabs")) { runAfterTabAppended(); } else { Q.mtf_related = () => { const related = document.querySelector("#related") if (!related) return true; $(getTabsHTML()).prependTo(related); runAfterTabAppended(); return false; } if (Q.mtf_related && Q.mtf_related() === false) Q.mtf_related = null; } } function setDefaultActiveTab() { const jElm = document.querySelector(`a[userscript-tab-content="${switchTabActivity_lastTab}"]:not(.hide)`) || document.querySelector(`a[userscript-tab-content="#tab-${settings.defaultTab}"]:not(.hide)`) || document.querySelector("a[userscript-tab-content]:not(.hide)") || null; switchTabActivity(jElm) } function insertBefore(elm, p) { if (elm && p && p.parentNode) p.parentNode.insertBefore(elm, p) } function addControlElement() { $('').prependTo('ytd-comments#comments') } let loadComments_cid1 = 0; function runAfterTabAppended() { setDefaultActiveTab(); let $wrapper = $('#ytd-userscript-watch-next-videos'); if(!$wrapper[0]) $wrapper=$('
') $wrapper.append($("ytd-watch-next-secondary-results-renderer")).appendTo("#tab-videos"); checkDescriptionLoaded(); tabsUiScript(); checkPlayList(); // chatToggleToTop() checkTabStatus(); checkChatStatus(); forceCheckLiveVideo(); $("#right-tabs [userscript-scrollbar-render]").scroll(makeBodyScroll); } function forceCheckLiveVideo(){ function timeCheck(){ setTimeout(function(){ const cssElm = document.querySelector('ytd-watch-flexy') if(!cssElm) return; if($('#ytd-player .ytp-time-display').is('.ytp-live')) cssElm.setAttribute('userscript-chatblock', 'chat-live') },170) } Q.mtf_forceCheckLiveVideo = () => { const playerLabel = document.querySelector('#ytd-player .ytp-time-display') && document.querySelector('ytd-live-chat-frame#chat') if (!playerLabel) return true; timeCheck(); return false; } if (Q.mtf_forceCheckLiveVideo && Q.mtf_forceCheckLiveVideo() === false) Q.mtf_forceCheckLiveVideo = null } function forceCheckLiveVideo__(){ // this is possible to detect the live video when chat area is collaseped //meta might not update... function timeCheck(){ setTimeout(()=>{ const spanMeta = document.querySelector('[itemprop="publication"][itemscope][itemtype]') if(!spanMeta)return; let meta_isLiveBroadcast = spanMeta.querySelector('meta[itemprop="isLiveBroadcast"]') meta_isLiveBroadcast=meta_isLiveBroadcast?meta_isLiveBroadcast.getAttribute('content').toLowerCase()=='true':null let meta_startDate = spanMeta.querySelector('meta[itemprop="isLiveBroadcast"]') meta_startDate=((meta_startDate?meta_startDate.getAttribute('content'):null)||"").length>0 let meta_endDate = spanMeta.querySelector('meta[itemprop="endDate"]') meta_endDate=((meta_endDate?meta_endDate.getAttribute('content'):null)||"").length>0 const cssElm = document.querySelector('ytd-watch-flexy') if(meta_isLiveBroadcast&&meta_startDate&&!meta_endDate){ cssElm.setAttribute('userscript-chatblock', 'chat-live') }else if(meta_isLiveBroadcast&&meta_startDate&&meta_endDate){ cssElm.setAttribute('userscript-chatblock', 'chat-playback') } },170) } Q.mtf_forceCheckLiveVideo = () => { const spanMeta = document.querySelector('[itemprop="publication"][itemscope][itemtype]') if (!spanMeta) return true; timeCheck(); return false; } if (Q.mtf_forceCheckLiveVideo && Q.mtf_forceCheckLiveVideo() === false) Q.mtf_forceCheckLiveVideo = null } function checkCommentsLoaded() { $('#tab-comments').attr('lazy-loading','') makeBodyScroll(); let $span = $("span#tab3-txt-loader") if (!$span[0]) return; Q.mtf_checkCommentsLoaded = () => { const commentRenderer = document.querySelector("#count.ytd-comments-header-renderer"); if (!commentRenderer) return true; let r = '0'; let txt = commentRenderer.textContent if (typeof txt == 'string') { let m = txt.match(/[\d\,\s]+/) if (m) r = m[0].trim() } $span[0].innerHTML = `${r}`; makeBodyScroll(); // force display content $('#tab-comments[lazy-loading]').removeAttr('lazy-loading') return false } if (Q.mtf_checkCommentsLoaded && Q.mtf_checkCommentsLoaded() === false) Q.mtf_checkCommentsLoaded = null; } function checkDescriptionLoaded() { Q.mtf_checkDescriptionLoaded = () => { const expander = document.querySelector("#meta-contents ytd-expander"); if (!expander) return true; $(expander).appendTo("#tab-info") return false; } if (Q.mtf_checkDescriptionLoaded && Q.mtf_checkDescriptionLoaded() === false) Q.mtf_checkDescriptionLoaded = null Q.mtf_advancedComments = () => { const continuations = document.querySelector("ytd-comments#comments #continuations"); if (!continuations) return true; scrollForComments(); return false; } if (Q.mtf_advancedComments && Q.mtf_advancedComments() === false) Q.mtf_advancedComments = null } const mtoVs={} function checkTabStatus() { if(mtoVs.mtoVisibility_Playlist) { mtoVs.mtoVisibility_Playlist.takeRecords(); mtoVs.mtoVisibility_Playlist.disconnect(); mtoVs.mtoVisibility_Playlist=null; } let mtf_attrPlaylist=(mutations, observer)=>{ var playlist=document.querySelector('ytd-playlist-panel-renderer#playlist') const $tabBtn = $('[userscript-tab-content="#tab-list"]'); //console.log('attr playlist changed') if( $tabBtn.is('.hide') && !playlist.hasAttribute('hidden') ){ //console.log('attr playlist changed - no hide') $tabBtn.removeClass("hide"); }else if( !$tabBtn.is('.hide') && playlist.hasAttribute('hidden') ){ //console.log('attr playlist changed - add hide') var isActiveBefore = $tabBtn.is('.active') $tabBtn.addClass("hide"); if (isActiveBefore) { setDefaultActiveTab(); } } } Q.mtf_checkTabStatus_playlist=()=>{ var playlist=document.querySelector('ytd-playlist-panel-renderer#playlist') if(!playlist) return true; mtoVs.mtoVisibility_Playlist=new MutationObserver(mtf_attrPlaylist) mtoVs.mtoVisibility_Playlist.observe(playlist, { attributes: true, attributeFilter: ['hidden'], attributeOldValue: true }) mtf_attrPlaylist() return false; } if(Q.mtf_checkTabStatus_playlist&&Q.mtf_checkTabStatus_playlist()===false)Q.mtf_checkTabStatus_playlist=null; if(mtoVs.mtoVisibility_Comments) { mtoVs.mtoVisibility_Comments.takeRecords(); mtoVs.mtoVisibility_Comments.disconnect(); mtoVs.mtoVisibility_Comments=null; } let mtf_attrComments=(mutations, observer)=>{ var comments=document.querySelector('ytd-comments#comments') const $tabBtn = $('[userscript-tab-content="#tab-comments"]'); if(!comments || !$tabBtn[0])return; //console.log('attr comments changed') if( $tabBtn.is('.hide') && !comments.hasAttribute('hidden') ){ //console.log('attr comments changed - no hide') $tabBtn.removeClass("hide"); window.requestAnimationFrame(checkCommentsLoaded) }else if( !$tabBtn.is('.hide') && comments.hasAttribute('hidden') ){ //console.log('attr comments changed - add hide') if(!document.querySelector('[userscript-chatblock="chat-live"]')) $('#tab-comments').attr('lazy-loading','') $('span#tab3-txt-loader').text(''); var isActiveBefore = $tabBtn.is('.active') $tabBtn.addClass("hide"); if (isActiveBefore) { setDefaultActiveTab(); } if(!document.querySelector('[userscript-chatblock="chat-live"]')) $('#tab-comments').attr('lazy-loading','') $('span#tab3-txt-loader').text(''); } } Q.mtf_checkTabStatus_comments=()=>{ var comments=document.querySelector('ytd-comments#comments') if(!comments) return true; mtoVs.mtoVisibility_Comments=new MutationObserver(mtf_attrComments) mtoVs.mtoVisibility_Comments.observe(comments, { attributes: true, attributeFilter: ['hidden'], attributeOldValue: true }) mtf_attrComments() scrollForComments() return false; } if(Q.mtf_checkTabStatus_comments&&Q.mtf_checkTabStatus_comments()===false)Q.mtf_checkTabStatus_comments=null; } function checkChatStatus(){ if(mtoVs.mtoVisibility_Chatroom) { mtoVs.mtoVisibility_Chatroom.takeRecords(); mtoVs.mtoVisibility_Chatroom.disconnect(); mtoVs.mtoVisibility_Chatroom=null; } let cid_chatFrameCheck=0; let mtf_attrChatroom=(mutations, observer)=>{ const chatBlock = document.querySelector('ytd-live-chat-frame#chat') const cssElm = document.querySelector('ytd-watch-flexy') if(!cssElm.hasAttribute('userscript-chatblock')) cssElm.setAttribute('userscript-chatblock', ''); if (chatBlock.hasAttribute('collapsed')) { cssElm.setAttribute('userscript-chat-collapsed', ''); } else { cssElm.removeAttribute('userscript-chat-collapsed'); } if(!cid_chatFrameCheck){ let dd=+new Date; cid_chatFrameCheck=setInterval(()=>{ if(+new Date - dd>2750) { return (cid_chatFrameCheck=clearInterval(cid_chatFrameCheck)); } var chatFrameChecking=!!chatFrameElement('yt-live-chat-renderer #continuations') if(chatFrameChecking) { mtf_ChatExist(); return (cid_chatFrameCheck=clearInterval(cid_chatFrameCheck)); } },30) } } Q.mtf_checkStatus_chatroom=()=>{ var chatroom=document.querySelector('ytd-live-chat-frame#chat') if(!chatroom) return true; mtoVs.mtoVisibility_Chatroom=new MutationObserver(mtf_attrChatroom) mtoVs.mtoVisibility_Chatroom.observe(chatroom, { attributes: true, attributeFilter: ['collapsed'], attributeOldValue: true }) mtf_attrChatroom() return false; } if(Q.mtf_checkStatus_chatroom&&Q.mtf_checkStatus_chatroom()===false)Q.mtf_checkStatus_chatroom=null; if(mtoVs.mtoFlexyAttr) { mtoVs.mtoFlexyAttr.takeRecords(); mtoVs.mtoFlexyAttr.disconnect(); mtoVs.mtoFlexyAttr=null; } let checkQ = null; let mtf_attrFlexy=(mutations, observer)=>{ const cssElm = document.querySelector('ytd-watch-flexy') let checkR = !cssElm.hasAttribute('userscript-chat-collapsed') && cssElm.hasAttribute('userscript-chatblock') if(checkQ!==checkR){ checkQ=checkR; window.requestAnimationFrame(()=>{ if (checkQ) { switchTabActivity(null) } else { setDefaultActiveTab(); } }) } } Q.mtf_checkFlexy=()=>{ var flexy=document.querySelector('ytd-watch-flexy') if(!flexy) return true; mtoVs.mtoFlexyAttr=new MutationObserver(mtf_attrFlexy) mtoVs.mtoFlexyAttr.observe(flexy, { attributes: true, attributeFilter: ['userscript-chat-collapsed','userscript-chatblock'], attributeOldValue: true }) mtf_attrFlexy() return false; } if(Q.mtf_checkFlexy&&Q.mtf_checkFlexy()===false)Q.mtf_checkFlexy=null; } function checkPlayList() { Q.mtf_checkPlayList = () => { const items= document.querySelector('ytd-playlist-panel-renderer>#container>#items'); if(!items) return true; $(items).scroll(makeBodyScroll); return false; } if (Q.mtf_checkPlayList && Q.mtf_checkPlayList() === false) Q.mtf_checkPlayList = null; } let switchTabActivity_lastTab = null function switchTabActivity(activeLink) { if (activeLink && activeLink.hasAttribute('hide')) return; //console.log(1219,'hello', activeLink?activeLink.getAttribute('userscript-tab-content'):null) const links = document.querySelectorAll('#material-tabs a[userscript-tab-content]'); for (const link of links) { let content = document.querySelector(link.getAttribute('userscript-tab-content')); if (link && content) { if (link !== activeLink) { $(link).removeClass("active"); $(content).addClass("hideOnRight"); } else { $(link).addClass("active"); $(content).removeClass("hideOnRight"); window.requestAnimationFrame(() => content.focus()) } } } } let tabsUiScript_setclick = false; function tabsUiScript() { const materialTab = document.querySelector("#material-tabs") if (!materialTab) return; let noActiveTab = !!document.querySelector('ytd-watch-flexy[userscript-chatblock]:not([userscript-chat-collapsed])') const activeLink = materialTab.querySelector('a[userscript-tab-content].active:not(.hide)') if (activeLink) switchTabActivity(noActiveTab ? null : activeLink) if (!tabsUiScript_setclick) { tabsUiScript_setclick = true; $(materialTab).on("click", "a", function(evt) { if (!this.hasAttribute('userscript-tab-content')) return; switchTabActivity_lastTab = this.getAttribute('userscript-tab-content'); window.requestAnimationFrame(() => { Promise.resolve().then(() => { let button = document.querySelector('ytd-live-chat-frame#chat:not([collapsed])>.ytd-live-chat-frame#show-hide-button') return button }).then(button => { mtoIgnoreTo = +new Date + 300; if (button) { button.querySelector('ytd-toggle-button-renderer').click(); } }).then(() => { setTimeout(() => { switchTabActivity(this) setTimeout(() => { makeBodyScroll(); },20); }, 100); mtoIgnoreTo = 0; }) }) evt.preventDefault(); }); } } // --------------------------------------------------------------------------------------------- window.addEventListener("yt-navigate-finish", AddTabPanel) // https://github.com/cyfung1031/Tabview-Youtube/raw/main/js/content.js } ;!(function $$() { 'use strict'; if(document.documentElement==null) return window.requestAnimationFrame($$) var cssTxt = GM_getResourceText("contentCSS"); function addStyle (styleText) { const styleNode = document.createElement('style'); styleNode.type = 'text/css'; styleNode.textContent = styleText; document.documentElement.appendChild(styleNode); return styleNode; } addStyle (cssTxt); main(window.$); // Your code here... })();