Skip to content

Commit

Permalink
[:hammer: REFACTOR] Replace function keyword with ES6 syntax
Browse files Browse the repository at this point in the history
For consistence and simpliness.

Fixes ---
Related to ---
  • Loading branch information
tomlutzenberger committed Oct 6, 2017
1 parent 0ba1b1e commit 93ac9b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
22 changes: 11 additions & 11 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @description Multi-Browser support
*/
window.browser = (function () {
window.browser = (() => {

'use strict';

Expand Down Expand Up @@ -262,7 +262,7 @@ const Rbutr = () => {
browser.tabs.query({
active: true,
lastFocusedWindow: true
}, function (tab) {
}, (tab) => {
let $data = Object.assign({}, {rbutr: rbutr, action: action}, data);

utils.log('debug', 'Active tab:', tab[FIRST_ARRAY_ELEMENT]);
Expand Down Expand Up @@ -311,7 +311,7 @@ const Rbutr = () => {
fromPageUrlHash: b64_md5(url),
version: browser.runtime.getManifest().version,
cid: api.getCid()
}, function (data) {
}, (data) => {
rbutr.setProp('rebuttals', tabId, data);
rbutr.setProp('loggedIn', null, true);

Expand Down Expand Up @@ -357,7 +357,7 @@ const Rbutr = () => {

rbutr.postMessage('showMessageBox', {message: titleMessage, url: rbutr.getProp('canonicalUrls', tabId)});
}
}).error(function (msg) {
}).error((msg) => {
rbutr.setProp('rebuttals', tabId, msg.responseText);
});
};
Expand Down Expand Up @@ -400,15 +400,15 @@ const Rbutr = () => {
direct: getProp('direct'),
tags: getProp('tags'),
cid: api.getCid()
}, function (data) {
}, (data) => {
utils.log('debug', 'Submit rebuttal success:', data.status);
rbutr.displayMessage('<strong>' + data.result + '</strong>');
window.open(data.redirectUrl);
rbutr.getPopup().cancelSubmission(); // Clear the data now that it's submitted.
rbutr.tabLoaded(tabId, getProp('canonicalUrls', tabId)); // This will reload the data for the tab, and set the badge.
}, 'json').done(function (msg) {
}, 'json').done((msg) => {
utils.log('debug', 'Submit rebuttal done:', msg.status);
}).fail(function (msg) {
}).fail((msg) => {
rbutr.displayMessage('Failed to submit : ' + msg.responseText);
utils.log('debug', 'Submit rebuttal fail:', msg);
});
Expand Down Expand Up @@ -556,12 +556,12 @@ const Rbutr = () => {
var rbutr = Rbutr();


document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', () => {

rbutr.initialize();


browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {

'use strict';

Expand Down Expand Up @@ -606,7 +606,7 @@ document.addEventListener('DOMContentLoaded', function () {


// tab is going away, remove the canonical data for it
browser.tabs.onRemoved.addListener(function (tabId) {
browser.tabs.onRemoved.addListener((tabId) => {

'use strict';

Expand All @@ -619,7 +619,7 @@ document.addEventListener('DOMContentLoaded', function () {
/**
* @description Fires when a tab is updated
*/
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {

'use strict';

Expand Down
30 changes: 15 additions & 15 deletions src/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const platforms = {
filter: []
},
externalLinkPattern: null,
cleanurl: function (url) {
cleanurl: (url) => {
'use strict';
return url;
}
Expand All @@ -57,7 +57,7 @@ const platforms = {
filter: [{ element: 'div' }]
},
externalLinkPattern: new RegExp(/^https?:\/\/l\.facebook\.com\/l\.php\?u=([^&]+)/),
cleanurl: function (dirtyUrl) {
cleanurl: (dirtyUrl) => {

'use strict';

Expand Down Expand Up @@ -399,7 +399,7 @@ const Content = () => {
version: content.version,
cid: content.cid,
json: true
}, 'json').done( function (data) {
}, 'json').done((data) => {
callback(data, url, $element);
});
};
Expand Down Expand Up @@ -427,7 +427,7 @@ const Content = () => {
parentSelector = itemSelectors[index].parent,
bodySelector = itemSelectors[index].body;

$(parentSelector + ' ' + bodySelector + ':not([data-rbutr-processed]) a').each(function () {
$(parentSelector + ' ' + bodySelector + ':not([data-rbutr-processed]) a').each(() => {
// exclude links that have the same hostname
if (ownHostRegExp.test(this.href) === false) {
$linkWrapper = $(this).closest(bodySelector);
Expand All @@ -439,7 +439,7 @@ const Content = () => {
expandedUrl = platform.expandExternalLinks($currentLink);

if(expandedUrl) {
content.getRbutrData(expandedUrl, $linkWrapper, function (result, url, $element) {
content.getRbutrData(expandedUrl, $linkWrapper, (result, url, $element) => {
messageTemplate = content.createMessageTemplate(result, url);
$element.after($('<div class="rbutr-message-container"></div>').html(messageTemplate));
});
Expand Down Expand Up @@ -476,7 +476,7 @@ const Content = () => {
};


mutationObserver = new MutationObserver(function(mutations, thisInstance) {
mutationObserver = new MutationObserver((mutations, thisInstance) => {
let result = content.setAlertOnPosts();
if(result === true) {
thisInstance.disconnect();
Expand Down Expand Up @@ -513,22 +513,22 @@ const Content = () => {

const content = Content();

document.onreadystatechange = function () {
document.onreadystatechange = () => {

'use strict';

if (document.readyState === 'complete') {

browser.runtime.sendMessage({'action': 'getCid'}, function (response) {
browser.runtime.sendMessage({'action': 'getCid'}, (response) => {
content.cid = response;
});
browser.runtime.sendMessage({'action': 'getServerUrl'}, function (response) {
browser.runtime.sendMessage({'action': 'getServerUrl'}, (response) => {
content.serverUrl = response;
});
browser.runtime.sendMessage({'action': 'getServerDomain'}, function (response) {
browser.runtime.sendMessage({'action': 'getServerDomain'}, (response) => {
content.serverDomain = response;
});
browser.runtime.sendMessage({'action': 'getVersion'}, function (response) {
browser.runtime.sendMessage({'action': 'getVersion'}, (response) => {
content.version = response;
});
browser.runtime.sendMessage({'action': 'setCanonical', 'url': content.canonicalValue || location.href, 'title': content.title});
Expand All @@ -538,7 +538,7 @@ document.onreadystatechange = function () {
/**
* @description Handle requests from background script
*/
browser.runtime.onMessage.addListener(function (request) {
browser.runtime.onMessage.addListener((request) => {

const TIMEOUT_HIDE_FLOATER = 5000;

Expand All @@ -562,11 +562,11 @@ document.onreadystatechange = function () {
</div>`
);

window.setTimeout(function () {
window.setTimeout(() => {
$('#rbutrfloatdiv').remove();
}, TIMEOUT_HIDE_FLOATER);

$('#dontShowAgain').click(function () {
$('#dontShowAgain').click(() => {
localStorage.setItem('rbutr.dontshow.' + request.url, $('#dontShowAgain')[FIRST_ARRAY_ELEMENT].checked);
});
}
Expand All @@ -585,7 +585,7 @@ document.onreadystatechange = function () {


$('body').append('<div id="rbutr-installed"></div>');
$('.rbutr-message .more').click(function () {
$('.rbutr-message .more').click(() => {
$('.rbutr-message .details').toggleClass('hidden');
});
content.execute();
Expand Down
2 changes: 1 addition & 1 deletion src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let tabId;
/**
* @description Multi-Browser support
*/
window.browser = (function () {
window.browser = (() => {

'use strict';

Expand Down

0 comments on commit 93ac9b9

Please sign in to comment.