diff --git a/.eslintrc.js b/.eslintrc.js index da11fbc21..5417bdc63 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -40,7 +40,6 @@ module.exports = { rules: { 'arrow-parens': [2, 'as-needed', { 'requireForBlockBody': true }], 'camelcase': [0], - 'class-methods-use-this': [1], 'comma-dangle': [2, { 'arrays': 'only-multiline', 'objects': 'only-multiline', @@ -54,7 +53,6 @@ module.exports = { 'lines-between-class-members': [1], 'max-len': [0], 'newline-per-chained-call': [0, { 'ignoreChainWithDepth': 2 }], - 'no-mixed-operators': [1], 'no-nested-ternary': [0], 'no-param-reassign': ['error', { props: true, @@ -72,28 +70,22 @@ module.exports = { ] }], 'no-plusplus': [0], - 'no-prototype-builtins': [0], - 'no-restricted-syntax': [1], + 'no-prototype-builtins': [0], // Ignored because of hasOwnProperty calls. 'no-tabs': [0], 'no-underscore-dangle': [0], 'no-unused-vars': [1], 'no-useless-escape': [1], 'operator-linebreak': [0], - 'prefer-object-spread': [1], 'space-before-function-paren': [2, 'never'], // Plugin: Import 'import/no-cycle': [0], - 'import/prefer-default-export': [1], // Plugin: React - 'react/destructuring-assignment': [1], 'react/static-property-placement': [0], 'react/jsx-curly-newline': [0], 'react/jsx-indent': [1, 'tab'], 'react/jsx-indent-props': [1, 'tab'], - 'react/jsx-props-no-spreading': [1], - 'react/no-access-state-in-setstate': [1], 'react/no-danger': [0], 'react/prop-types': [0], 'react/jsx-fragments': [1, 'element'], diff --git a/app/content-scripts/click_to_play.js b/app/content-scripts/click_to_play.js index a17479c69..3109c291b 100644 --- a/app/content-scripts/click_to_play.js +++ b/app/content-scripts/click_to_play.js @@ -161,11 +161,10 @@ const Click2PlayContentScript = (function(win, doc) { if (message) { // Dequeue C2P data stored while the script injection was taking place const messageKeys = Object.keys(message); - for (let i = 0; i < messageKeys.length; i++) { - const app_id = messageKeys[i]; + messageKeys.forEach((app_id) => { applyC2P(app_id, message[app_id].data, message[app_id].html); delete message[app_id]; - } + }); } } diff --git a/app/images/panel/green-upgrade-banner-small.svg b/app/images/panel/green-upgrade-banner-small.svg deleted file mode 100644 index 210cc4245..000000000 --- a/app/images/panel/green-upgrade-banner-small.svg +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/panel-android/components/Panel.jsx b/app/panel-android/components/Panel.jsx index 50f53dca5..93d408c6e 100644 --- a/app/panel-android/components/Panel.jsx +++ b/app/panel-android/components/Panel.jsx @@ -148,8 +148,7 @@ export default class Panel extends React.Component { } render() { - const { panel } = this.props; - const { cliqzModuleData } = this.state; + const { panel, cliqzModuleData } = this.state; return (
diff --git a/app/panel-android/components/content/ChartSVG.jsx b/app/panel-android/components/content/ChartSVG.jsx index 893d50046..ffff1c305 100644 --- a/app/panel-android/components/content/ChartSVG.jsx +++ b/app/panel-android/components/content/ChartSVG.jsx @@ -24,14 +24,13 @@ export default class ChartSVG extends React.Component { } increaseN = () => { - const { paths } = this.props; - const { nItem } = this.state; - let currentN = nItem; - if (currentN < paths.length) { - this.setState({ - nItem: currentN += 1, - }); - } + this.setState((prevState) => { + const { paths } = this.props; + if (prevState.nItem < paths.length) { + return { nItem: prevState.nItem + 1 }; + } + return null; + }); } render() { diff --git a/app/panel-android/components/content/DotsMenu.jsx b/app/panel-android/components/content/DotsMenu.jsx index 7cc17d440..a612ea2ab 100644 --- a/app/panel-android/components/content/DotsMenu.jsx +++ b/app/panel-android/components/content/DotsMenu.jsx @@ -43,12 +43,7 @@ export default class DotsMenu extends React.Component { /* Toggle menu */ dotsButtonClicked = () => { - const { opening } = this.state; - const currentState = opening; - - this.setState({ - opening: !currentState, - }); + this.setState(prevState => ({ opening: !prevState.opening })); } render() { diff --git a/app/panel-android/components/content/FixedMenu.jsx b/app/panel-android/components/content/FixedMenu.jsx index 29a3d7dc6..5f0eb44c5 100644 --- a/app/panel-android/components/content/FixedMenu.jsx +++ b/app/panel-android/components/content/FixedMenu.jsx @@ -51,16 +51,14 @@ export default class FixedMenu extends React.Component { switch (type) { case 'enable_anti_tracking': { const categories = Object.keys(this.antiTrackingData); - for (let i = 0; i < categories.length; i++) { - const category = categories[i]; + categories.forEach((category) => { const apps = Object.keys(this.antiTrackingData[category]); - for (let j = 0; j < apps.length; j++) { - const app = apps[j]; + apps.forEach((app) => { if (this.antiTrackingData[category][app] === 'unsafe') { total++; } - } - } + }); + }); return total; } case 'enable_ad_block': @@ -79,14 +77,10 @@ export default class FixedMenu extends React.Component { } toggleMenu = () => { - const { open } = this.state; - const currentState = open; - this.setState({ - open: !currentState, - }); + this.setState(prevState => ({ open: !prevState.open })); } - updateHeadeText = (text) => { + updateHeaderText = (text) => { const textToShow = text || FixedMenu.defaultHeaderText; this.setState({ @@ -106,7 +100,7 @@ export default class FixedMenu extends React.Component {
  • { - const { updateHeadeText, title } = this.props; + const { updateHeaderText, title } = this.props; this.setState({ opening: true, }); - updateHeadeText(title); + updateHeaderText(title); } closeButtonClicked = () => { - const { updateHeadeText } = this.props; + const { updateHeaderText } = this.props; this.setState({ opening: false, }); - updateHeadeText(''); + updateHeaderText(''); } switcherClicked = () => { diff --git a/app/panel/components/Blocking.jsx b/app/panel/components/Blocking.jsx index 159482a49..f598eb93c 100644 --- a/app/panel/components/Blocking.jsx +++ b/app/panel/components/Blocking.jsx @@ -26,18 +26,6 @@ import { updateSummaryBlockingCount } from '../utils/blocking'; class Blocking extends React.Component { static contextType = DynamicUIPortContext; - /** - * Refactoring UNSAFE_componentWillMount into Constructor - * Stats: - * Constructor runtime before refactor: 0.038ms - * Constructor + UNSAFE_componentWillMount runtime before refactor: 0.333ms - * Constructor runtime after refactor: 0.129ms - * - * Notes: - * calling buildBlockingClasses and computeSiteNotScanned in the constructor takes 0.018ms. - * - * Conclusion: Refactor using constructor as the added computation is minimal - */ constructor(props) { super(props); diff --git a/app/panel/components/Blocking/BlockingHeader.jsx b/app/panel/components/Blocking/BlockingHeader.jsx index 05c0bcc41..4ec56c338 100644 --- a/app/panel/components/Blocking/BlockingHeader.jsx +++ b/app/panel/components/Blocking/BlockingHeader.jsx @@ -48,9 +48,6 @@ class BlockingHeader extends React.Component { /** * Lifecycle event - * Refactor Notes: - * Refactor UNSAFE_componentWillReceiveProps using getDerivedStateFromProps - * because we are only manipulating state. */ static getDerivedStateFromProps(prevProps, prevState) { return BlockingHeader.updateBlockAll(prevProps.categories, prevState.fromHere); diff --git a/app/panel/components/Blocking/Tracker.jsx b/app/panel/components/Blocking/Tracker.jsx index 4f9ea6a9e..a74ed851d 100644 --- a/app/panel/components/Blocking/Tracker.jsx +++ b/app/panel/components/Blocking/Tracker.jsx @@ -27,20 +27,6 @@ import { renderKnownTrackerButtons, renderUnknownTrackerButtons } from './tracke class Tracker extends React.Component { static contextType = ThemeContext; - /** - * Refactoring UNSAFE_componentWillMount into Constructor - * Stats: - * Constructor runtime before refactor: 0.037ms - * Constructor + UNSAFE_componentWillMount runtime before refactor: 0.415ms - * Constructor runtime after refactor: 0.215ms - * - * Refactoring UNSAFE_componentWillMount into componentDidMount - * Stats: - * Constructor runtime after refactor: 0.020ms - * Constructor + componentDidMount runtime after refactor: 14.205ms - * - * Conclusion: Refactor using componentDidMount - */ constructor(props) { super(props); this.state = { diff --git a/app/panel/components/BuildingBlocks/DonutGraph.jsx b/app/panel/components/BuildingBlocks/DonutGraph.jsx index 9dda64d93..d48b9a0df 100644 --- a/app/panel/components/BuildingBlocks/DonutGraph.jsx +++ b/app/panel/components/BuildingBlocks/DonutGraph.jsx @@ -153,7 +153,7 @@ class DonutGraph extends React.Component { return; } - // componentWillReceiveProps gets called many times during page load as new trackers or unsafe data points are found + // componentDidUpdate gets called many times during page load as new trackers or unsafe data points are found // so only compare tracker totals if we don't already have to redraw anyway as a result of the cheaper checks above const prevTrackerTotal = prevCategories.reduce((total, category) => total + category.num_total, 0); const trackerTotal = categories.reduce((total, category) => total + category.num_total, 0); diff --git a/app/panel/components/Detail.jsx b/app/panel/components/Detail.jsx index fc20f5f36..b03bcffc8 100644 --- a/app/panel/components/Detail.jsx +++ b/app/panel/components/Detail.jsx @@ -22,23 +22,6 @@ import Rewards from '../containers/RewardsContainer'; * @memberOf PanelClasses */ class Detail extends React.Component { - /** - * Refactoring UNSAFE_componentWillMount into Constructor - * Stats: - * Constructor runtime before refactor: 0.085ms - * Constructor + UNSAFE_componentWillMount runtime before refactor: 0.345ms - * Constructor runtime after refactor: 0.163ms - * - * Refactoring UNSAFE_componentWillMount into componentDidMount - * Stats: - * Constructor runtime with no componentDidMount: 0.163ms - * Constructor runtime with componentDidMount: 0.078ms - * Constructor + componentDidMount runtime: 8.313ms - * Notes: - * Noticably slower when refactoring using componentDidMount - * - * Conclusion: Refactor using constructor - */ constructor(props) { super(props); diff --git a/app/panel/components/Settings.jsx b/app/panel/components/Settings.jsx index 67ab99bfa..5ca6ba4d2 100644 --- a/app/panel/components/Settings.jsx +++ b/app/panel/components/Settings.jsx @@ -42,22 +42,6 @@ class Settings extends React.Component { }); }, 3000) - /** - * Refactoring UNSAFE_componentWillMount into Constructor - * Stats: - * Constructor runtime before refactor: 0.145ms - * Constructor + UNSAFE_componentWillMount runtime before refactor: 0.330ms - * Constructor runtime after refactor: 0.144ms - * - * Refactoring UNSAFE_componentWillMount into componentDidMount - * Stats: - * Constructor runtime with no componentDidMount: 0.123ms - * Constructor runtime with componentDidMount: 0.147ms - * - * Notes: Negligible difference using componentDidMount. - * - * Conclusion: Refactor using constructor to avoid re-render - */ constructor(props) { super(props); this.state = { diff --git a/app/panel/components/Settings/GeneralSettings.jsx b/app/panel/components/Settings/GeneralSettings.jsx index 61b4ad320..1381b34e2 100644 --- a/app/panel/components/Settings/GeneralSettings.jsx +++ b/app/panel/components/Settings/GeneralSettings.jsx @@ -19,23 +19,6 @@ import moment from 'moment/min/moment-with-locales.min'; * @memberOf SettingsComponents */ class GeneralSettings extends React.Component { - /** - * Refactoring UNSAFE_componentWillMount into Constructor - * Stats: - * Constructor runtime before refactor: 0.026ms - * Constructor + UNSAFE_componentWillMount runtime before refactor: 2.410ms - * Constructor runtime after refactor: 1.631ms - * - * Refactoring UNSAFE_componentWillMount into componentDidMount - * Stats: - * Constructor runtime with no componentDidMount: 0.208ms - * Constructor runtime with componentDidMount: 0.074ms - * - * Notes: - * updateDbLastUpdated takes ~2ms to run the firt time and then 0.139ms subsequent times. - * - * Conclusion: Refactor using componentDidMount as to not do computations in the constructor - */ constructor(props) { super(props); this.state = { diff --git a/app/panel/components/Settings/TrustAndRestrict.jsx b/app/panel/components/Settings/TrustAndRestrict.jsx index 71a358210..366532192 100644 --- a/app/panel/components/Settings/TrustAndRestrict.jsx +++ b/app/panel/components/Settings/TrustAndRestrict.jsx @@ -184,8 +184,6 @@ class TrustAndRestrict extends React.Component { const { menu, trustedValue, currentWarning, restrictedValue } = this.state; - const trusted_sites = site_whitelist; - const restricted_sites = site_blacklist; return (
    @@ -212,8 +210,8 @@ class TrustAndRestrict extends React.Component {
    {currentWarning}
    - { trusted_sites && trusted_sites.length > 0 && - + { site_whitelist && site_whitelist.length > 0 && + }
  • @@ -227,8 +225,8 @@ class TrustAndRestrict extends React.Component {
    {currentWarning}
    - { restricted_sites && restricted_sites.length > 0 && - + { site_blacklist && site_blacklist.length > 0 && + } diff --git a/app/panel/components/Summary.jsx b/app/panel/components/Summary.jsx index ae0c22adf..79c0faecd 100644 --- a/app/panel/components/Summary.jsx +++ b/app/panel/components/Summary.jsx @@ -82,7 +82,7 @@ class Summary extends React.Component { } /** - * Calculates total tracker latency and sets it to state + * Calculates total tracker latency * @param {Object} props Summary's props, either this.props or nextProps. */ static _computeTrackerLatency(props) { diff --git a/app/panel/reducers/panel.js b/app/panel/reducers/panel.js index 559d82663..746838d44 100644 --- a/app/panel/reducers/panel.js +++ b/app/panel/reducers/panel.js @@ -268,17 +268,6 @@ export default (state = initialState, action) => { setTheme(document); return { ...state, current_theme: initialState.current_theme }; } - // @TODO? - // case LOGOUT_SUCCESS: { - // const notificationAction = { - // payload: { - // text: 'Logged out successfully.', - // classes: 'success', - // } - // }; - // const updated = _showNotification(state, notificationAction); - // return Object.assign({}, state, updated); - // } case RESET_PASSWORD_SUCCESS: { const notificationAction = { payload: { diff --git a/app/panel/reducers/settings.js b/app/panel/reducers/settings.js index 9b20c7534..f009072d9 100644 --- a/app/panel/reducers/settings.js +++ b/app/panel/reducers/settings.js @@ -92,20 +92,18 @@ const _exportSettings = (state, action) => { */ const _importSettingsDialog = (state, action) => { const result = action.data; - let updated_actionSuccess = state.actionSuccess; - let updated_importResultText = state.importResultText; if (result === true) { // showBrowseWindow was successful window.close(); - } else { - updated_actionSuccess = false; - updated_importResultText = t('settings_import_dialog_error'); } - return { - actionSuccess: updated_actionSuccess, - importResultText: updated_importResultText, + return (result === true) ? { + actionSuccess: state.actionSuccess, + importResultText: state.importResultText, + } : { + actionSuccess: false, + importResultText: t('settings_import_dialog_error'), }; }; @@ -120,15 +118,9 @@ const _importSettingsDialog = (state, action) => { */ const _importSettingsNative = (state, action) => { const { settings } = action; - const updated_state = {}; - const settingsKeys = Object.keys(settings); - for (let i = 0; i < settingsKeys.length; i++) { - const key = settingsKeys[i]; - let value = settings[key]; - if (key === 'alert_bubble_timeout') { - value = (value > 30) ? 30 : value; - } - updated_state[key] = value; + const updated_state = { ...settings }; + if (updated_state.hasOwnProperty('alert_bubble_timeout')) { + updated_state.alert_bubble_timeout = Math.min(30, updated_state.alert_bubble_timeout); } updated_state.settings_last_imported = Number((new Date()).getTime()); diff --git a/app/scss/partials/_upgrade_banner.scss b/app/scss/partials/_upgrade_banner.scss index d942e8dae..cac002216 100644 --- a/app/scss/partials/_upgrade_banner.scss +++ b/app/scss/partials/_upgrade_banner.scss @@ -13,13 +13,21 @@ .UpgradeBanner { @extend %pointer; - background: url("../../app/images/panel/green-upgrade-banner.svg"); - background-size: contain; - background-repeat: repeat-x; } .UpgradeBanner--normal { height: 25px; + background: linear-gradient(#9ECC42, #429321); + &::before { + content: ''; + position: absolute; + right: 0; + height: 0; + width: 0; + border-top: 12.5px solid transparent; + border-bottom: 12.5px solid transparent; + border-right: 10px solid white; + } .UpgradeBanner__text { font-size: 12px; @@ -34,6 +42,17 @@ .UpgradeBanner--small { height: 20px; + background: linear-gradient(#9ECC42, #429321); + &::before { + content: ''; + position: absolute; + right: 0; + height: 0; + width: 0; + border-top: 10px solid transparent; + border-bottom: 10px solid transparent; + border-right: 8px solid white; + } .UpgradeBanner__text { font-size: 10px; @@ -43,6 +62,7 @@ .UpgradeBanner__plus { vertical-align: middle; + padding-right: 12px; } } @@ -55,5 +75,5 @@ .UpgradeBanner__plus { display: inline-block; - padding-right: 18px; + padding-right: 15px; } diff --git a/src/background.js b/src/background.js index 92e892283..d04f996bd 100644 --- a/src/background.js +++ b/src/background.js @@ -163,14 +163,13 @@ function setGhosteryDefaultBlocking() { log('Blocking all trackers in categories:', ...categoriesBlock); const selected_app_ids = {}; const app_ids = Object.keys(bugDb.db.apps); - for (let i = 0; i < app_ids.length; i++) { - const app_id = app_ids[i]; + app_ids.forEach((app_id) => { const category = bugDb.db.apps[app_id].cat; if (categoriesBlock.indexOf(category) >= 0 && !selected_app_ids.hasOwnProperty(app_id)) { selected_app_ids[app_id] = 1; } - } + }); panelData.set({ selected_app_ids }); } @@ -580,12 +579,11 @@ function handleGhosteryHub(name, message, callback) { panelData.set({ setup_block: 3 }); const selected_app_ids = {}; const app_ids = Object.keys(bugDb.db.apps); - for (let i = 0; i < app_ids.length; i++) { - const app_id = app_ids[i]; + app_ids.forEach((app_id) => { if (!selected_app_ids.hasOwnProperty(app_id)) { selected_app_ids[app_id] = 1; } - } + }); panelData.set({ selected_app_ids }); break; } @@ -889,6 +887,8 @@ function onMessageHandler(request, sender, callback) { .then((foundUser) => { const user = { user: { ...foundUser } }; if (foundUser) { + user.user.plusAccess = account.hasScopesUnverified(['subscriptions:plus']) + || account.hasScopesUnverified(['subscriptions:premium']); user.user.premiumAccess = account.hasScopesUnverified(['subscriptions:premium']); } callback(user); diff --git a/src/classes/BugDb.js b/src/classes/BugDb.js index 8b714dbd4..5ca1fd738 100644 --- a/src/classes/BugDb.js +++ b/src/classes/BugDb.js @@ -76,7 +76,6 @@ class BugDb extends Updatable { let appId; let category; let blocked; - let categoryName; const categoryArray = []; const categories = {}; @@ -123,8 +122,7 @@ class BugDb extends Updatable { } const categoryNames = Object.keys(categories); - for (let i = 0; i < categoryNames.length; i++) { - categoryName = categoryNames[i]; + categoryNames.forEach((categoryName) => { const cat = categories[categoryName]; if (cat.trackers) { cat.trackers.sort((a, b) => { @@ -135,7 +133,7 @@ class BugDb extends Updatable { } categoryArray.push(cat); - } + }); // Sort categories by tracker numbers categoryArray.sort((a, b) => { @@ -176,10 +174,9 @@ class BugDb extends Updatable { log('initializing bugdb regexes...'); const regexesKeys = Object.keys(regexes); - for (let i = 0; i < regexesKeys.length; i++) { - const id = regexesKeys[i]; + regexesKeys.forEach((id) => { db.patterns.regex[id] = new RegExp(regexes[id], 'i'); - } + }); log('setting bugdb noneSelected/allSelected...'); diff --git a/src/classes/Click2PlayDb.js b/src/classes/Click2PlayDb.js index 16fc6847e..69172c150 100644 --- a/src/classes/Click2PlayDb.js +++ b/src/classes/Click2PlayDb.js @@ -68,15 +68,14 @@ class Click2PlayDb extends Updatable { let keep = false; const allowKeys = Object.keys(this.allowOnceList[tab_id]); - for (let i = 0; i < allowKeys.length; i++) { - const appID = allowKeys[i]; + allowKeys.forEach((appID) => { const count = this.allowOnceList[tab_id][appID]; const newCount = count - 1; this.allowOnceList[tab_id][appID] = newCount; if (newCount > 0) { keep = true; } - } + }); if (!keep) { delete this.allowOnceList[tab_id]; } diff --git a/src/classes/FoundBugs.js b/src/classes/FoundBugs.js index fd2cd17d4..73332e226 100644 --- a/src/classes/FoundBugs.js +++ b/src/classes/FoundBugs.js @@ -194,20 +194,15 @@ class FoundBugs { const bugs = this.getBugs(tab_id); const { db } = bugDb; - let id; - let appid; - let cid; // category id - if (!bugs) { return bugs; } // squish all the bugs into categories first const ids = Object.keys(bugs); - for (let i = 0; i < ids.length; i++) { - id = ids[i]; - appid = db.bugs[id].aid; - cid = db.apps[appid].cat; + ids.forEach((id) => { + const appid = db.bugs[id].aid; + const cid = db.apps[appid].cat; if (cats_obj.hasOwnProperty(cid)) { if (!cats_obj[cid].appIds.includes(appid)) { @@ -239,14 +234,13 @@ class FoundBugs { total: 1 }; } - } + }); // convert categories hash to array const cids = Object.keys(cats_obj); - for (let i = 0; i < cids.length; i++) { - cid = cids[i]; + cids.forEach((cid) => { cats_arr.push(cats_obj[cid]); - } + }); if (sorted) { cats_arr.sort((a, b) => { diff --git a/src/classes/PanelData.js b/src/classes/PanelData.js index 7bc8881aa..bf6d28fef 100644 --- a/src/classes/PanelData.js +++ b/src/classes/PanelData.js @@ -590,8 +590,7 @@ class PanelData { // Set the conf from data const dataKeys = Object.keys(data); - for (let i = 0; i < dataKeys.length; i++) { - const key = dataKeys[i]; + dataKeys.forEach((key) => { const value = data[key]; if (conf.hasOwnProperty(key) && !isEqual(conf[key], value)) { conf[key] = value; @@ -613,7 +612,7 @@ class PanelData { } PanelData._toggleBlockingHelper(); } - } + }); if (data.needsReload && this._activeTab) { tabInfo.setTabInfo(this._activeTab.id, 'needsReload', data.needsReload); diff --git a/src/utils/cliqzModulesData.js b/src/utils/cliqzModulesData.js index 1e4555ad4..4a882a34e 100644 --- a/src/utils/cliqzModulesData.js +++ b/src/utils/cliqzModulesData.js @@ -58,17 +58,15 @@ export function getCliqzData(tabId, tabHostUrl, antiTracking) { return tracker.ads; }; - for (let i = 0; i < bugsValues.length; i++) { - const bug = bugsValues[i]; + bugsValues.forEach((bug) => { const dataPoints = getDataPoints(bug); if (dataPoints) { totalUnsafeCount += dataPoints; trackerCount++; } - } + }); - for (let i = 0; i < othersValues.length; i++) { - const other = othersValues[i]; + othersValues.forEach((other) => { let whitelisted = false; const dataPoints = getDataPoints(other); @@ -98,7 +96,7 @@ export function getCliqzData(tabId, tabHostUrl, antiTracking) { name, domains, ads, cookies, fingerprints, whitelisted, type }); } - } + }); return { totalUnsafeCount, diff --git a/src/utils/utils.js b/src/utils/utils.js index 965681395..d4e4e3c81 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -354,11 +354,10 @@ function _fetchJson(method, url, query, extraHeaders, referrer = 'no-referrer', }); if (extraHeaders) { const extraHeadersKeys = Object.keys(extraHeaders); - for (let i = 0; i < extraHeadersKeys.length; i++) { - const key = extraHeadersKeys[i]; + extraHeadersKeys.forEach((key) => { const value = extraHeaders[key]; headers.append(key, value); - } + }); } const options = { method, @@ -450,11 +449,10 @@ function _fetchJson(method, url, query, extraHeaders, referrer = 'no-referrer', xhr.setRequestHeader('Accept', 'application/json'); if (extraHeaders) { const extraHeadersKeys = Object.keys(extraHeaders); - for (let i = 0; i < extraHeadersKeys.length; i++) { - const key = extraHeadersKeys[i]; + extraHeadersKeys.forEach((key) => { const value = extraHeaders[key]; xhr.setRequestHeader(key, value); - } + }); } xhr.overrideMimeType('application/json'); xhr.send(query); diff --git a/tools/leet/leet-en.js b/tools/leet/leet-en.js index 7cf02cdfd..869d98b41 100644 --- a/tools/leet/leet-en.js +++ b/tools/leet/leet-en.js @@ -66,10 +66,9 @@ const leet_convert = function(string) { output = output.replace(/cks/g, 'x'); const characterKeys = Object.keys(characterMap); - for (let i = 0; i < characterKeys.length; i++) { - const letter = characterKeys[i]; + characterKeys.forEach((letter) => { output = output.replace(new RegExp(letter, 'g'), characterMap[letter]); - } + }); return output; }; @@ -85,14 +84,13 @@ if (!fs.existsSync('./tools/leet/messages.en.copy.json')) { // Create a LEETed version of the messages.json file const enKeys = Object.keys(en); - for (let i = 0; i < enKeys.length; i++) { - const key = enKeys[i]; + enKeys.forEach((key) => { if (en[key].hasOwnProperty('message')) { const message = leet_convert(en[key].message); const { placeholders } = en[key]; leet[key] = { message, placeholders }; } - } + }); // Save the leeted version and override the existing English messages.json file fs.writeFileSync('./tools/leet/messages.leet.json', JSON.stringify(leet), 'utf-8');