Skip to content

Commit

Permalink
feat(lit):out of box functions, countor \ newtab timer \ events
Browse files Browse the repository at this point in the history
  • Loading branch information
guocaoyi committed Oct 16, 2023
1 parent fb82175 commit d9339d2
Show file tree
Hide file tree
Showing 67 changed files with 711 additions and 527 deletions.
3 changes: 3 additions & 0 deletions template-lit-js/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["bierner.lit-html"]
}
14 changes: 14 additions & 0 deletions template-lit-js/devtools.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/icons/logo.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chrome Extension + Lit + JS + Vite</title>
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<devtools-root></devtools-root>
<script type="module" src="./src/devtools/index.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions template-lit-js/newtab.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/icons/logo.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chrome Extension + Lit + JS + Vite</title>
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<newtab-root></newtab-root>
<script type="module" src="./src/newtab/index.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions template-lit-js/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<meta charset="UTF-8" />
<link rel="icon" href="/icons/logo.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chrome Extension + Lit + JS + Vite App - Options</title>
<title>Chrome Extension + Lit + JS + Vite</title>
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<options-panel></options-panel>
<options-root></options-root>
<script type="module" src="./src/options/index.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions template-lit-js/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<meta charset="UTF-8" />
<link rel="icon" href="/icons/logo.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chrome Extension + Lit + JS + Vite App - Popup</title>
<title>Chrome Extension + Lit + JS + Vite</title>
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<popup-panel></popup-panel>
<popup-root></popup-root>
<script type="module" src="./src/popup/index.js"></script>
</body>
</html>
Binary file modified template-lit-js/public/icons/logo.ico
Binary file not shown.
3 changes: 1 addition & 2 deletions template-lit-js/public/icons/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified template-lit-js/public/img/logo-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 modified template-lit-js/public/img/logo-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 modified template-lit-js/public/img/logo-34.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 modified template-lit-js/public/img/logo-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions template-lit-js/sidepanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<meta charset="UTF-8" />
<link rel="icon" href="/icons/logo.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chrome Extension + Lit + JS + Vite App - Side Panel</title>
<title>Chrome Extension + Lit + JS + Vite</title>
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<side-panel></side-panel>
<sidepanel-root></sidepanel-root>
<script type="module" src="./src/sidepanel/index.js"></script>
</body>
</html>
8 changes: 6 additions & 2 deletions template-lit-js/src/background/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
console.info('chrome-ext template-li-js background script')
console.log('background is running')

export {}
chrome.runtime.onMessage.addListener((request) => {
if (request.type === 'COUNT') {
console.log('background has received a message from popup, and count is ', request?.count)
}
})
3 changes: 0 additions & 3 deletions template-lit-js/src/content/index.js

This file was deleted.

1 change: 1 addition & 0 deletions template-lit-js/src/contentScript/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.info('contentScript is running')
57 changes: 56 additions & 1 deletion template-lit-js/src/devtools/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
export {}
import { LitElement, css, html } from 'lit'

chrome.devtools.panels.create('LitCrx', '', '../../devtools.html', () => {
console.log('devtools panel create')
})

export class DevTools extends LitElement {
link = 'https://github.com/guocaoyi/create-chrome-ext'

render() {
return html`
<main>
<h3>DevTools Page</h3>
<a href=${this.link} target="_blank"> generated by create-chrome-ext </a>
</main>
`
}

static styles = css`
@media (prefers-color-scheme: light) {
a:hover {
color: #324fff;
}
}
body {
min-width: 20rem;
}
main {
text-align: center;
padding: 1em;
margin: 0 auto;
}
h3 {
color: #324fff;
text-transform: uppercase;
font-size: 1.5rem;
font-weight: 200;
line-height: 1.2rem;
margin: 2rem auto;
}
a {
font-size: 0.5rem;
margin: 0.5rem;
color: #cccccc;
text-decoration: none;
}
`
}

export default DevTools

window.customElements.define('devtools-root', DevTools)
31 changes: 18 additions & 13 deletions template-lit-js/src/index.css
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
:root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
font-weight: 400;
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen,
Ubuntu,
Cantarell,
'Open Sans',
'Helvetica Neue',
sans-serif;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
background-color: #fafafa;
}
}

body {
min-width: 20rem;
margin: 0;
}
15 changes: 10 additions & 5 deletions template-lit-js/src/manifest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { defineManifest } from '@crxjs/vite-plugin'
import packageData from '../package.json'

export default defineManifest({
name: 'create-chrome-ext',
description: '',
version: '0.0.0',
name: packageData.name,
description: packageData.description,
version: packageData.version,
manifest_version: 3,
icons: {
16: 'img/logo-16.png',
Expand All @@ -16,14 +17,15 @@ export default defineManifest({
default_icon: 'img/logo-48.png',
},
options_page: 'options.html',
devtools_page: 'devtools.html',
background: {
service_worker: 'src/background/index.js',
type: 'module',
},
content_scripts: [
{
matches: ['http://*/*', 'https://*/*'],
js: ['src/content/index.js'],
js: ['src/contentScript/index.js'],
},
],
side_panel: {
Expand All @@ -35,5 +37,8 @@ export default defineManifest({
matches: [],
},
],
permissions: ['sidePanel'],
permissions: ['sidePanel', 'storage'],
chrome_url_overrides: {
newtab: 'newtab.html',
},
})
80 changes: 79 additions & 1 deletion template-lit-js/src/newtab/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
export {}
import { LitElement, css, html } from 'lit'

export class NewTab extends LitElement {
static get properties() {
return {
time: { type: Number, default: '-' },
link: { type: String, default: 'https://github.com/guocaoyi/create-chrome-ext' },
}
}

getTime() {
const date = new Date()
const hour = String(date.getHours()).padStart(2, '0')
const minute = String(date.getMinutes()).padStart(2, '0')
return `${hour}:${minute}`
}

connectedCallback() {
super.connectedCallback()
let intervalId = setInterval(() => {
this.time = this.getTime()
}, 1000)

this.addEventListener('disconnected', () => {
clearInterval(intervalId)
})
}

render() {
return html`
<section>
<span></span>
<h1>${this.time}</h1>
<a .href=${this.link} target="_blank"> generated by create-chrome-ext </a>
</section>
`
}

static styles = css`
section::before {
content: '';
position: fixed;
z-index: -1;
width: 100vw;
height: 100vh;
background-image: url('https://source.unsplash.com/random');
background-size: cover;
filter: blur(10px);
}
section {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
}
h1 {
color: #324fff;
text-transform: uppercase;
font-size: 6rem;
margin: 2rem auto;
}
a {
font-size: 0.5rem;
margin: 0.5rem;
color: #cccccc;
text-decoration: none;
}
`
}

export default NewTab

window.customElements.define('newtab-root', NewTab)
Loading

0 comments on commit d9339d2

Please sign in to comment.