From 1b2574a686ae6d94833387ff33b4115ab0ce5ea7 Mon Sep 17 00:00:00 2001 From: davtur19 Date: Sat, 3 Oct 2020 03:21:43 +0200 Subject: [PATCH] Add max_failed_in_a_row and bugfix --- dotgit.js | 25 ++++++++++++++++++++++--- manifest.json | 2 +- options/options.html | 6 +++++- options/options.js | 3 ++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/dotgit.js b/dotgit.js index 7f9eb2e..920cad3 100644 --- a/dotgit.js +++ b/dotgit.js @@ -13,7 +13,8 @@ const DEFAULT_OPTIONS = { "download": { "wait": 100, "max_wait": 10000, - "max_connections": 20 + "max_connections": 20, + "failed_in_a_row": 250 } }; @@ -78,6 +79,7 @@ let notification_download; let check_git; let check_svn; let check_hg; +let failed_in_a_row; function notification(title, message) { @@ -208,7 +210,7 @@ function startDownload(baseUrl, downloadFinished) { let waiting = 0; let fileExist = false; let downloadStats = {}; - + let failedInARow = 0; let downloadStatus = { successful: 0, failed: 0, @@ -255,6 +257,11 @@ function startDownload(baseUrl, downloadFinished) { function downloadFile(path, decompress, callback) { if (walkedPaths.includes(path)) { + downloadZip(); + return; + } + if (failedInARow > failed_in_a_row) { + downloadZip(); return; } @@ -282,10 +289,13 @@ function startDownload(baseUrl, downloadFinished) { if (response.ok && response.status === 200) { fileExist = true; downloadStatus.successful++; + failedInARow = 0; + sendDownloadStatus(baseUrl, downloadStatus); return response.arrayBuffer(); } running_tasks--; downloadStatus.failed++; + failedInARow++; sendDownloadStatus(baseUrl, downloadStatus); }).then(function (buffer) { if (typeof buffer !== "undefined") { @@ -389,6 +399,7 @@ function set_options(options) { wait = options.download.wait; max_wait = options.download.max_wait; max_connections = options.download.max_connections; + failed_in_a_row = options.download.failed_in_a_row; notification_new_git = options.notification.new_git; notification_download = options.notification.download; check_git = options.functions.git; @@ -463,6 +474,9 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { } else if (request.type === "max_wait") { max_wait = request.value; sendResponse({status: true}); + } else if (request.type === "failed_in_a_row") { + failed_in_a_row = request.value; + sendResponse({status: true}); } else if (request.type === "reset_options") { chrome.storage.local.set({options: DEFAULT_OPTIONS}); set_options(DEFAULT_OPTIONS); @@ -488,7 +502,7 @@ chrome.storage.local.get(["checked", "withExposedGit", "options"], function (res chrome.storage.local.set({options: DEFAULT_OPTIONS}); } // upgrade 3.7.4 => 4.0 - if (typeof result.options.functions === "undefined" || typeof result.withExposedGit[0].type === "undefined") { + if (typeof result.options.functions === "undefined" || (typeof result.withExposedGit[0] !== "undefined" && typeof result.withExposedGit[0].type === "undefined")) { let urls = []; result.options.functions = DEFAULT_OPTIONS.functions; result.withExposedGit.forEach(function (url) { @@ -497,6 +511,11 @@ chrome.storage.local.get(["checked", "withExposedGit", "options"], function (res result.withExposedGit = urls; chrome.storage.local.set({withExposedGit: result.withExposedGit}); } + // upgrade 4.0 => 4.1 + if (typeof result.options.download.failed_in_a_row === "undefined") { + result.options.download.failed_in_a_row = DEFAULT_OPTIONS.download.failed_in_a_row; + chrome.storage.local.set({withExposedGit: result.withExposedGit}); + } chrome.storage.local.set({options: checkOptions(DEFAULT_OPTIONS, result.options)}); diff --git a/manifest.json b/manifest.json index 8ad32ee..dc85b51 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "DotGit", - "version": "4.0.2", + "version": "4.1", "description": "An extension for checking if .git is exposed in visited websites", "icons": { "16": "icons/dotgit-16.png", diff --git a/options/options.html b/options/options.html index 5190e86..8ad7e73 100644 --- a/options/options.html +++ b/options/options.html @@ -88,9 +88,13 @@
Download
- By changing these values the browser may become unstable!
+
+
+ +
+ By changing the values below, the browser may become unstable!
Change them only if you know what you are doing

diff --git a/options/options.js b/options/options.js index a28d186..f456585 100644 --- a/options/options.js +++ b/options/options.js @@ -13,6 +13,7 @@ function set_gui(options) { document.getElementById("hgOff").checked = !options.functions.hg; document.getElementById("max_sites").value = options.max_sites; document.getElementById("max_connections").value = options.download.max_connections; + document.getElementById("failed_in_a_row").value = options.download.failed_in_a_row; document.getElementById("wait").value = options.download.wait; document.getElementById("max_wait").value = options.download.max_wait; document.getElementById("on1").checked = options.notification.new_git; @@ -72,7 +73,7 @@ document.addEventListener("DOMContentLoaded", function () { value: result.options.notification.download }, function (response) { }); - } else if (e.target.validity.valid === true && (e.target.id === "max_connections" || e.target.id === "wait" || e.target.id === "max_wait")) { + } else if (e.target.validity.valid === true && (e.target.id === "max_connections" || e.target.id === "wait" || e.target.id === "max_wait" || e.target.id === "failed_in_a_row")) { result.options.download[e.target.id] = e.target.value; chrome.storage.local.set(result); chrome.runtime.sendMessage({