Skip to content

Commit

Permalink
Add crypto extension
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Sep 13, 2024
1 parent 562e413 commit bf3fa9b
Show file tree
Hide file tree
Showing 18 changed files with 898 additions and 144 deletions.
33 changes: 33 additions & 0 deletions e2e/new-crypto.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import path from 'path'
import {execSync} from 'child_process'
import {extensionFixtures} from './extension-fixtures'

const exampleDir = 'examples/new-typescript'
const pathToExtension = path.join(__dirname, `../${exampleDir}/dist/chrome`)
const test = extensionFixtures(pathToExtension, true)

test.beforeAll(async () => {
execSync(`pnpm extension build ${exampleDir}`, {
cwd: path.join(__dirname, '..')
})
})

test('should exist an element with the welcome message text', async ({
page
}) => {
await page.goto('chrome://newtab/')
const h1 = page.locator('h1')
await test.expect(h1).toHaveText('Welcome to your Crypto Extension.')
})

test('should exist a default color value', async ({page}) => {
await page.goto('chrome://newtab/')
const h1 = page.locator('h1')
const color = await page.evaluate(
(locator) => {
return window.getComputedStyle(locator!).getPropertyValue('color')
},
await h1.elementHandle()
)
await test.expect(color).toEqual('rgb(74, 74, 74)')
})
2 changes: 1 addition & 1 deletion examples/content-react-svgr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"@types/react-dom": "^18.0.5",
"typescript": "5.3.3"
}
}
}
9 changes: 9 additions & 0 deletions examples/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ const TS_TEMPLATES: Template[] = [
hasBackground: false,
hasEnv: false,
configFiles: ['tsconfig.json']
},
{
name: 'new-crypto',
uiContext: ['newTab'],
uiFramework: undefined,
css: 'css',
hasBackground: false,
hasEnv: false,
configFiles: ['tsconfig.json', 'extension.config.js']
}
]

Expand Down
31 changes: 31 additions & 0 deletions examples/new-crypto/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
dist

# misc
.DS_Store

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# lock files
yarn.lock
package-lock.json

# debug files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# extension.js
extension-env.d.ts
15 changes: 15 additions & 0 deletions examples/new-crypto/extension.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')

/** @type {import('extension-develop').FileConfig} */
module.exports = {
config: (config) => {
config.plugins = [
...config.plugins,
new NodePolyfillPlugin({
additionalAliases: ['process']
})
]

return config
}
}
Binary file added examples/new-crypto/images/extension_128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/new-crypto/images/extension_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/new-crypto/images/extension_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/new-crypto/images/typescript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions examples/new-crypto/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"manifest_version": 3,
"version": "0.0.1",
"name": "Newtab Crypto Template",
"description": "An Extension.js example.",
"icons": {
"16": "images/extension_16.png",
"48": "images/extension_48.png",
"128": "images/extension_128.png"
},
"chrome_url_overrides": {
"newtab": "newtab/index.html"
}
}
36 changes: 36 additions & 0 deletions examples/new-crypto/newtab/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>TypeScript Extension</title>
<link rel="stylesheet" href="https://unpkg.com/sakura.css/css/sakura.css" media="screen" />
<link rel="stylesheet" href="https://unpkg.com/sakura.css/css/sakura-dark.css" media="screen and (prefers-color-scheme: dark)" />
<link rel="stylesheet" href="./styles.css" media="screen" />
</head>
<body>
<header>
<h1>
<img class="crypto" src="../public/logo.svg" alt="The Crypto Template logo" width="120px" />
<br />
Welcome to your Crypto Extension.
</h1>
<article>
<label for="input-text">Enter a string to hash:</label>
<div class="hash-form">
<input type="text" id="input-text" placeholder="Type something...">
<button id="hash-button">Hash It!</button>
</div>
<p>Hashed Output (SHA-256):</p>
<pre id="hashed-output">Hash a string to see the result</pre>
</article>
<footer>
Learn more about creating cross-browser extensions at
<a href="https://extension.js.org" target="_blank">https://extension.js.org</a>.
</footer>
</header>
</body>
<script src="./scripts.ts"></script>
</html>


17 changes: 17 additions & 0 deletions examples/new-crypto/newtab/scripts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as crypto from 'crypto'

function hashString(input: string): string {
// Hash the input using SHA-256
return crypto.createHash('sha256').update(input).digest('hex')
}

document.getElementById('hash-button')?.addEventListener('click', () => {
const inputText = (document.getElementById('input-text') as HTMLInputElement)
.value
const hashedOutput = hashString(inputText)

const outputElement = document.getElementById('hashed-output')
if (outputElement) {
outputElement.textContent = hashedOutput
}
})
30 changes: 30 additions & 0 deletions examples/new-crypto/newtab/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
body {
display: flex;
justify-content: center;
align-items: center;
height: calc(100vh - 26px);
}

h1 {
font-size: 3.7em;
}

.crypto {
transition: all 400ms cubic-bezier(.47,1.64,.41,.8);
}

.crypto:hover {
transform: scale(1.5);
}

input {
width: 100%;
height: 100%;
}

.hash-form {
display: grid;
grid-template-columns: 1fr auto;
gap: 2rem;
margin-bottom: 2rem;
}
16 changes: 16 additions & 0 deletions examples/new-crypto/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"private": true,
"name": "new-crypto",
"description": "An Extension.js example.",
"version": "0.0.1",
"author": {
"name": "Cezar Augusto",
"email": "boss@cezaraugusto.net",
"url": "https://cezaraugusto.com"
},
"license": "MIT",
"devDependencies": {
"node-polyfill-webpack-plugin": "^4.0.0",
"typescript": "5.3.3"
}
}
7 changes: 7 additions & 0 deletions examples/new-crypto/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions examples/new-crypto/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"moduleResolution": "node",
"module": "esnext",
"noEmit": true,
"resolveJsonModule": true,
"strict": true,
"target": "esnext",
"verbatimModuleSyntax": true,
"useDefineForClassFields": true,
"skipLibCheck": true
},
"include": ["./"],
"exclude": ["node_modules", "dist"]
}
Loading

0 comments on commit bf3fa9b

Please sign in to comment.