forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add topsites/basic sample (GoogleChrome#967)
* Update sample file structure. * Update description * Fix wrong favicon path * Add basic sample * Update README.md * Fix comments
- Loading branch information
Showing
11 changed files
with
76 additions
and
12 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# chrome.topSites - Basic | ||
|
||
This sample demonstrates using the `chrome.topSites` API to get the user's most visited sites. | ||
|
||
## Overview | ||
|
||
The extension uses `chrome.topSites.get` to get the user's most visited sites, and then renders them in the popup. | ||
|
||
## Running this extension | ||
|
||
1. Clone this repository. | ||
2. Load this directory in Chrome as an [unpacked extension](https://developer.chrome.com/docs/extensions/mv3/getstarted/development-basics/#load-unpacked). | ||
3. Click the extension's action icon. |
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,11 @@ | ||
{ | ||
"name": "Top Sites", | ||
"version": "1.2", | ||
"description": "Shows the top sites in the popup.", | ||
"permissions": ["topSites"], | ||
"action": { | ||
"default_icon": "icon.png", | ||
"default_popup": "popup.html" | ||
}, | ||
"manifest_version": 3 | ||
} |
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,8 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<h2 style="width: 300px">Most Visited:</h2> | ||
<div id="mostVisited_div"></div> | ||
<script src="popup.js"></script> | ||
</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,25 @@ | ||
// Event listener for clicks on links in an action popup. | ||
// Open the link in a new tab of the current window. | ||
function onAnchorClick(event) { | ||
chrome.tabs.create({ url: event.target.href }); | ||
return false; | ||
} | ||
|
||
// Given an array of URLs, build a DOM list of these URLs in the action popup. | ||
function buildPopupDom(mostVisitedURLs) { | ||
const popupDiv = document.getElementById('mostVisited_div'); | ||
const ol = popupDiv.appendChild(document.createElement('ol')); | ||
|
||
for (let i = 0; i < mostVisitedURLs.length; i++) { | ||
const li = ol.appendChild(document.createElement('li')); | ||
const a = li.appendChild(document.createElement('a')); | ||
a.href = mostVisitedURLs[i].url; | ||
a.appendChild(document.createTextNode(mostVisitedURLs[i].title)); | ||
a.addEventListener('click', onAnchorClick); | ||
} | ||
} | ||
|
||
window.onload = async () => { | ||
const mostVisitedURLs = await chrome.topSites.get(); | ||
buildPopupDom(mostVisitedURLs); | ||
}; |
2 changes: 1 addition & 1 deletion
2
api-samples/topSites/README.md → api-samples/topSites/magic8ball/README.md
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,10 @@ | ||
{ | ||
"name": "topSites API sample", | ||
"version": "2", | ||
"description": "An extension that demonstrates the chrome.topSites API by registering a custom new tab page.", | ||
"chrome_url_overrides": { | ||
"newtab": "newTab.html" | ||
}, | ||
"permissions": ["topSites", "favicon"], | ||
"manifest_version": 3 | ||
} |
File renamed without changes.
File renamed without changes.
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 was deleted.
Oops, something went wrong.