let gettingItem = browser.storage.sync.get({commentsRemove: false}); // Retrieves the storage variable to determine whether comments should be removed function setComments(remove) { if (!remove) return; var commentStyle = document.createElement('style'); document.head.appendChild(commentStyle); commentStyle.sheet.insertRule("ytd-comments {visibility: hidden !important}"); } function onGot(result) { var remove = result.commentsRemove; setComments(remove); // Sets the visibility of the comments section depending on the storage vairable } function onFailure(error) { alert(`Error: ${error}`); } gettingItem.then(onGot, onFailure);