From b695eea70cec964d0adc49daa6b60d473a6cbf33 Mon Sep 17 00:00:00 2001 From: Najam Ul Saqib Date: Thu, 2 Jan 2025 21:54:00 +0500 Subject: [PATCH] Revert "fix lint errors" This reverts commit 422853def1d60d71c4beee2ccf03fe679f84fd17. Signed-off-by: Najam Ul Saqib --- src/main/zapHomeFiles/hud/utils.js | 78 ++++++++++++++++-------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/src/main/zapHomeFiles/hud/utils.js b/src/main/zapHomeFiles/hud/utils.js index e6ccbfd3..3a01cc5d 100644 --- a/src/main/zapHomeFiles/hud/utils.js +++ b/src/main/zapHomeFiles/hud/utils.js @@ -43,27 +43,27 @@ const utils = (function () { function parseRequestHeader(headerText) { const header = {}; - header.method = headerText.slice(0, Math.max(0, headerText.indexOf(' '))); - headerText = headerText.slice(Math.max(0, headerText.indexOf(' ') + 1)); + header.method = headerText.substring(0, headerText.indexOf(' ')); + headerText = headerText.substring(headerText.indexOf(' ') + 1); - header.uri = headerText.slice(0, Math.max(0, headerText.indexOf(' '))); - headerText = headerText.slice(Math.max(0, headerText.indexOf(' ') + 1)); + header.uri = headerText.substring(0, headerText.indexOf(' ')); + headerText = headerText.substring(headerText.indexOf(' ') + 1); - header.version = headerText.slice(0, Math.max(0, headerText.indexOf('\r'))); - headerText = headerText.slice(Math.max(0, headerText.indexOf('\n') + 1)); + header.version = headerText.substring(0, headerText.indexOf('\r')); + headerText = headerText.substring(headerText.indexOf('\n') + 1); header.fields = {}; while (headerText !== '') { - const field = headerText.slice(0, Math.max(0, headerText.indexOf(':'))); - headerText = headerText.slice(Math.max(0, headerText.indexOf(':') + 2)); + const field = headerText.substring(0, headerText.indexOf(':')); + headerText = headerText.substring(headerText.indexOf(':') + 2); let value; - if (!headerText.includes('\n')) { + if (headerText.indexOf('\n') < 0) { value = headerText; headerText = ''; } else { - value = headerText.slice(0, Math.max(0, headerText.indexOf('\n'))); - headerText = headerText.slice(Math.max(0, headerText.indexOf('\n') + 1)); + value = headerText.substring(0, headerText.indexOf('\n')); + headerText = headerText.substring(headerText.indexOf('\n') + 1); } header.fields[field] = value; @@ -78,22 +78,22 @@ const utils = (function () { function parseResponseHeader(headerText) { const header = {}; - header.version = headerText.slice(0, Math.max(0, headerText.indexOf(' '))); - headerText = headerText.slice(Math.max(0, headerText.indexOf(' ') + 1)); + header.version = headerText.substring(0, headerText.indexOf(' ')); + headerText = headerText.substring(headerText.indexOf(' ') + 1); - header.status = headerText.slice(0, Math.max(0, headerText.indexOf(' '))); - headerText = headerText.slice(Math.max(0, headerText.indexOf(' ') + 1)); + header.status = headerText.substring(0, headerText.indexOf(' ')); + headerText = headerText.substring(headerText.indexOf(' ') + 1); - header.reason = headerText.slice(0, Math.max(0, headerText.indexOf(' '))); - headerText = headerText.slice(Math.max(0, headerText.indexOf(' ') + 1)); + header.reason = headerText.substring(0, headerText.indexOf(' ')); + headerText = headerText.substring(headerText.indexOf(' ') + 1); header.fields = {}; while (headerText !== '') { - const field = headerText.slice(0, Math.max(0, headerText.indexOf(':'))); - headerText = headerText.slice(Math.max(0, headerText.indexOf(':') + 2)); + const field = headerText.substring(0, headerText.indexOf(':')); + headerText = headerText.substring(headerText.indexOf(':') + 2); - const value = headerText.slice(0, Math.max(0, headerText.indexOf('\n'))); - headerText = headerText.slice(Math.max(0, headerText.indexOf('\n') + 1)); + const value = headerText.substring(0, headerText.indexOf('\n')); + headerText = headerText.substring(headerText.indexOf('\n') + 1); header.fields[field] = value; } @@ -121,11 +121,11 @@ const utils = (function () { hostname = hostname.split('?')[0]; hostname = hostname.split('#')[0]; - // Remove port if present - hostname = hostname.split(':')[0]; + // Remove port if present + hostname = hostname.split(':')[0]; // Split the hostname into parts - const parts = hostname.split('.'); + const parts = hostname.split('.'); // If the hostname has more than two parts, return the last two parts as the domain if (parts.length > 2) { @@ -136,7 +136,7 @@ const utils = (function () { } function hasScheme(url) { - return url.includes('://'); + return url.indexOf('://') > -1; } /* @@ -163,7 +163,7 @@ const utils = (function () { * Initialize all of the info that will be stored in indexeddb. */ function initializeHUD(leftTools, rightTools, drawer) { - if (IS_DEV_MODE && !leftTools.includes('hudErrors')) { + if (IS_DEV_MODE && leftTools.indexOf('hudErrors') < 0) { // Always add the error tool in dev mode leftTools.push('hudErrors'); } @@ -206,8 +206,8 @@ const utils = (function () { function setDefaultTools(leftTools, rightTools) { const promises = []; - for (const [i, leftTool] of leftTools.entries()) { - loadTool(leftTool) + for (let i = 0; i < leftTools.length; i++) { + loadTool(leftTools[i]) .then(tool => { if (!tool) { log(LOG_ERROR, 'utils.setDefaultTools', 'Failed to load tool.', tool.name); @@ -223,8 +223,8 @@ const utils = (function () { .catch(errorHandler); } - for (const [i, rightTool] of rightTools.entries()) { - loadTool(rightTool) + for (let i = 0; i < rightTools.length; i++) { + loadTool(rightTools[i]) .then(tool => { if (!tool) { log(LOG_ERROR, 'utils.setDefaultTools', 'Failed to load tool.', tool.name); @@ -441,7 +441,8 @@ const utils = (function () { function messageFrame(tabId, frameId, message) { return clients.matchAll({includeUncontrolled: true}) .then(clients => { - for (const client of clients) { + for (let i = 0; i < clients.length; i++) { + const client = clients[i]; const parameters = new URL(client.url).searchParams; const tid = parameters.get('tabId'); @@ -479,7 +480,8 @@ const utils = (function () { .then(clients => { const frameClients = []; - for (const client of clients) { + for (let i = 0; i < clients.length; i++) { + const client = clients[i]; const parameters = new URL(client.url).searchParams; const fid = parameters.get('frameId'); @@ -498,7 +500,9 @@ const utils = (function () { }) .then(clients => { return new Promise(((resolve, reject) => { - for (const client of clients) { + for (let i = 0; i < clients.length; i++) { + const client = clients[i]; + const channel = new MessageChannel(); channel.port1.start(); channel.port2.start(); @@ -531,7 +535,8 @@ const utils = (function () { .then(clients => { const frameClients = []; - for (const client of clients) { + for (let i = 0; i < clients.length; i++) { + const client = clients[i]; const parameters = new URL(client.url).searchParams; const fid = parameters.get('frameId'); @@ -661,7 +666,7 @@ const utils = (function () { scheme = 'http'; } - return scheme + '://' + domain + url.slice(Math.max(0, url.indexOf(domain) + domain.length)); + return scheme + '://' + domain + url.substring(url.indexOf(domain) + domain.length); }) .catch(errorHandler); } @@ -676,7 +681,7 @@ const utils = (function () { // Construct the stack trace const lines = error.stack.split('\n').slice(0, -1); lines.forEach(line => { - const functionName = line.slice(0, Math.max(0, line.indexOf('/'))); + const functionName = line.substring(0, line.indexOf('/')); const urlAndLineNo = line.substring(line.indexOf('http'), line.length - 1); const parts = urlAndLineNo.split(':'); let url = parts[0] + ':' + parts[1]; @@ -777,7 +782,6 @@ const utils = (function () { timestampToTimeString }; } - return { parseRequestHeader, parseResponseHeader,