Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: issue-reporter.js

Issue 29587596: Noissue - Address eslint warnings in the issue reporter (Closed) Base URL: https://hg.adblockplus.org/adblockplusui
Patch Set: Changed indentation Created Oct. 24, 2017, 12:17 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: issue-reporter.js
===================================================================
--- a/issue-reporter.js
+++ b/issue-reporter.js
@@ -14,22 +14,23 @@
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
window.ext = {};
-let reportData = new DOMParser().parseFromString("<report></report>", "text/xml");
+let reportData = new DOMParser().parseFromString("<report></report>",
+ "text/xml");
let pages = {
- "typeSelectorPage": [initTypeSelector, leaveTypeSelector],
- "commentPage": [initCommentPage, leaveCommentPage],
- "sendPage": [initSendPage, leaveSendPage]
+ typeSelectorPage: [initTypeSelector, leaveTypeSelector],
+ commentPage: [initCommentPage, leaveCommentPage],
+ sendPage: [initSendPage, leaveSendPage]
};
document.addEventListener("DOMContentLoaded", () =>
{
document.getElementById("cancel").addEventListener("click", () =>
{
window.close();
});
@@ -37,19 +38,19 @@ document.addEventListener("DOMContentLoa
document.getElementById("continue").addEventListener("click", () =>
{
if (!document.getElementById("continue").disabled)
pages[getCurrentPage()][1]();
});
document.addEventListener("keydown", event =>
{
- let blacklistedElements = new Set(["textarea", "button", "a"])
+ let blacklisted = new Set(["textarea", "button", "a"]);
- if (event.key == "Enter" && !blacklistedElements.has(event.target.localName))
+ if (event.key == "Enter" && !blacklisted.has(event.target.localName))
document.getElementById("continue").click();
else if (event.key == "Escape")
document.getElementById("cancel").click();
});
browser.runtime.sendMessage({
type: "app.get",
what: "doclink",
@@ -77,30 +78,30 @@ function setCurrentPage(pageId)
previousPage.hidden = true;
document.getElementById(pageId).hidden = false;
pages[pageId][0]();
}
function censorURL(url)
{
- return url.replace(/([?;&\/#][^?;&\/#]+?=)[^?;&\/#]+/g, "$1*");
+ return url.replace(/([?;&/#][^?;&/#]+?=)[^?;&/#]+/g, "$1*");
}
function encodeHTML(str)
{
return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
}
function serializeReportData()
{
let result = new XMLSerializer().serializeToString(reportData);
// Insert line breaks before each new tag
- result = result.replace(/(<[^\/]([^"<>]*|"[^"]*")*>)/g, "\n$1");
+ result = result.replace(/(<[^/]([^"<>]*|"[^"]*")*>)/g, "\n$1");
result = result.replace(/^\n+/, "");
return result;
}
function retrieveAddonInfo()
{
let element = reportData.createElement("adblock-plus");
return browser.runtime.sendMessage({
@@ -185,18 +186,22 @@ function retrieveSubscriptions()
{
if (!/^(http|https|ftp):/.test(subscription.url))
continue;
let now = Math.round(Date.now() / 1000);
let subscriptionElement = reportData.createElement("subscription");
subscriptionElement.setAttribute("id", subscription.url);
if (subscription.lastDownload)
- subscriptionElement.setAttribute("lastDownloadAttempt", subscription.lastDownload - now);
- subscriptionElement.setAttribute("downloadStatus", subscription.downloadStatus);
+ {
+ subscriptionElement.setAttribute("lastDownloadAttempt",
+ subscription.lastDownload - now);
+ }
+ subscriptionElement.setAttribute("downloadStatus",
+ subscription.downloadStatus);
element.appendChild(subscriptionElement);
}
reportData.documentElement.appendChild(element);
});
}
function initDataCollector()
{
@@ -243,25 +248,27 @@ function leaveTypeSelector()
let checkbox = document.querySelector("input[name='type']:checked");
reportData.documentElement.setAttribute("type", checkbox.value);
setCurrentPage("commentPage");
}
function initCommentPage()
{
let continueButton = document.getElementById("continue");
+ let label = browser.i18n.getMessage("issueReporter_sendButton_label");
+ continueButton.textContent = label;
continueButton.disabled = true;
- continueButton.textContent = browser.i18n.getMessage("issueReporter_sendButton_label");
let emailElement = reportData.createElement("email");
let emailField = document.getElementById("email");
let anonymousSubmissionField = document.getElementById("anonymousSubmission");
let validateEmail = () =>
{
- document.getElementById("anonymousSubmissionWarning").setAttribute("data-invisible", !anonymousSubmissionField.checked);
+ document.getElementById("anonymousSubmissionWarning")
+ .setAttribute("data-invisible", !anonymousSubmissionField.checked);
if (anonymousSubmissionField.checked)
{
emailField.value = "";
emailField.disabled = true;
continueButton.disabled = false;
if (emailElement.parentNode)
emailElement.parentNode.removeChild(emailElement);
}
@@ -283,76 +290,82 @@ function initCommentPage()
{
if (commentElement.parentNode)
commentElement.parentNode.removeChild(commentElement);
let value = event.target.value.trim();
commentElement.textContent = value.substr(0, 1000);
if (value)
reportData.documentElement.appendChild(commentElement);
- document.getElementById("commentLengthWarning").setAttribute("data-invisible", value.length <= 1000);
+ document.getElementById("commentLengthWarning")
+ .setAttribute("data-invisible", value.length <= 1000);
});
document.getElementById("showData").addEventListener("click", event =>
{
event.preventDefault();
// window.open() won't open data: URIs in Chrome
browser.tabs.getCurrent().then(tab =>
{
browser.tabs.create({
- url: "data:text/xml;charset=utf-8," + encodeURIComponent(serializeReportData()),
+ url: "data:text/xml;charset=utf-8," +
+ encodeURIComponent(serializeReportData()),
openerTabId: tab.id
});
- })
+ });
});
emailField.focus();
}
function leaveCommentPage()
{
setCurrentPage("sendPage");
}
function initSendPage()
{
document.getElementById("cancel").hidden = true;
let continueButton = document.getElementById("continue");
- continueButton.textContent = browser.i18n.getMessage("issueReporter_doneButton_label");
+ let label = browser.i18n.getMessage("issueReporter_doneButton_label");
+ continueButton.textContent = label;
continueButton.disabled = true;
let uuid = new Uint16Array(8);
window.crypto.getRandomValues(uuid);
uuid[3] = uuid[3] & 0x0FFF | 0x4000; // version 4
uuid[4] = uuid[4] & 0x3FFF | 0x8000; // variant 1
let uuidString = "";
for (let i = 0; i < uuid.length; i++)
{
let component = uuid[i].toString(16);
while (component.length < 4)
component = "0" + component;
uuidString += component;
- if (i >= 1 && i<= 4)
+ if (i >= 1 && i <= 4)
uuidString += "-";
}
let params = new URLSearchParams({
version: 1,
guid: uuidString,
- lang: reportData.getElementsByTagName("adblock-plus")[0].getAttribute("locale")
+ lang: reportData.getElementsByTagName("adblock-plus")[0]
+ .getAttribute("locale")
});
let url = "https://reports.adblockplus.org/submitReport?" + params;
let reportSent = event =>
{
let success = false;
- let errorMessage = browser.i18n.getMessage("filters_subscription_lastDownload_connectionError");
+ let errorMessage = browser.i18n.getMessage(
+ "filters_subscription_lastDownload_connectionError"
+ );
try
{
success = request.status == 200;
if (request.status != 0)
errorMessage = request.status + " " + request.statusText;
}
catch (e)
{
@@ -382,19 +395,19 @@ function initSendPage()
errorElement.removeChild(errorElement.firstChild);
let link = document.createElement("a");
link.textContent = linkText;
browser.runtime.sendMessage({
type: "app.get",
what: "doclink",
link: "reporter_connect_issue"
- }).then(url =>
+ }).then(supportUrl =>
{
- link.href = url;
+ link.href = supportUrl;
});
errorElement.appendChild(document.createTextNode(beforeLink));
errorElement.appendChild(link);
errorElement.appendChild(document.createTextNode(afterLink));
errorElement.hidden = false;
@@ -403,34 +416,34 @@ function initSendPage()
result = result.replace(/%CONFIRMATION%/g, encodeHTML(browser.i18n.getMessage("issueReporter_confirmationMessage")));
result = result.replace(/%KNOWNISSUE%/g, encodeHTML(browser.i18n.getMessage("issueReporter_knownIssueMessage")));
result = result.replace(/(<html)\b/, '$1 dir="' + encodeHTML(window.getComputedStyle(document.documentElement, "").direction + '"'));
document.getElementById("sendReportMessage").hidden = true;
document.getElementById("sendingProgressContainer").hidden = true;
let resultFrame = document.getElementById("result");
- resultFrame.setAttribute("src", "data:text/html;charset=utf-8," + encodeURIComponent(result));
+ resultFrame.setAttribute("src", "data:text/html;charset=utf-8," +
+ encodeURIComponent(result));
resultFrame.hidden = false;
document.getElementById("continue").disabled = false;
};
let request = new XMLHttpRequest();
request.open("POST", url);
request.setRequestHeader("Content-Type", "text/xml");
request.setRequestHeader("X-Adblock-Plus", "1");
request.addEventListener("load", reportSent);
request.addEventListener("error", reportSent);
request.upload.addEventListener("progress", event =>
{
if (!event.lengthComputable)
return;
- let progress = Math.round(event.loaded / event.total * 100);
if (event.loaded > 0)
{
let progress = document.getElementById("sendingProgress");
progress.max = event.total;
progress.value = event.loaded;
}
});
request.send(serializeReportData());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld