Skip to content

Commit

Permalink
Improve demo extension
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Nov 8, 2024
1 parent 321aa4d commit 4033fd3
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,25 @@ import './init/context-menu.js';
import './init/devtools-tab.js';
import './init/offscreen.js';

const table = Object.entries(detect)
.filter(([key, exported]) => typeof exported === 'function' && key !== 'disableWebextDetectPageCache')
const results = Object.entries(detect)
.filter(([key, exported]) => typeof exported === 'function' && key !== 'disableWebextDetectPageCache' && key !== 'getContextName')
.map(([key, detection]) => [key, detection()])
.sort(([keyA, resultA], [keyB, resultB]) => {
if (resultA === resultB) {
return keyA.localeCompare(keyB);
}
.sort(([, a], [, b]) => a === b ? 0 : (a ? -1 : 1))
.map(([key, result]) => result === true ? `✅ ${key}` : (result === false ? `❌ ${key}` : `${key}(): ${result}`));

return resultA === true ? -1 : 1;
});
console.group(`contextName: ${detect.getContextName()}`);
for (const result of results) {
console.log(result);
}

console.table(table);
console.groupEnd();

if ('document' in globalThis) {
globalThis.document.body.insertAdjacentHTML('beforeend', `
<fieldset>
<legend>${detect.getContextName()}</legend>
<legend>contextName: ${detect.getContextName()}</legend>
<ul>
${table.map(([key, result]) => `
<li>
<span>
${result === true ? '✅' : (result === false ? '❌' : '')}
${key}
${typeof result === 'string' ? `: ${result}` : ''}
</span>
</li>
`).join('')}
${results.map(result => `<li>${result}</li>`).join('')}
</ul>
</fieldset>
`);
Expand Down

0 comments on commit 4033fd3

Please sign in to comment.