Skip to content

Commit

Permalink
single space indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
joshparkerj committed May 26, 2023
1 parent 476346c commit e2478fc
Show file tree
Hide file tree
Showing 114 changed files with 5,211 additions and 4,469 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
},
"rules": {
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-console": 0
"no-console": 0,
"max-statements-per-line": "error",
"indent": ["error", 1]
},
"plugins": [
"jest"
Expand Down
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ file-sizes
nightcafe/result*
nightcafe-result
nightcafe/*.csv
LOW.csv
TEVA.csv
nightcafe/creation-settings.user.js
nightcafe/cytoscape-graph-viz.user.js
nightcafe/js-drop-file.js
nightcafe/top-ten-log.html
wikipedia/bitbucket-pipeline-csv-download.user.js
wikipedia/result.csv
wikipedia/result.json
wikipedia/uncials.html
youtube/something.js
4 changes: 2 additions & 2 deletions basic-dynamic-static-example/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
document.querySelector('img').addEventListener('click', () => {
// eslint-disable-next-line no-alert
alert('You clicked the image!');
// eslint-disable-next-line no-alert
alert('You clicked the image!');
});
19 changes: 8 additions & 11 deletions basic-dynamic-static-example/hashing-algorithm-examples.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
const hashString = (s, maxCode = 65536) => (
[...s]
.reduce((acc, e, i) => (
((acc + (e.charCodeAt(0) * 31 ** i)) % maxCode) % maxCode
), 0)
[...s].reduce((acc, e, i) => ((acc * (e.charCodeAt(0) * 31 ** i)) % maxCode) % maxCode, 0)
);

const hash = (e, maxCode = 65536) => {
if (typeof e === 'string') {
return hashString(e, maxCode);
}
if (typeof e === 'string') {
return hashString(e, maxCode);
}

if (Number.isInteger(e)) {
return e % maxCode;
}
if (Number.isInteger(e)) {
return e % maxCode;
}

return undefined;
return undefined;
};

export default hash;
135 changes: 71 additions & 64 deletions basic-dynamic-static-example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,86 @@ const { readFile } = require('fs');
const months = require('./months.json');

const staticContentTypes = {
html: 'text/html',
css: 'text/css',
js: 'application/javascript',
png: 'image/png',
jpg: 'image/jpeg',
gif: 'image/gif',
svg: 'image/svg+xml',
ico: 'image/x-icon',
json: 'application/json',
txt: 'text/plain',
xml: 'application/xml',
pdf: 'application/pdf',
zip: 'application/zip',
mp3: 'audio/mpeg',
mp4: 'video/mp4',
wav: 'audio/wav',
woff: 'application/font-woff',
woff2: 'application/font-woff2',
ttf: 'application/font-ttf',
jpeg: 'image/jpeg',
html: 'text/html',
css: 'text/css',
js: 'application/javascript',
png: 'image/png',
jpg: 'image/jpeg',
gif: 'image/gif',
svg: 'image/svg+xml',
ico: 'image/x-icon',
json: 'application/json',
txt: 'text/plain',
xml: 'application/xml',
pdf: 'application/pdf',
zip: 'application/zip',
mp3: 'audio/mpeg',
mp4: 'video/mp4',
wav: 'audio/wav',
woff: 'application/font-woff',
woff2: 'application/font-woff2',
ttf: 'application/font-ttf',
jpeg: 'image/jpeg',
};

const staticExtensions = new Set(Object.keys(staticContentTypes));
const serverFiles = new Set(['/index.js', '/controller.js']);

http.createServer((req, res) => {
http
.createServer((req, res) => {
if (req.url === '/') {
readFile('./index.html', (err, data) => {
if (err) {
res.writeHead(500);
res.end(err.message);
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
}
});
readFile('./index.html', (err, data) => {
if (err) {
res.writeHead(500);
res.end(err.message);
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
}
});
} else if (serverFiles.has(req.url)) {
res.writeHead(400);
res.end('NO');
res.writeHead(400);
res.end('NO');
} else {
const filename = req.url.match(/\/(.*)$/);
const extension = filename && filename[1].match(/\.([^.]+)$/);
if (extension && staticExtensions.has(extension[1]) && filename && filename[1].match(/^[^./]+\.[^./]+$/)) {
readFile(`./${filename[1]}`, (err, data) => {
if (err) {
if (err.code === 'ENOENT') {
res.writeHead(404);
} else {
res.writeHead(500);
}
const filename = req.url.match(/\/(.*)$/);
const extension = filename && filename[1].match(/\.([^.]+)$/);
if (
extension
&& staticExtensions.has(extension[1])
&& filename
&& filename[1].match(/^[^./]+\.[^./]+$/)
) {
readFile(`./${filename[1]}`, (err, data) => {
if (err) {
if (err.code === 'ENOENT') {
res.writeHead(404);
} else {
res.writeHead(500);
}

res.end(err.message);
return;
}
res.end(err.message);
return;
}

const headers = {
'Content-Type': staticContentTypes[extension[1]],
};
const headers = {
'Content-Type': staticContentTypes[extension[1]],
};

res.writeHead(200, headers);
res.end(data);
});
} else if (req.url === '/time') {
const now = new Date();
res.writeHead(200);
res.end(`The time is ${now.getHours()}:${now.getMinutes()}`);
} else if (req.url === '/date') {
const now = new Date();
res.writeHead(200);
res.end(`The date is ${months[now.getMonth()]} ${now.getDate()}, ${now.getFullYear()}`);
} else {
res.writeHead(404);
res.end('404');
}
res.writeHead(200, headers);
res.end(data);
});
} else if (req.url === '/time') {
const now = new Date();
res.writeHead(200);
res.end(`The time is ${now.getHours()}:${now.getMinutes()}`);
} else if (req.url === '/date') {
const now = new Date();
res.writeHead(200);
res.end(`The date is ${months[now.getMonth()]} ${now.getDate()}, ${now.getFullYear()}`);
} else {
res.writeHead(404);
res.end('404');
}
}
}).listen(8080, () => console.log('server listening on port 8080'));
})
.listen(8080, () => console.log('server listening on port 8080'));
47 changes: 23 additions & 24 deletions bitbucket/execution-times.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,34 @@
// ==/UserScript==

(function testExecutionTimes() {
const parser = new DOMParser();
const parser = new DOMParser();

const nextSelector = 'button[aria-label=Next]';
const nextSelector = 'button[aria-label=Next]';

const pages = [document];
let { href } = window.location;
const pages = [document];
let { href } = window.location;

const getNext = function getNext(next) {
return new Promise((resolve, reject) => {
if (!next || next.disabled) {
resolve();
}
const getNext = function getNext(next) {
return new Promise((resolve, reject) => {
if (!next || next.disabled) {
resolve();
}

const match = href.match(/(.*)\/(\d+)$/);
const match = href.match(/(.*)\/(\d+)$/);

// eslint-disable-next-line no-unused-vars
const [_, url, page] = match;
href = `${url}${Number(page) + 1}`;
fetch(href)
.then((r) => r.text())
.then((text) => parser.parseFromString(text, 'text/html'))
.then((dom) => {
pages.push(dom);
resolve(dom.querySelector(nextSelector));
})
.catch(() => reject());
// eslint-disable-next-line no-unused-vars
const [_, url, page] = match;
href = `${url}${Number(page) + 1}`;
fetch(href)
.then((r) => r.text())
.then((text) => parser.parseFromString(text, 'text/html'))
.then((dom) => {
pages.push(dom);
resolve(dom.querySelector(nextSelector));
})
.then((n) => n && getNext(n));
};
.catch(() => reject());
}).then((n) => n && getNext(n));
};

getNext(document.querySelector(nextSelector));
getNext(document.querySelector(nextSelector));
}());
60 changes: 30 additions & 30 deletions britannica/three-column.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@
// ==/UserScript==

(function threeColumn() {
let containerGrid2;
let containerGrid3;
const addColumns = () => {
const container = document.querySelector('div.container');
if (containerGrid2) container.removeChild(containerGrid2);
if (containerGrid3) container.removeChild(containerGrid3);
container.removeChild(containerGrid3);
const containerGrid = document.querySelector('div.container > div.grid');
container.style.setProperty('display', 'grid');
container.style.setProperty('grid-template-columns', '1fr 1fr 1fr');
container.style.setProperty('width', '100%');
container.style.setProperty('max-width', 'unset');
container.style.setProperty('margin', '0');
container.style.setProperty('padding', '0');
containerGrid.style.setProperty('grid-column', 'span 1');
containerGrid2 = containerGrid.cloneNode(true);
containerGrid2.style.setProperty('position', 'relative');
containerGrid2.style.setProperty('top', '-100vh');
containerGrid3 = containerGrid.cloneNode(true);
containerGrid3.style.setProperty('position', 'relative');
containerGrid3.style.setProperty('top', '-200vh');
container.appendChild(containerGrid2);
container.appendChild(containerGrid3);
};
let containerGrid2;
let containerGrid3;
const addColumns = () => {
const container = document.querySelector('div.container');
if (containerGrid2) container.removeChild(containerGrid2);
if (containerGrid3) container.removeChild(containerGrid3);
container.removeChild(containerGrid3);
const containerGrid = document.querySelector('div.container > div.grid');
container.style.setProperty('display', 'grid');
container.style.setProperty('grid-template-columns', '1fr 1fr 1fr');
container.style.setProperty('width', '100%');
container.style.setProperty('max-width', 'unset');
container.style.setProperty('margin', '0');
container.style.setProperty('padding', '0');
containerGrid.style.setProperty('grid-column', 'span 1');
containerGrid2 = containerGrid.cloneNode(true);
containerGrid2.style.setProperty('position', 'relative');
containerGrid2.style.setProperty('top', '-100vh');
containerGrid3 = containerGrid.cloneNode(true);
containerGrid3.style.setProperty('position', 'relative');
containerGrid3.style.setProperty('top', '-200vh');
container.appendChild(containerGrid2);
container.appendChild(containerGrid3);
};

const mutationObserver = new MutationObserver(() => {
addColumns();
});

const ipc = document.querySelector('div.infinite-pagination-container');
mutationObserver.observe(ipc, { subtree: true, childList: true });
const mutationObserver = new MutationObserver(() => {
addColumns();
});

const ipc = document.querySelector('div.infinite-pagination-container');
mutationObserver.observe(ipc, { subtree: true, childList: true });
addColumns();
}());
Loading

0 comments on commit e2478fc

Please sign in to comment.