diff --git a/assets/.eslintrc.json b/assets/.eslintrc.json index f3829a49..089dced4 100644 --- a/assets/.eslintrc.json +++ b/assets/.eslintrc.json @@ -2,18 +2,22 @@ "root": true, "extends": "eslint-config-airbnb-base/legacy", "rules": { - "camelcase": "off", + "camelcase": [ + "error", + { + "allow": [ + "^gcaptcha_" + ] + } + ], "consistent-return": "off", - "eqeqeq": "off", "func-names": "off", - "guard-for-in": "off", "max-len": "off", "no-bitwise": "off", "no-continue": "off", "no-multi-assign": "off", "no-param-reassign": "off", "no-plusplus": "off", - "no-prototype-builtins": "off", "no-restricted-syntax": "off", "no-shadow": "off", "no-use-before-define": "off", diff --git a/assets/badge.js b/assets/badge.js index 95d2321e..980f622b 100644 --- a/assets/badge.js +++ b/assets/badge.js @@ -56,9 +56,9 @@ parent.removeChild(script) // setup iframe RPC - iframe.onload = function () { + iframe.addEventListener('load', function () { setup(iframe) - } + }) } // setup an "RPC" channel between iframe and us @@ -75,8 +75,8 @@ // update width var wp = 'slackin-width:' + id + ':' - if (wp === e.data.substr(0, wp.length)) { - var width = e.data.substr(wp.length) + if (wp === e.data.slice(0, wp.length)) { + var width = e.data.slice(wp.length) iframe.style.width = width + 'px' // ensure it's shown (since first time hidden) @@ -85,8 +85,8 @@ // redirect to URL var redir = 'slackin-redirect:' + id + ':' - if (redir === e.data.substr(0, redir.length)) { - window.location.href = e.data.substr(redir.length) // lgtm [js/client-side-unvalidated-url-redirection] + if (redir === e.data.slice(0, redir.length)) { + window.location.href = e.data.slice(redir.length) // lgtm [js/client-side-unvalidated-url-redirection] } }) } @@ -133,12 +133,12 @@ ni.style.height = '15.5em' ni.style.borderWidth = 0 ni.src = iframe.src.replace('iframe', 'iframe/dialog') - ni.onload = function () { + ni.addEventListener('load', function () { setup(ni) window.addEventListener('scroll', dposition) window.addEventListener('resize', dposition) position() - } + }) // arrows var a1 = document.createElement('div') @@ -235,7 +235,7 @@ } function click(ev) { - if (ev.target.className != '__slackin') { + if (ev.target.className !== '__slackin') { hide() } } diff --git a/assets/client.js b/assets/client.js index 4ec5ad0d..45848726 100644 --- a/assets/client.js +++ b/assets/client.js @@ -70,14 +70,18 @@ url.href = window.location // realtime updates var socket = io({ path: data.path + 'socket.io' }) socket.on('data', function (users) { - for (var i in users) update(i, users[i]) + for (var i in users) { + if (Object.prototype.hasOwnProperty.call(users, i)) { + update(i, users[i]) + } + } }) socket.on('total', function (n) { update('total', n) }) socket.on('active', function (n) { update('active', n) }) function update(val, n) { var el = document.querySelector('.' + val) - if (el && el.textContent != n) { + if (el && el.textContent !== n) { el.textContent = n anim(el, val) } @@ -112,8 +116,8 @@ window.addEventListener('message', function onmsg(e) { } }) -body.onload = function () { +body.addEventListener('load', function () { if (window.location.hash) { body.querySelector('select[name=channel]').value = window.location.hash.slice(1) } -} +}) diff --git a/assets/iframe.js b/assets/iframe.js index 144ac2ff..58f2492c 100644 --- a/assets/iframe.js +++ b/assets/iframe.js @@ -19,7 +19,7 @@ id = e.data.replace(/^slackin:/, '') document.body.addEventListener('click', function (ev) { var el = ev.target - while (el && el.nodeName != 'A') el = el.parentNode + while (el && el.nodeName !== 'A') el = el.parentNode if (el && el.target === '_blank') { ev.preventDefault() window.parent.postMessage('slackin-click:' + id, '*') @@ -36,7 +36,7 @@ var button = document.querySelector('.slack-button') var lastWidth function refresh() { - if (window != window.top && window.postMessage) { + if (window !== window.top && window.postMessage) { var width = Math.ceil(button.getBoundingClientRect().width) if (lastWidth !== width) { lastWidth = width @@ -48,7 +48,7 @@ // initialize realtime events asynchronously var script = document.createElement('script') script.src = 'https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.4/socket.io.slim.min.js' - script.onload = function () { + script.addEventListener('load', function () { // use dom element for better cross browser compatibility var url = document.createElement('a') url.href = window.location @@ -56,14 +56,18 @@ var count = document.querySelector('.slack-count') socket.on('data', function (users) { - for (var i in users) update(i, users[i]) + for (var i in users) { + if (Object.prototype.hasOwnProperty.call(users, i)) { + update(i, users[i]) + } + } }) socket.on('total', function (n) { update('total', n) }) socket.on('active', function (n) { update('active', n) }) var anim function update(key, n) { - if (data[key] != n) { + if (data[key] !== n) { data[key] = n var str = '' if (data.active) str = data.active + '/' @@ -78,6 +82,6 @@ refresh() } } - } + }) document.body.appendChild(script) }()) diff --git a/lib/index.js b/lib/index.js index 136c155c..91c882b5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -64,7 +64,7 @@ function slackin({ let channelsFiltered; if (channels) { channelsFiltered = channels.split(',').map((channel) => ( - channel.startsWith('#') ? channel.substr(1) : channel + channel.startsWith('#') ? channel.slice(1) : channel )); }