Ver Fonte

use 2nd parameter of Array.from

Former-commit-id: 6c180cb221f1fd90d761bab0c645859ae3224a17
Gildas há 6 anos atrás
pai
commit
87fa8e45ea

+ 2 - 2
extension/ui/bg/ui-options.js

@@ -447,7 +447,7 @@
 	async function refresh(profileName) {
 		const [profiles, rules] = await Promise.all([browser.runtime.sendMessage({ method: "config.getProfiles" }), browser.runtime.sendMessage({ method: "config.getRules" })]);
 		const selectedProfileName = profileName || profileNamesInput.value || DEFAULT_PROFILE_NAME;
-		Array.from(profileNamesInput.childNodes).forEach(node => node.remove());
+		Array.from(profileNamesInput.childNodes, node => node.remove());
 		profileNamesInput.options.length = 0;
 		ruleProfileInput.options.length = 0;
 		ruleAutoSaveProfileInput.options.length = 0;
@@ -477,7 +477,7 @@
 		ruleAutoSaveProfileInput.appendChild(optionElement);
 		ruleEditAutoSaveProfileInput.appendChild(optionElement.cloneNode(true));
 		const rulesDataElement = rulesElement.querySelector(".rules-data");
-		Array.from(rulesDataElement.childNodes).forEach(node => (!node.className || !node.className.includes("rule-edit")) && node.remove());
+		Array.from(rulesDataElement.childNodes, node => (!node.className || !node.className.includes("rule-edit")) && node.remove());
 		const editURLElement = rulesElement.querySelector(".rule-edit");
 		createURLElement.hidden = false;
 		editURLElement.hidden = true;

+ 1 - 1
extension/ui/content/content-ui-infobar.js

@@ -201,7 +201,7 @@ this.singlefile.extension.ui.content.infobar = this.singlefile.extension.ui.cont
 	function createElement(tagName, parentElement) {
 		const element = document.createElement(tagName);
 		parentElement.appendChild(element);
-		Array.from(getComputedStyle(element)).forEach(property => element.style.setProperty(property, "initial", "important"));
+		Array.from(getComputedStyle(element), property => element.style.setProperty(property, "initial", "important"));
 		return element;
 	}
 

+ 1 - 1
extension/ui/content/content-ui-main.js

@@ -45,7 +45,7 @@ this.singlefile.extension.ui.content.main = this.singlefile.extension.ui.content
 
 	let logsWindowElement = createLogsWindowElement();
 	const allProperties = new Set();
-	Array.from(getComputedStyle(document.body)).forEach(property => allProperties.add(property));
+	Array.from(getComputedStyle(document.body), property => allProperties.add(property));
 
 	return {
 		markSelection,

+ 2 - 2
lib/hooks/content/content-hooks-frames-web.js

@@ -169,7 +169,7 @@
 	addEventListener(LOAD_DEFERRED_IMAGES_START_EVENT, () => {
 		loadDeferredImages = true;
 		const docBoundingRect = document.documentElement.getBoundingClientRect();
-		Array.from(observers).forEach(([intersectionObserver, observer]) => {
+		Array.from(observers, ([intersectionObserver, observer]) => {
 			const rootBoundingRect = observer.options.root && observer.options.root.getBoundingClientRect();
 			observer.callback(observedElements.get(intersectionObserver).map(target => {
 				const boundingClientRect = target.getBoundingClientRect();
@@ -181,7 +181,7 @@
 			}), intersectionObserver);
 		});
 		if (pendingRequestAnimationFrameCalls.size) {
-			Array.from(pendingRequestAnimationFrameCalls).forEach(([id, callback]) => {
+			Array.from(pendingRequestAnimationFrameCalls, ([id, callback]) => {
 				cancelAnimationFrame(id);
 				callback();
 			});

+ 2 - 2
lib/single-file/modules/html-minifier.js

@@ -151,7 +151,7 @@ this.singlefile.lib.modules.htmlMinifier = this.singlefile.lib.modules.htmlMinif
 
 	function collapseBooleanAttributes(node) {
 		if (node.nodeType == Node_ELEMENT_NODE) {
-			Array.from(node.attributes).forEach(attribute => {
+			Array.from(node.attributes, attribute => {
 				if (booleanAttributes.includes(attribute.name)) {
 					node.setAttribute(attribute.name, "");
 				}
@@ -218,7 +218,7 @@ this.singlefile.lib.modules.htmlMinifier = this.singlefile.lib.modules.htmlMinif
 
 	function removeEmptyAttributes(node) {
 		if (node.nodeType == Node_ELEMENT_NODE) {
-			Array.from(node.attributes).forEach(attribute => {
+			Array.from(node.attributes, attribute => {
 				if (safeToRemoveAttrs.includes(attribute.name.toLowerCase())) {
 					const attributeValue = node.getAttribute(attribute.name);
 					if (attributeValue == "" || (attributeValue || "").match(REGEXP_ENDS_WHITESPACE)) {

+ 3 - 3
lib/single-file/modules/html-serializer.js

@@ -113,10 +113,10 @@ this.singlefile.lib.modules.serializer = this.singlefile.lib.modules.serializer
 		let content = "";
 		if (!omittedStartTag || element.attributes.length) {
 			content = "<" + tagName;
-			Array.from(element.attributes).forEach(attribute => content += serializeAttribute(attribute, element));
+			Array.from(element.attributes, attribute => content += serializeAttribute(attribute, element));
 			content += ">";
 		}
-		Array.from(element.childNodes).forEach(childNode => content += serialize(childNode));
+		Array.from(element.childNodes, childNode => content += serialize(childNode));
 		const omittedEndTag = OMITTED_END_TAGS.find(omittedEndTag => tagName == omittedEndTag.tagName && omittedEndTag.accept(element.nextSibling, element));
 		if (!omittedEndTag && !SELF_CLOSED_TAG_NAMES.includes(tagName)) {
 			content += "</" + tagName + ">";
@@ -130,7 +130,7 @@ this.singlefile.lib.modules.serializer = this.singlefile.lib.modules.serializer
 		if (!name.match(/["'>/=]/)) {
 			let value = attribute.value;
 			if (name == "class") {
-				value = Array.from(element.classList).map(className => className.trim()).join(" ");
+				value = Array.from(element.classList, className => className.trim()).join(" ");
 			}
 			let simpleQuotesValue;
 			value = value.replace(/&/g, "&amp;").replace(/\u00a0/g, "&nbsp;");

+ 8 - 8
lib/single-file/single-file-core.js

@@ -525,7 +525,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 
 			function removeUnmarkedElements(element) {
 				let selectedElementFound = false;
-				Array.from(element.childNodes).forEach(node => {
+				Array.from(element.childNodes, node => {
 					if (node.nodeType == 1) {
 						const isSelectedElement = node.getAttribute(SELECTED_CONTENT_ATTRIBUTE_NAME) == "";
 						selectedElementFound = selectedElementFound || isSelectedElement;
@@ -537,7 +537,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 						} else {
 							if (canHideNode(node)) {
 								node.style.setProperty("display", "none", "important");
-								Array.from(node.childNodes).forEach(removeNode);
+								Array.from(node.childNodes, removeNode);
 							}
 						}
 					}
@@ -1009,13 +1009,13 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 		}
 
 		async processStylesheets() {
-			await Promise.all(Array.from(this.stylesheets).map(([, stylesheetInfo]) =>
+			await Promise.all(Array.from(this.stylesheets, ([, stylesheetInfo]) =>
 				ProcessorHelper.processStylesheet(stylesheetInfo.stylesheet.children, this.baseURI, this.options, this.cssVariables, this.batchRequest)
 			));
 		}
 
 		async processStyleAttributes() {
-			return Promise.all(Array.from(this.styles).map(([, declarationList]) =>
+			return Promise.all(Array.from(this.styles, ([, declarationList]) =>
 				ProcessorHelper.processStyle(declarationList.children.toArray(), this.baseURI, this.options, this.cssVariables, this.batchRequest)
 			));
 		}
@@ -1048,7 +1048,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 		}
 
 		async processScripts() {
-			await Promise.all(Array.from(this.doc.querySelectorAll("script[src]")).map(async scriptElement => {
+			await Promise.all(Array.from(this.doc.querySelectorAll("script[src]"), async scriptElement => {
 				let resourceURL;
 				const scriptSrc = scriptElement.getAttribute("src");
 				scriptElement.removeAttribute("src");
@@ -1556,7 +1556,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 		}
 
 		static async processAttribute(resourceElements, attributeName, baseURI, options, cssVariables, styles, batchRequest, processDuplicates, removeElementIfMissing) {
-			await Promise.all(Array.from(resourceElements).map(async resourceElement => {
+			await Promise.all(Array.from(resourceElements, async resourceElement => {
 				let resourceURL = resourceElement.getAttribute(attributeName);
 				resourceURL = Util.normalizeURL(resourceURL);
 				if (!Util.testIgnoredPath(resourceURL)) {
@@ -1596,7 +1596,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 
 		static async processXLinks(resourceElements, baseURI, options, batchRequest) {
 			const attributeName = "xlink:href";
-			await Promise.all(Array.from(resourceElements).map(async resourceElement => {
+			await Promise.all(Array.from(resourceElements, async resourceElement => {
 				const originalResourceURL = resourceElement.getAttribute(attributeName);
 				let resourceURL = Util.normalizeURL(originalResourceURL);
 				if (Util.testValidPath(resourceURL) && !Util.testIgnoredPath(resourceURL)) {
@@ -1631,7 +1631,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 		}
 
 		static async processSrcset(resourceElements, attributeName, baseURI, batchRequest) {
-			await Promise.all(Array.from(resourceElements).map(async resourceElement => {
+			await Promise.all(Array.from(resourceElements, async resourceElement => {
 				const srcset = util.parseSrcset(resourceElement.getAttribute(attributeName));
 				const srcsetValues = await Promise.all(srcset.map(async srcsetValue => {
 					let resourceURL = Util.normalizeURL(srcsetValue.url);

+ 4 - 4
lib/single-file/single-file-helper.js

@@ -74,7 +74,7 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 		doc.querySelectorAll("script").forEach(element => element.textContent = element.textContent.replace(/<\/script>/gi, "<\\/script>"));
 		doc.querySelectorAll("noscript").forEach(element => {
 			const disabledNoscriptElement = doc.createElement("disabled-noscript");
-			Array.from(element.childNodes).forEach(node => disabledNoscriptElement.appendChild(node));
+			Array.from(element.childNodes, node => disabledNoscriptElement.appendChild(node));
 			disabledNoscriptElement.hidden = true;
 			element.parentElement.replaceChild(disabledNoscriptElement, element);
 		});
@@ -154,7 +154,7 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 				shadowRootInfo.delegatesFocus = element.shadowRoot.delegatesFocus;
 				shadowRootInfo.mode = element.shadowRoot.mode;
 				if (element.shadowRoot.adoptedStyleSheets && element.shadowRoot.adoptedStyleSheets.length) {
-					shadowRootInfo.adoptedStyleSheets = Array.from(element.shadowRoot.adoptedStyleSheets).map(stylesheet => Array.from(stylesheet.cssRules).map(cssRule => cssRule.cssText).join("\n"));
+					shadowRootInfo.adoptedStyleSheets = Array.from(element.shadowRoot.adoptedStyleSheets, stylesheet => Array.from(stylesheet.cssRules, cssRule => cssRule.cssText).join("\n"));
 				}
 			}
 			getElementsInfo(win, doc, element, options, data, elementHidden);
@@ -288,7 +288,7 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 	function postProcessDoc(doc, markedElements) {
 		doc.querySelectorAll("disabled-noscript").forEach(element => {
 			const noscriptElement = doc.createElement("noscript");
-			Array.from(element.childNodes).forEach(node => noscriptElement.appendChild(node));
+			Array.from(element.childNodes, node => noscriptElement.appendChild(node));
 			element.parentElement.replaceChild(noscriptElement, element);
 		});
 		doc.querySelectorAll("meta[disabled-http-equiv]").forEach(element => {
@@ -326,7 +326,7 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 					tempStyleElement.remove();
 					if (!stylesheet || stylesheet.cssRules.length != styleElement.sheet.cssRules.length) {
 						styleElement.setAttribute(STYLESHEET_ATTRIBUTE_NAME, styleIndex);
-						contents[styleIndex] = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
+						contents[styleIndex] = Array.from(styleElement.sheet.cssRules, cssRule => cssRule.cssText).join("\n");
 					}
 				} catch (error) {
 					// ignored