Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ parserOptions:

extends:
- eslint:recommended
- plugin:mozilla/recommended

globals:
BrowserStorageCredentials: false
Expand All @@ -34,9 +35,13 @@ globals:
saveToKinto: false
setAnimation: false

plugins:
- mozilla

root: true

rules:
consistent-return: warn
eqeqeq: error
linebreak-style: [error, unix]
no-console: warn
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"chai": "^4.1.0",
"chai-as-promised": "^7.1.1",
"cross-spawn": "^5.1.0",
"eslint": "^4.0.0",
"eslint": "^4.17.0",
"eslint-plugin-mozilla": "^0.7.0",
"eslint-plugin-no-unsanitized": "^2.0.2",
"fetch-mock": "^5.12.2",
"fs-extra": "^4.0.1",
"karma": "^1.7.1",
Expand Down
6 changes: 3 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ function sendMetrics(event, context = {}) {
let metrics = {};

if (event === 'open') {
metrics.cd9 = context.loaded === false ? false : true;
metrics.cd9 = context.loaded !== false;
} else if (event === 'close') {
metrics.cd7 = context.closeUI;
metrics.cd8 = null; // reason editing session ended
} else if (event === 'changed' || event === 'drag-n-drop') { // Editing
} else if (event === 'changed' || event === 'drag-n-drop') { // Editing
metrics = {
cm1: context.characters,
cm2: context.lineBreaks,
Expand Down Expand Up @@ -129,7 +129,7 @@ browser.runtime.onMessage.addListener(function(eventData) {
browser.runtime.sendMessage({
action: 'kinto-loaded',
data: result && typeof result.data !== 'undefined' ? result.data.content : null,
last_modified: result && typeof result.data !== 'undefined' && typeof result.data.last_modified !== 'undefined' ? result.data.last_modified : null,
last_modified: result && typeof result.data !== 'undefined' && typeof result.data.last_modified !== 'undefined' ? result.data.last_modified : null,
});
}).catch(() => {
sendMetrics('open', {loaded: false});
Expand Down
30 changes: 15 additions & 15 deletions src/fxa-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Module that provides utils for Firefox Accounts
*/

/**
*
* @param {String} FXA_PROFILE_SERVER - profile server
Expand All @@ -13,19 +14,19 @@ function fxaFetchProfile(FXA_PROFILE_SERVER, token) { // eslint-disable-line no-
});
const request = new Request(`${FXA_PROFILE_SERVER}/profile`, {
method: 'GET',
headers: headers
headers
});

return fetch(request).then((resp) => {
if (resp.status === 200) {
return resp.json();
} else {
throw new Error('Failed to fetch profile');
}
throw new Error('Failed to fetch profile');
});
}

function fxaRenewCredential(credential) { // eslint-disable-line no-unused-vars
// eslint-disable-next-line no-unused-vars
function fxaRenewCredential(credential) {
const fxaOAuthServer = credential.metadata.server;
const clientId = credential.metadata.client_id;
const scope = credential.metadata.scope;
Expand All @@ -37,19 +38,21 @@ function fxaRenewCredential(credential) { // eslint-disable-line no-unused-vars

const accessTokenVerifyRequest = new Request(`${fxaOAuthServer}/verify`, {
method: 'POST',
headers: headers,
headers,
body: JSON.stringify({
token: accessToken,
})
});

const refreshTokenRequest = new Request(`${fxaOAuthServer}/token`, {
method: 'POST',
headers: headers,
headers,
body: JSON.stringify({
client_id: clientId, // eslint-disable-line camelcase
grant_type: 'refresh_token', // eslint-disable-line camelcase
refresh_token: refreshToken, // eslint-disable-line camelcase
// eslint-disable camelcase
client_id: clientId,
grant_type: 'refresh_token',
refresh_token: refreshToken,
// eslint-enable camelcase
scope: scope.join(' ')
})
});
Expand All @@ -64,24 +67,21 @@ function fxaRenewCredential(credential) { // eslint-disable-line no-unused-vars
}, () => {
throw new Error('Failed to verify token');
}).then((resp) => {
if (! resp) {
if (!resp) {
// no response means we never made the request
return null;
} else if (resp.status === 200) {
return resp.json();
} else {
// if failed to renew then throw
throw new Error('Failed to renew token');
}
// if failed to renew then throw
throw new Error('Failed to renew token');
}, () => {
throw new Error('Failed to renew token');
}).then((renewResp) => {
if (renewResp) {
// if a renew response then update credential
credential.access_token = renewResp.access_token;
}

return credential;
});

}
6 changes: 3 additions & 3 deletions src/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ const themeLegend = document.getElementById('themeTitle');
const defaultThemeLabel = document.getElementById('default_label');
const darkThemeLabel = document.getElementById('dark_label');

/* eslint-disable no-unsanitized/property */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just disabled the rule for these 3 lines. Not sure if there is some "sanitization" module we wanted to use or something to make sure there aren't any potential XSS leaks from the l10n files.

themeLegend.innerHTML = browser.i18n.getMessage('themeLegend');
defaultThemeLabel.innerHTML = browser.i18n.getMessage('defaultThemeTitle');
darkThemeLabel.innerHTML = browser.i18n.getMessage('darkThemeTitle');
/* eslint-enable no-unsanitized/property */

const themeRadioBtn = document.getElementsByName('theme');

Expand Down Expand Up @@ -33,9 +35,7 @@ function getTheme() {
continue;
}

const selectedTheme = {
theme: theme
};
const selectedTheme = {theme};

return selectedTheme;
}
Expand Down
6 changes: 3 additions & 3 deletions src/sidebar/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function customizeEditor(editor) {
editor.fire('changesDone');
});
});

document.addEventListener('dragover', () => {
mainEditor.classList.add('drag-n-drop-focus');
});
Expand All @@ -38,7 +38,7 @@ function customizeEditor(editor) {
localizeEditorButtons();
}

function localizeEditorButtons () {
function localizeEditorButtons() {
// Clear CKEditor tooltips. Fixes: https://github.com/mozilla/notes/issues/410
document.querySelectorAll('.ck-toolbar .ck-tooltip__text').forEach((sel) => {
sel.remove();
Expand Down Expand Up @@ -185,5 +185,5 @@ function setAnimation( animateSyncIcon = true, syncingLayout, warning, syncSucce
*/
function formatFooterTime(date) {
date = date || Date.now();
return new Date(date).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
return new Date(date).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'});
}
8 changes: 4 additions & 4 deletions src/sidebar/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ migrationCloseButton.addEventListener('click', () => {
});

function migrationCheck(editor) {
console.log('Editor migration started...'); // eslint-disable-line no-console
console.log('Editor migration started...'); // eslint-disable-line no-console
const quill = new Quill('#migrationPlaceholder', {});

syncNowEnabledCheck();
Expand All @@ -29,7 +29,7 @@ function migrationCheck(editor) {
browser.storage.local.set({ notesQuillBackup: data.notes });
} else {
// if there is no old data then nothing to do
console.log('Already migrated.'); // eslint-disable-line no-console
console.log('Already migrated.'); // eslint-disable-line no-console

chrome.runtime.sendMessage({
action: 'metrics-migrated-before'
Expand All @@ -53,7 +53,7 @@ function migrationCheck(editor) {
});

migrationNote.classList.add('visible');
console.log('Editor migration complete.'); // eslint-disable-line no-console
console.log('Editor migration complete.'); // eslint-disable-line no-console
});

});
Expand All @@ -74,7 +74,7 @@ function syncNowEnabledCheck() {

// do not block editor on this getter
browser.storage.local.get('asked-for-syncing').then((data) => {
if(data && data['asked-for-syncing']) {
if (data && data['asked-for-syncing']) {
noteDiv.classList.add('visible');
browser.storage.local.remove('asked-for-syncing');
}
Expand Down
21 changes: 10 additions & 11 deletions src/sidebar/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ ClassicEditor.create(document.querySelector('#editor'), {
if (isFocused || name === 'rename' || name === 'insert') {
const content = editor.getData();
if (!ignoreNextLoadEvent && content !== undefined &&
content.replace(/ /g, ' ') !== INITIAL_CONTENT) {
content.replace(/ /g, ' ') !== INITIAL_CONTENT) {
ignoreTextSynced = true;
if (content.length > 15000) {
console.error('Maximum notepad size reached:', content.length); // eslint-disable-line no-console
console.error('Maximum notepad size reached:', content.length); // eslint-disable-line no-console
migrationNote.classList.add('visible');
migrationBody.textContent = browser.i18n.getMessage('maximumPadSizeExceeded');
} else {
Expand Down Expand Up @@ -170,7 +170,7 @@ ClassicEditor.create(document.querySelector('#editor'), {
syncingInProcess = false;
break;
case 'text-saved':
if (! waitingToReconnect && ! isAuthenticated) {
if (!waitingToReconnect && !isAuthenticated) {
// persist reconnect warning, do not override with the 'saved at'
savingIndicator.textContent = browser.i18n.getMessage('savedComplete2', formatFooterTime());
}
Expand Down Expand Up @@ -233,15 +233,13 @@ function handleLocalContent(editor, content) {
});
}
});
} else {
if (editor.getData() !== content) {
} else if (editor.getData() !== content) {
// Prevent from loading too big content but allow for conflict handling.
editor.setData(content);
}
}
}

function reconnectSync () {
function reconnectSync() {
waitingToReconnect = true;
isAuthenticated = false;
setAnimation(false, true, true); // animateSyncIcon, syncingLayout, warning
Expand All @@ -251,7 +249,7 @@ function reconnectSync () {
});
}

function disconnectFromSync () {
function disconnectFromSync() {
waitingToReconnect = false;
disconnectSync.style.display = 'none';
isAuthenticated = false;
Expand Down Expand Up @@ -284,7 +282,7 @@ function enableSyncAction(editor) {
} else if (!isAuthenticated && (footerButtons.classList.contains('savingLayout') || waitingToReconnect)) {
// Login
giveFeedbackButton.style.display = 'none';
setAnimation(true, true, false); // animateSyncIcon, syncingLayout, warning
setAnimation(true, true, false); // animateSyncIcon, syncingLayout, warning

// enable disable sync button
disconnectSync.style.display = 'block';
Expand Down Expand Up @@ -316,10 +314,11 @@ function getLastSyncedTime() {

if (isAuthenticated) {
giveFeedbackButton.style.display = 'none';
savingIndicator.innerHTML = browser.i18n.getMessage('syncComplete3', formatFooterTime(lastModified));
// eslint-disable-next-line no-unsanitized/property
savingIndicator.innerHTML = browser.i18n.getMessage('syncComplete3', formatFooterTime(lastModified));
disconnectSync.style.display = 'block';
isAuthenticated = true;
setAnimation(false, true, false, true); // animateSyncIcon, syncingLayout, warning, syncSuccess
setAnimation(false, true, false, true); // animateSyncIcon, syncingLayout, warning, syncSuccess
} else {
savingIndicator.textContent = browser.i18n.getMessage('changesSaved', formatFooterTime());
}
Expand Down
8 changes: 3 additions & 5 deletions src/sidebar/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ function getThemeFromStorage() {
const getting = browser.storage.local.get(['theme']);
getting.then(function applyTheme(data) {
if (data.theme === 'dark') {
if (! document.getElementById('dark-styles')) {
if (!document.getElementById('dark-styles')) {
const darkSS = document.createElement('link');
darkSS.id = 'dark-styles';
darkSS.type = 'text/css';
darkSS.rel = 'stylesheet';
darkSS.href = 'styles-dark.css';
document.getElementsByTagName('head')[0].appendChild(darkSS);
} else
return;
}
} else if (data.theme === 'default' || data.theme === undefined) {
if (document.getElementById('dark-styles')) {
const darkSS = document.getElementById('dark-styles');
darkSS.parentElement.removeChild(darkSS);
} else
return;
}
}
});
}
Expand Down
9 changes: 4 additions & 5 deletions src/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,10 @@ function syncKinto(client, credentials) {
} else if (error.message === 'Failed to renew token') {
// cannot refresh the access token, log the user out.
return reconnectSync(credentials);
} else {
console.error(error); // eslint-disable-line no-console
reconnectSync(credentials);
return Promise.reject(error);
}
console.error(error); // eslint-disable-line no-console
reconnectSync(credentials);
return Promise.reject(error);
});
}

Expand Down Expand Up @@ -299,7 +298,7 @@ function loadFromKinto(client, credentials) {
browser.runtime.sendMessage({
action: 'kinto-loaded',
data: result && typeof result.data !== 'undefined' ? result.data.content : null,
last_modified: result && typeof result.data !== 'undefined' && typeof result.data.last_modified !== 'undefined' ? result.data.last_modified : null,
last_modified: result && typeof result.data !== 'undefined' && typeof result.data.last_modified !== 'undefined' ? result.data.last_modified : null,
});
});
}
Expand Down