mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-26 13:19:49 +07:00
* Replaced clearbit API (deprecated) with Google's favicon snatcher * Updated UI designs for optional_permissions examples of both mv2 and mv3 Using chrome's build in favicon provider for optional_permissions examples * Run linter --------- Co-authored-by: Oliver Dunk <oliverdunk@google.com>
This commit is contained in:
@@ -20,16 +20,19 @@ function createTop(){chrome.topSites.get(function(topSites) {
|
|||||||
topSites.forEach(function(site) {
|
topSites.forEach(function(site) {
|
||||||
let div = document.createElement('div');
|
let div = document.createElement('div');
|
||||||
div.className = 'colorFun';
|
div.className = 'colorFun';
|
||||||
let tooltip = document.createElement('span');
|
let tooltip = document.createElement('a');
|
||||||
|
tooltip.href = site.url;
|
||||||
tooltip.innerText = site.title;
|
tooltip.innerText = site.title;
|
||||||
tooltip.className = 'tooltip';
|
tooltip.className = 'tooltip';
|
||||||
let url = document.createElement('a');
|
let url = document.createElement('a');
|
||||||
url.href = site.url;
|
url.href = site.url;
|
||||||
let hostname = (new URL(site.url)).hostname;
|
let imageContainer = document.createElement('div');
|
||||||
|
imageContainer.className = 'imageContainer';
|
||||||
let image = document.createElement('img');
|
let image = document.createElement('img');
|
||||||
image.title = site.title;
|
image.title = site.title;
|
||||||
image.src = 'https://logo.clearbit.com/' + hostname;
|
image.src = 'chrome://favicon/' + site.url;
|
||||||
url.appendChild(image);
|
imageContainer.appendChild(image);
|
||||||
|
url.appendChild(imageContainer);
|
||||||
div.appendChild(url);
|
div.appendChild(url);
|
||||||
div.appendChild(tooltip);
|
div.appendChild(tooltip);
|
||||||
sites_div.appendChild(div);
|
sites_div.appendChild(div);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "Optional Permissions New Tab",
|
"name": "Optional Permissions New Tab",
|
||||||
"version": "1.2.5.0",
|
"version": "1.2.5.0",
|
||||||
"description": "Demonstrates optional permissions in extensions",
|
"description": "Demonstrates optional permissions in extensions",
|
||||||
"permissions": ["storage"],
|
"permissions": ["storage", "chrome://favicon/*"],
|
||||||
"optional_permissions": [
|
"optional_permissions": [
|
||||||
"topSites"
|
"topSites"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ h1 {
|
|||||||
|
|
||||||
#display_top {
|
#display_top {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
|
margin-bottom: 40px;
|
||||||
width: 600px;
|
width: 600px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,6 +19,11 @@ h1 {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
|
animation-name: color-extravaganza;
|
||||||
|
animation-duration: 6s;
|
||||||
|
animation-iteration-count: infinite;
|
||||||
|
animation-direction: alternate;
|
||||||
}
|
}
|
||||||
|
|
||||||
.center {
|
.center {
|
||||||
@@ -36,41 +42,41 @@ h1 {
|
|||||||
|
|
||||||
.colorFun {
|
.colorFun {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 100px;
|
height: 70px;
|
||||||
width: 100px;
|
width: 100px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-top: 60px;
|
margin-top: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.colorFun .tooltip {
|
.colorFun .tooltip {
|
||||||
visibility: hidden;
|
width: 100px;
|
||||||
width: 120px;
|
|
||||||
color: #fff;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 5px 0;
|
padding: 5px 0;
|
||||||
border-radius: 6px;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
bottom: 0%;
|
bottom: 0%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
margin-left: -60px;
|
transform: translateX(-50%);
|
||||||
opacity: 0;
|
overflow: hidden;
|
||||||
transition: opacity 0.3s;
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.imageContainer {
|
||||||
#todo_div, .colorFun:hover .tooltip {
|
background-color: #cdcdcd;
|
||||||
visibility: visible;
|
width: 50px;
|
||||||
opacity: 1;
|
height: 50px;
|
||||||
animation-name: color-extravaganza;
|
display: flex;
|
||||||
animation-duration: 6s;
|
align-items: center;
|
||||||
animation-iteration-count: infinite;
|
justify-content: center;
|
||||||
animation-direction: alternate;
|
border-radius: 50%;
|
||||||
|
justify-self: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
.imageContainer img {
|
||||||
width: 100px;
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
@@ -78,3 +84,27 @@ footer {
|
|||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
left: 20px;
|
left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input#todo_value {
|
||||||
|
width: 300px;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 18px;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input#todo_value ~ input[type="submit"] {
|
||||||
|
background-color: #4285F4;
|
||||||
|
color: white;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
input#todo_value ~ input[type="submit"]:hover {
|
||||||
|
background-color: #45a049;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "Optional Permissions New Tab",
|
"name": "Optional Permissions New Tab",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Demonstrates optional permissions in extensions",
|
"description": "Demonstrates optional permissions in extensions",
|
||||||
"permissions": ["storage"],
|
"permissions": ["storage", "favicon"],
|
||||||
"optional_permissions": ["topSites"],
|
"optional_permissions": ["topSites"],
|
||||||
"icons": {
|
"icons": {
|
||||||
"16": "images/icon16.png",
|
"16": "images/icon16.png",
|
||||||
|
|||||||
@@ -28,16 +28,22 @@ const createTop = () => {
|
|||||||
topSites.forEach((site) => {
|
topSites.forEach((site) => {
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
div.className = 'colorFun';
|
div.className = 'colorFun';
|
||||||
const tooltip = document.createElement('span');
|
const tooltip = document.createElement('a');
|
||||||
|
tooltip.href = site.url;
|
||||||
tooltip.innerText = site.title;
|
tooltip.innerText = site.title;
|
||||||
tooltip.className = 'tooltip';
|
tooltip.className = 'tooltip';
|
||||||
const url = document.createElement('a');
|
const url = document.createElement('a');
|
||||||
url.href = site.url;
|
url.href = site.url;
|
||||||
const hostname = new URL(site.url).hostname;
|
const imageContainer = document.createElement('div');
|
||||||
|
imageContainer.className = 'imageContainer';
|
||||||
|
const imgUrl = new URL(chrome.runtime.getURL('/_favicon/'));
|
||||||
|
imgUrl.searchParams.set('pageUrl', site.url);
|
||||||
|
imgUrl.searchParams.set('size', '28');
|
||||||
const image = document.createElement('img');
|
const image = document.createElement('img');
|
||||||
image.title = site.title;
|
image.title = site.title;
|
||||||
image.src = 'https://logo.clearbit.com/' + hostname;
|
image.src = imgUrl.toString();
|
||||||
url.appendChild(image);
|
imageContainer.appendChild(image);
|
||||||
|
url.appendChild(imageContainer);
|
||||||
div.appendChild(url);
|
div.appendChild(url);
|
||||||
div.appendChild(tooltip);
|
div.appendChild(tooltip);
|
||||||
sites_div.appendChild(div);
|
sites_div.appendChild(div);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ h1 {
|
|||||||
|
|
||||||
#display_top {
|
#display_top {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
|
margin-bottom: 40px;
|
||||||
width: 600px;
|
width: 600px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +29,11 @@ h1 {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
|
animation-name: color-extravaganza;
|
||||||
|
animation-duration: 6s;
|
||||||
|
animation-iteration-count: infinite;
|
||||||
|
animation-direction: alternate;
|
||||||
}
|
}
|
||||||
|
|
||||||
.center {
|
.center {
|
||||||
@@ -56,41 +62,41 @@ h1 {
|
|||||||
|
|
||||||
.colorFun {
|
.colorFun {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 100px;
|
height: 70px;
|
||||||
width: 100px;
|
width: 100px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-top: 60px;
|
margin-top: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.colorFun .tooltip {
|
.colorFun .tooltip {
|
||||||
visibility: hidden;
|
width: 100px;
|
||||||
width: 120px;
|
|
||||||
color: #fff;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 5px 0;
|
padding: 5px 0;
|
||||||
border-radius: 6px;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
bottom: 0%;
|
bottom: 0%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
margin-left: -60px;
|
transform: translateX(-50%);
|
||||||
opacity: 0;
|
overflow: hidden;
|
||||||
transition: opacity 0.3s;
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
#todo_div,
|
.imageContainer {
|
||||||
.colorFun:hover .tooltip {
|
background-color: #cdcdcd;
|
||||||
visibility: visible;
|
width: 50px;
|
||||||
opacity: 1;
|
height: 50px;
|
||||||
animation-name: color-extravaganza;
|
display: flex;
|
||||||
animation-duration: 6s;
|
align-items: center;
|
||||||
animation-iteration-count: infinite;
|
justify-content: center;
|
||||||
animation-direction: alternate;
|
border-radius: 50%;
|
||||||
|
justify-self: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
.imageContainer img {
|
||||||
width: 100px;
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
@@ -98,3 +104,27 @@ footer {
|
|||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
left: 20px;
|
left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input#todo_value {
|
||||||
|
width: 300px;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 18px;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input#todo_value ~ input[type="submit"] {
|
||||||
|
background-color: #4285F4;
|
||||||
|
color: white;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
input#todo_value ~ input[type="submit"]:hover {
|
||||||
|
background-color: #45a049;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user