-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
488 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const { merge } = require('webpack-merge'); | ||
|
||
const common = require('./webpack.common.js'); | ||
const PATHS = require('./paths'); | ||
|
||
// Merge webpack configuration files | ||
const config = (env, argv) => | ||
merge(common, { | ||
entry: { | ||
sidepanel: PATHS.src + '/sidepanel.js', | ||
background: PATHS.src + '/background.js', | ||
}, | ||
devtool: argv.mode === 'production' ? false : 'source-map', | ||
}); | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
// With background scripts you can communicate with sidepanel | ||
// and contentScript files. | ||
// For more information on background script, | ||
// See https://developer.chrome.com/extensions/background_pages | ||
|
||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
if (request.type === 'GREETINGS') { | ||
const message = | ||
"Hi Syd, my name is Bac. I am from Background. It's great to hear from you."; | ||
|
||
// Log message coming from the `request` parameter | ||
console.log(request.payload.message); | ||
// Send a response message | ||
sendResponse({ | ||
message, | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* normalize css starts here */ | ||
*, | ||
*::before, | ||
*::after { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
ul { | ||
list-style: none; | ||
} | ||
/* normalize css ends here */ | ||
|
||
html { | ||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, | ||
sans-serif; | ||
color: #222; | ||
} | ||
|
||
.app { | ||
height: 100%; | ||
text-align: left; | ||
padding: 20px; | ||
} | ||
|
||
.app-heading { | ||
font-size: 20px; | ||
font-weight: 700; | ||
} | ||
|
||
.tabs-list { | ||
margin: 15px -8px; | ||
} | ||
|
||
.tab-container { | ||
display: flex; | ||
align-items: center; | ||
padding: 8px; | ||
cursor: pointer; | ||
border-radius: 4px; | ||
} | ||
|
||
.tab-container:hover { | ||
background-color: #fafafa; | ||
} | ||
|
||
.tab-image { | ||
width: 20px; | ||
height: 20px; | ||
margin-right: 8px; | ||
flex-shrink: 0; | ||
} | ||
|
||
.tab-image-placeholder { | ||
font-size: 22px; | ||
color: #555; | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.tab-title { | ||
font-size: 14px; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
} | ||
|
||
.title { | ||
font-size: 18px; | ||
font-weight: 600; | ||
margin-bottom: 10px; | ||
text-align: center; | ||
} | ||
|
||
.subtitle { | ||
font-size: 12px; | ||
text-align: center; | ||
} | ||
|
||
code { | ||
font-size: 12px; | ||
font-family: inherit; | ||
background-color: rgba(254, 237, 185, 0.3); | ||
padding: 2px 4px; | ||
border-radius: 2px; | ||
} | ||
|
||
.divider { | ||
margin: 30px auto 25px; | ||
width: 50px; | ||
border: 0.5px dashed #000; | ||
opacity: 0.1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict'; | ||
|
||
import './sidepanel.css'; | ||
|
||
(function () { | ||
function initList(tabs) { | ||
const list = document.getElementById('tabs-list'); | ||
|
||
const listItem = tabs.map((tab) => { | ||
return ` | ||
<li> | ||
<div data-tab-id="${tab.id}" class="tab-container"> | ||
${ | ||
tab.favIconUrl | ||
? `<img src="${tab.favIconUrl}" alt="" class="tab-image" />` | ||
: '<span class="tab-image tab-image-placeholder">❐</span>' | ||
} | ||
<p class="tab-title" title="${tab.title}">${tab.title}</p> | ||
</div> | ||
</li> | ||
`; | ||
}); | ||
|
||
list.innerHTML = listItem.join('\n'); | ||
|
||
list.addEventListener('click', (event) => { | ||
if (event.target && event.target.closest('.tab-container')) { | ||
const tabId = event.target | ||
.closest('.tab-container') | ||
.getAttribute('data-tab-id'); | ||
|
||
chrome.tabs.update(Number(tabId), { | ||
active: true, | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function setupTabList() { | ||
chrome.tabs.query( | ||
{ | ||
currentWindow: true, | ||
}, | ||
(tabs) => { | ||
initList(tabs); | ||
} | ||
); | ||
} | ||
|
||
function setupTabListeners() { | ||
chrome.tabs.onCreated.addListener(setupTabList); | ||
chrome.tabs.onMoved.addListener(setupTabList); | ||
chrome.tabs.onRemoved.addListener(setupTabList); | ||
chrome.tabs.onUpdated.addListener(setupTabList); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
setupTabList(); | ||
setupTabListeners(); | ||
}); | ||
|
||
// Communicate with background file by sending a message | ||
chrome.runtime.sendMessage( | ||
{ | ||
type: 'GREETINGS', | ||
payload: { | ||
message: 'Hello, my name is Syd. I am from SidePanel.', | ||
}, | ||
}, | ||
(response) => { | ||
console.log(response.message); | ||
} | ||
); | ||
})(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>My Sidepanel</title> | ||
<link rel="stylesheet" href="sidepanel.css" /> | ||
</head> | ||
<body> | ||
<div class="app"> | ||
<p class="app-heading">Tabs</p> | ||
|
||
<ul id="tabs-list" class="tabs-list"></ul> | ||
|
||
<hr class="divider" /> | ||
|
||
<p class="title">Chrome Extension is Ready!</p> | ||
<p class="subtitle">Start by updating <code>sidepanel.html</code></p> | ||
</div> | ||
|
||
<script src="sidepanel.js"></script> | ||
|
||
<!-- | ||
This HTML file opens when you click on icon from the toolbar. | ||
To begin the development, run `npm run watch`. | ||
To create a production bundle, use `npm run build`. | ||
--> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const { merge } = require('webpack-merge'); | ||
|
||
const common = require('./webpack.common.js'); | ||
const PATHS = require('./paths'); | ||
|
||
// Merge webpack configuration files | ||
const config = (env, argv) => | ||
merge(common, { | ||
entry: { | ||
sidepanel: PATHS.src + '/sidepanel.ts', | ||
background: PATHS.src + '/background.ts', | ||
}, | ||
devtool: argv.mode === 'production' ? false : 'source-map', | ||
}); | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
// With background scripts you can communicate with sidepanel | ||
// and contentScript files. | ||
// For more information on background script, | ||
// See https://developer.chrome.com/extensions/background_pages | ||
|
||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
if (request.type === 'GREETINGS') { | ||
const message: string = | ||
"Hi Syd, my name is Bac. I am from Background. It's great to hear from you."; | ||
|
||
// Log message coming from the `request` parameter | ||
console.log(request.payload.message); | ||
// Send a response message | ||
sendResponse({ | ||
message, | ||
}); | ||
} | ||
}); |
Oops, something went wrong.