Skip to content

Commit a6240ec

Browse files
committed
I can't take it anymore; lines should end in semicolons
1 parent 8e0dc6b commit a6240ec

10 files changed

+133
-109
lines changed

.eslintrc.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es6": true
5+
},
6+
"extends": "eslint:recommended",
7+
"parserOptions": {
8+
"ecmaVersion": 2018
9+
},
10+
"rules": {
11+
"indent": [
12+
"error",
13+
2
14+
],
15+
"quotes": [
16+
"error",
17+
"single"
18+
],
19+
"semi": [
20+
"error",
21+
"always"
22+
]
23+
}
24+
}

src/_utils.js

+37-37
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,34 @@
2929
* @returns {MutationObserver} Returns the observer used in case you want to disconnect it.
3030
*/
3131
function jscss (selector, props) { // eslint-disable-line no-unused-vars
32-
const body = document.getRootNode().body
32+
const body = document.getRootNode().body;
3333

34-
let matchCache = body.querySelectorAll(selector)
34+
let matchCache = body.querySelectorAll(selector);
3535
matchCache.forEach((elem) => {
36-
applyStyle(elem, props)
37-
})
36+
applyStyle(elem, props);
37+
});
3838

3939
const observer = new MutationObserver(() => {
40-
const matches = body.querySelectorAll(selector)
40+
const matches = body.querySelectorAll(selector);
4141

4242
// Exit early if there are no new items. Also works for the empty case.
4343
if (matchCache.length === matches.length) {
44-
let different = false
44+
let different = false;
4545
for (let k = 0; k < matches.length; k++) {
46-
different = matches[k] !== matchCache[k]
47-
if (different) { break }
46+
different = matches[k] !== matchCache[k];
47+
if (different) { break; }
4848
}
49-
if (!different) { return }
49+
if (!different) { return; }
5050
}
5151

5252
// MutationObservers can trigger themselves recursively so we want to
5353
// update matchCache now, before we possibly modify elements further.
54-
const oldMatches = matchCache
55-
matchCache = matches
54+
const oldMatches = matchCache;
55+
matchCache = matches;
5656

57-
let i
58-
let j
59-
let seen
57+
let i;
58+
let j;
59+
let seen;
6060

6161
/**
6262
* Apply styles to newly ADDED elements.
@@ -65,35 +65,35 @@ function jscss (selector, props) { // eslint-disable-line no-unused-vars
6565
* possible cuz there's no duplicate items.
6666
*/
6767
for (i = 0; i < matches.length; i++) {
68-
seen = false
68+
seen = false;
6969
for (j = 0; j < oldMatches.length; j++) {
70-
seen = matches[i] === oldMatches[j]
71-
if (seen) { break }
70+
seen = matches[i] === oldMatches[j];
71+
if (seen) { break; }
7272
}
73-
if (seen) { continue }
73+
if (seen) { continue; }
7474
// From this point forward matches[i] is known to be newly ADDED.
75-
applyStyle(matches[i], props)
75+
applyStyle(matches[i], props);
7676

7777
// As an optimization, jscss can be requested to apply only once.
7878
if (props.firstResultOnly) {
79-
observer.disconnect()
79+
observer.disconnect();
8080
}
8181
}
8282

8383
/**
8484
* Apply styles to newly REMOVED elements.
8585
*/
8686
for (j = 0; j < oldMatches.length; j++) {
87-
seen = false
87+
seen = false;
8888
for (i = 0; i < matches.length; i++) {
89-
seen = oldMatches[j] === matches[i]
90-
if (seen) { break }
89+
seen = oldMatches[j] === matches[i];
90+
if (seen) { break; }
9191
}
92-
if (seen) { continue }
92+
if (seen) { continue; }
9393
// From this point forward oldMatches[i] is known to be newly REMOVED.
94-
removeStyle(oldMatches[j], props)
94+
removeStyle(oldMatches[j], props);
9595
}
96-
})
96+
});
9797

9898
observer.observe(body, {
9999
subtree: true,
@@ -102,15 +102,15 @@ function jscss (selector, props) { // eslint-disable-line no-unused-vars
102102
// Technically any attribute can cause a change worth observing since css
103103
// has attribute selectors. No need atm though, so let's be performant.
104104
attributeFilter: ['id', 'class']
105-
})
105+
});
106106

107-
return observer
107+
return observer;
108108
}
109109

110110
function applyStyle (elem, props) {
111111
// Search/replace text support
112112
if ('search' in props && 'replace' in props) {
113-
addTextObserver(elem, props)
113+
addTextObserver(elem, props);
114114
}
115115
}
116116

@@ -122,22 +122,22 @@ function removeStyle (elem, props) {
122122
}
123123

124124
function addTextObserver (elem, props) {
125-
searchAndReplaceChildren(elem, props)
125+
searchAndReplaceChildren(elem, props);
126126

127-
const observer = new MutationObserver(() => searchAndReplaceChildren(elem, props))
127+
const observer = new MutationObserver(() => searchAndReplaceChildren(elem, props));
128128
observer.observe(elem, {
129129
childList: true,
130130
characterData: true
131-
})
131+
});
132132
}
133133

134134
function searchAndReplaceChildren (elem, props) {
135135
elem.childNodes.forEach((child) => {
136-
if (child.nodeType !== Node.TEXT_NODE) { return }
137-
const newStr = child.textContent.replace(props.search, props.replace)
136+
if (child.nodeType !== Node.TEXT_NODE) { return; }
137+
const newStr = child.textContent.replace(props.search, props.replace);
138138
// Only assign if the value would actually change, since blindly
139139
// assigning could cause another mutation to be observed.
140-
if (child.textContent === newStr) { return }
141-
child.textContent = newStr
142-
})
140+
if (child.textContent === newStr) { return; }
141+
child.textContent = newStr;
142+
});
143143
}

src/background.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const GLOBAL_SCRIPTS = [
44
'src/_utils.js'
5-
]
5+
];
66

77
const CONTENT_SCRIPTS = [
88
{
@@ -77,42 +77,42 @@ const CONTENT_SCRIPTS = [
7777
'remove-view-count.js'
7878
]
7979
}
80-
]
80+
];
8181

82-
let isEnabled = true
82+
let isEnabled = true;
8383
let registeredContentScripts = []
8484

8585
;(function main () {
86-
updateIcon()
87-
updateContentScripts()
88-
})()
86+
updateIcon();
87+
updateContentScripts();
88+
})();
8989

9090
browser.browserAction.onClicked.addListener(() => {
91-
isEnabled = !isEnabled
92-
updateIcon()
93-
updateContentScripts()
94-
browser.tabs.reload()
95-
})
91+
isEnabled = !isEnabled;
92+
updateIcon();
93+
updateContentScripts();
94+
browser.tabs.reload();
95+
});
9696

9797
function updateIcon () {
9898
browser.browserAction.setTitle({
9999
title: `Disengaged (${isEnabled ? 'on' : 'off'})`
100-
})
100+
});
101101

102102
// Mobile Firefox doesn't support setIcon
103-
if (!browser.browserAction.setIcon) { return }
103+
if (!browser.browserAction.setIcon) { return; }
104104
browser.browserAction.setIcon({
105105
path: isEnabled ? 'icons/icon_48_on.png' : 'icons/icon_48_off.png'
106-
})
106+
});
107107
}
108108

109109
function updateContentScripts () {
110-
isEnabled ? registerContentScripts() : unregisterContentScripts()
110+
isEnabled ? registerContentScripts() : unregisterContentScripts();
111111
}
112112

113113
function unregisterContentScripts () {
114-
registeredContentScripts.forEach(rcs => rcs.unregister())
115-
registeredContentScripts = []
114+
registeredContentScripts.forEach(rcs => rcs.unregister());
115+
registeredContentScripts = [];
116116
}
117117

118118
async function registerContentScripts () {
@@ -123,16 +123,16 @@ async function registerContentScripts () {
123123
allFrames: !!contentScript.allFrames,
124124
css: contentScript.files
125125
.filter(file => file.match(/.*\.css$/))
126-
.map((file) => { return { file: `${contentScript.folder}/${file}` } }),
126+
.map((file) => { return { file: `${contentScript.folder}/${file}` }; }),
127127
js: [].concat(
128128
GLOBAL_SCRIPTS
129-
.map((file) => { return { file } }),
129+
.map((file) => { return { file }; }),
130130
contentScript.files
131131
.filter(file => file.match(/.*\.js$/))
132-
.map((file) => { return { file: `${contentScript.folder}/${file}` } })
132+
.map((file) => { return { file: `${contentScript.folder}/${file}` }; })
133133
)
134134
}).then((rcs) => {
135-
registeredContentScripts.push(rcs)
136-
})
137-
})
135+
registeredContentScripts.push(rcs);
136+
});
137+
});
138138
}

src/hacker-news/collapse-deep-comments.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,34 @@ const COMMENT_COLLAPSE_DEPTH = 1;
1414
* @type {Number} depth
1515
*/
1616
(function collapseDeepComments (depth) {
17-
let indentWidth
17+
let indentWidth;
1818

1919
document.querySelectorAll('tr.athing.comtr').forEach((comment) => {
2020
// already collapsed? nothing to do
21-
if (comment.classList.contains('coll')) return
21+
if (comment.classList.contains('coll')) return;
2222

2323
// measure the indentation element to see how nested we are
24-
const indent = comment.querySelector('td.ind img')
24+
const indent = comment.querySelector('td.ind img');
2525
if (!indentWidth && indent.width) {
2626
// varies by platform; 40px on desktop and 12px on mobile
27-
indentWidth = indent.width
27+
indentWidth = indent.width;
2828
}
2929
// convert depth to indentation
30-
const targetWidth = indentWidth * depth
30+
const targetWidth = indentWidth * depth;
3131

3232
// rule out anything not indented deeply enough
33-
if (!indent.width || indent.width < targetWidth) return
33+
if (!indent.width || indent.width < targetWidth) return;
3434

3535
// set all of hn's classes for the collapsed comment
36-
comment.classList.add('coll')
37-
const toggle = comment.querySelector('.togg')
38-
toggle.textContent = `[+${toggle.getAttribute('n')}]`
39-
comment.querySelector('.comment').classList.add('noshow')
40-
comment.querySelector('.votelinks').classList.add('nosee')
36+
comment.classList.add('coll');
37+
const toggle = comment.querySelector('.togg');
38+
toggle.textContent = `[+${toggle.getAttribute('n')}]`;
39+
comment.querySelector('.comment').classList.add('noshow');
40+
comment.querySelector('.votelinks').classList.add('nosee');
4141

4242
// sub comments are additionally hidden with noshow
4343
if (indent.width > targetWidth) {
44-
comment.classList.add('noshow')
44+
comment.classList.add('noshow');
4545
}
46-
})
47-
})(COMMENT_COLLAPSE_DEPTH)
46+
});
47+
})(COMMENT_COLLAPSE_DEPTH);

src/hacker-news/collapse-low-quality-comments.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
(function collapseLowQualityComments () {
66
document.querySelectorAll('tr.athing.comtr').forEach((comment) => {
77
// already collapsed? nothing to do
8-
if (comment.classList.contains('coll')) return
8+
if (comment.classList.contains('coll')) return;
99

10-
const fadedSpan = comment.querySelector('div.comment > span:not(.c00)')
10+
const fadedSpan = comment.querySelector('div.comment > span:not(.c00)');
1111

12-
const div = comment.querySelector('div.comment')
13-
const flagged = div.textContent.trim() === '[flagged]'
12+
const div = comment.querySelector('div.comment');
13+
const flagged = div.textContent.trim() === '[flagged]';
1414

1515
if (fadedSpan || flagged) {
1616
// set all of hn's classes for the collapsed comment
17-
comment.classList.add('coll')
18-
const toggle = comment.querySelector('.togg')
19-
toggle.textContent = `[+${toggle.getAttribute('n')}]`
20-
comment.querySelector('.comment').classList.add('noshow')
21-
comment.querySelector('.votelinks').classList.add('nosee')
17+
comment.classList.add('coll');
18+
const toggle = comment.querySelector('.togg');
19+
toggle.textContent = `[+${toggle.getAttribute('n')}]`;
20+
comment.querySelector('.comment').classList.add('noshow');
21+
comment.querySelector('.votelinks').classList.add('nosee');
2222
}
23-
})
24-
})()
23+
});
24+
})();

src/hacker-news/remove-self-karma.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
search: /\(\d+\)\s/,
1010
replace: '',
1111
firstResultOnly: true
12-
})
13-
})()
12+
});
13+
})();

src/youtube-music/remove-view-count.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
search: /^\s\s|[\d.]+[KMB]*\sviews$/,
1111
replace: '',
1212
firstResultOnly: true
13-
})
14-
})()
13+
});
14+
})();

0 commit comments

Comments
 (0)