Skip to content

Commit

Permalink
Adding semicolons to match SERP
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanKingston committed Feb 15, 2021
1 parent a54a0cc commit a02b0fe
Show file tree
Hide file tree
Showing 20 changed files with 1,121 additions and 1,120 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "standard",
"rules": {
"indent": ["error", 4]
"indent": ["error", 4],
"semi": ["error", "always"]
},
"env": {
"browser": true
Expand Down
112 changes: 56 additions & 56 deletions TEMPLATES/complex/main.js
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
const startButton = document.querySelector('#start')
const downloadButton = document.querySelector('#download')
const startButton = document.querySelector('#start');
const downloadButton = document.querySelector('#download');

const testsDiv = document.querySelector('#tests')
const testsSummaryDiv = document.querySelector('#tests-summary')
const testsDetailsDiv = document.querySelector('#tests-details')
const testsDiv = document.querySelector('#tests');
const testsSummaryDiv = document.querySelector('#tests-summary');
const testsDetailsDiv = document.querySelector('#tests-details');

const tests = [
{
id: 'test-test',
run: () => {
// function returning either a value or a promise
let res
const promise = new Promise((resolve, reject) => { res = resolve })
let res;
const promise = new Promise((resolve, reject) => { res = resolve; });

setTimeout(() => res('ok'), 1000)
setTimeout(() => res('ok'), 1000);

return promise
return promise;
}
}
]
];

// object that contains results of all tests
const results = {
page: 'name-of-the-test', // FILL ME OUT!
date: null,
results: []
}
};

function resultToHTML (data) {
if (Array.isArray(data)) {
return `<ul>${data.map(r => `<li>${r.test} - ${r.result}</li>`).join('')}</ul>`
return `<ul>${data.map(r => `<li>${r.test} - ${r.result}</li>`).join('')}</ul>`;
} else if (data) {
return JSON.stringify(data, null, 2)
return JSON.stringify(data, null, 2);
}

return null
return null;
}

/**
* Test runner
*/
function runTests () {
startButton.setAttribute('disabled', 'disabled')
downloadButton.removeAttribute('disabled')
testsDiv.removeAttribute('hidden')
startButton.setAttribute('disabled', 'disabled');
downloadButton.removeAttribute('disabled');
testsDiv.removeAttribute('hidden');

results.results.length = 0
results.date = (new Date()).toUTCString()
let all = 0
let failed = 0
results.results.length = 0;
results.date = (new Date()).toUTCString();
let all = 0;
let failed = 0;

testsDetailsDiv.innerHTML = ''
testsDetailsDiv.innerHTML = '';

function updateSummary () {
testsSummaryDiv.innerText = `Performed ${all} tests${failed > 0 ? ` (${failed} failed)` : ''}. Click for details.`
testsSummaryDiv.innerText = `Performed ${all} tests${failed > 0 ? ` (${failed} failed)` : ''}. Click for details.`;
}

for (const test of tests) {
const resultObj = {
id: test.id,
value: null
}
results.results.push(resultObj)
};
results.results.push(resultObj);

const li = document.createElement('li')
li.id = `test-${test.id.replace(' ', '-')}`
li.innerHTML = `${test.id} - <span class='value'>…</span>`
const valueSpan = li.querySelector('.value')
const li = document.createElement('li');
li.id = `test-${test.id.replace(' ', '-')}`;
li.innerHTML = `${test.id} - <span class='value'>…</span>`;
const valueSpan = li.querySelector('.value');

testsDetailsDiv.appendChild(li)
testsDetailsDiv.appendChild(li);

try {
const result = test.run()
const result = test.run();

if (result instanceof Promise) {
result
.then(data => {
valueSpan.innerHTML = resultToHTML(data)
resultObj.value = data || null
valueSpan.innerHTML = resultToHTML(data);
resultObj.value = data || null;
})
.catch(e => {
failed++
valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`
updateSummary()
})
failed++;
valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`;
updateSummary();
});
} else {
valueSpan.innerHTML = resultToHTML(data)
resultObj.value = result || null
valueSpan.innerHTML = resultToHTML(data);
resultObj.value = result || null;
}
} catch (e) {
failed++
valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`
failed++;
valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`;
}

all++
all++;
}

updateSummary()
updateSummary();

startButton.removeAttribute('disabled')
startButton.removeAttribute('disabled');
}

function downloadTheResults () {
const data = JSON.stringify(results, null, 2)
const a = document.createElement('a')
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/json' }))
a.href = url
a.download = 'fingerprinting-results.json'
const data = JSON.stringify(results, null, 2);
const a = document.createElement('a');
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/json' }));
a.href = url;
a.download = 'fingerprinting-results.json';

document.body.appendChild(a)
a.click()
document.body.appendChild(a);
a.click();

window.URL.revokeObjectURL(url)
a.remove()
window.URL.revokeObjectURL(url);
a.remove();
}

downloadButton.addEventListener('click', () => downloadTheResults())
downloadButton.addEventListener('click', () => downloadTheResults());

// run tests if button was clicked or…
startButton.addEventListener('click', () => runTests())
startButton.addEventListener('click', () => runTests());

// if url query is '?run'
if (document.location.search === '?run') {
runTests()
runTests();
}
26 changes: 13 additions & 13 deletions features/stack-tracing/script.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/* globals log */

(() => {
const base = new URL(document.currentScript.src)
const party = base.origin === window.top.location.origin ? 'first' : 'third'
const scriptName = `${party} party script`
const base = new URL(document.currentScript.src);
const party = base.origin === window.top.location.origin ? 'first' : 'third';
const scriptName = `${party} party script`;

log(scriptName, new Error().stack)
log(scriptName, new Error().stack);

const worker = new Worker('./worker.js')
const worker = new Worker('./worker.js');
worker.addEventListener('message', msg => {
const { source, stackValue } = msg.data
log(`${scriptName} loading ${source}`, stackValue)
})
worker.postMessage({ action: 'setup' })
const { source, stackValue } = msg.data;
log(`${scriptName} loading ${source}`, stackValue);
});
worker.postMessage({ action: 'setup' });

setTimeout(() => {
log(`${scriptName} setTimeout`, new Error().stack)
}, 0)
log(`${scriptName} setTimeout`, new Error().stack);
}, 0);

document.write(`<script>log('${scriptName} write', new Error().stack);</script>`)
})()
document.write(`<script>log('${scriptName} write', new Error().stack);</script>`);
})();
12 changes: 6 additions & 6 deletions features/stack-tracing/worker.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function log (source, stackValue) {
postMessage({ source, stackValue })
postMessage({ source, stackValue });
}

self.addEventListener('message', msg => {
if (msg.data.action && msg.data.action === 'setup') {
setup()
setup();
}
})
});

function setup () {
log('worker', new Error().stack)
log('worker', new Error().stack);

setTimeout(() => {
log('worker setTimeout', new Error().stack)
}, 0)
log('worker setTimeout', new Error().stack);
}, 0);
}
6 changes: 3 additions & 3 deletions privacy-protections/fingerprinting/helpers/constants.js

Large diffs are not rendered by default.

Loading

0 comments on commit a02b0fe

Please sign in to comment.