aveAltSheets = false; var altStyleSelected = false; for (let currentStyleSheet of styleSheets) { if (!currentStyleSheet.disabled) { altStyleSelected = true; } haveAltSheets = true; let lastWithSameTitle = null; if (currentStyleSheet.title in currentStyleSheets) { lastWithSameTitle = currentStyleSheets[currentStyleSheet.title]; } if (!lastWithSameTitle) { let menuItem = document.createXULElement("menuitem"); menuItem.setAttribute("type", "radio"); menuItem.setAttribute("label", currentStyleSheet.title); menuItem.setAttribute("data", currentStyleSheet.title); menuItem.setAttribute( "checked", !currentStyleSheet.disabled && !styleDisabled ); menuItem.addEventListener("command", event => this.switchStyleSheet(event.currentTarget.getAttribute("data")) ); menuPopup.appendChild(menuItem); currentStyleSheets[currentStyleSheet.title] = menuItem; } else if (currentStyleSheet.disabled) { lastWithSameTitle.removeAttribute("checked"); } } noStyle.setAttribute("checked", styleDisabled); persistentOnly.setAttribute("checked", !altStyleSelected && !styleDisabled); persistentOnly.hidden = styleSheetInfo.preferredStyleSheetSet ? haveAltSheets : false; sep.hidden = (noStyle.hidden && persistentOnly.hidden) || !haveAltSheets; }, /** * Send a message to all PageStyleParents by walking the BrowsingContext tree. * * @param message * The string message to send to each PageStyleChild. * @param data * The data to send to each PageStyleChild within the message. */ _sendMessageToAll(message, data) { let contextsToVisit = [gBrowser.selectedBrowser.browsingContext]; while (contextsToVisit.length) { let currentContext = contextsToVisit.pop(); let global = currentContext.currentWindowGlobal; if (!global) { continue; } let actor = global.getActor("PageStyle"); actor.sendAsyncMessage(message, data); contextsToVisit.push(...currentContext.children); } }, /** * Switch the stylesheet of all documents in the current browser. * * @param title The title of the stylesheet to switch to. */ switchStyleSheet(title) { let sheetData = this._getStyleSheetInfo(gBrowser.selectedBrowser); for (let sheet of sheetData.filteredStyleSheets) { sheet.disabled = sheet.title !== title; } this._sendMessageToAll("PageStyle:Switch", { title }); }, /** * Disable all stylesheets. Called with View > Page Style > No Style. */ disableStyle() { this._sendMessageToAll("PageStyle:Disable", {}); }, }; PK