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.
- Loading branch information
Showing
846 changed files
with
44,473 additions
and
0 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,7 @@ | ||
Chromium Extension Examples | ||
|
||
The directory structure is as follows: | ||
* api/ - trivial extensions focused on a single API package | ||
* howto/ - simple extensions showing how to perform a particular task | ||
* tutorials/ - multi-step walkthroughs referenced inline in the docs | ||
* extensions/ - full featured extensions spanning multiple API packages |
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,15 @@ | ||
{ | ||
"name": "My Bookmarks", | ||
"version": "1.1", | ||
"description": "A browser action with a popup dump of all bookmarks, including search, add, edit and delete.", | ||
"permissions": [ | ||
"bookmarks" | ||
], | ||
"browser_action": { | ||
"default_title": "My Bookmarks", | ||
"default_icon": "icon.png", | ||
"default_popup": "popup.html" | ||
}, | ||
"manifest_version": 2, | ||
"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'" | ||
} |
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 @@ | ||
<html> | ||
<head> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | ||
<script src="popup.js"></script> | ||
</head> | ||
<body style="width: 400px"> | ||
<div>Search Bookmarks: <input id="search"></div> | ||
<div id="bookmarks"></div> | ||
<div id="editdialog"></div> | ||
<div id="deletedialog"></div> | ||
<div id="adddialog"></div> | ||
</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,128 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Search the bookmarks when entering the search keyword. | ||
$(function() { | ||
$('#search').change(function() { | ||
$('#bookmarks').empty(); | ||
dumpBookmarks($('#search').val()); | ||
}); | ||
}); | ||
// Traverse the bookmark tree, and print the folder and nodes. | ||
function dumpBookmarks(query) { | ||
var bookmarkTreeNodes = chrome.bookmarks.getTree( | ||
function(bookmarkTreeNodes) { | ||
$('#bookmarks').append(dumpTreeNodes(bookmarkTreeNodes, query)); | ||
}); | ||
} | ||
function dumpTreeNodes(bookmarkNodes, query) { | ||
var list = $('<ul>'); | ||
var i; | ||
for (i = 0; i < bookmarkNodes.length; i++) { | ||
list.append(dumpNode(bookmarkNodes[i], query)); | ||
} | ||
return list; | ||
} | ||
function dumpNode(bookmarkNode, query) { | ||
if (bookmarkNode.title) { | ||
if (query && !bookmarkNode.children) { | ||
if (String(bookmarkNode.title).indexOf(query) == -1) { | ||
return $('<span></span>'); | ||
} | ||
} | ||
var anchor = $('<a>'); | ||
anchor.attr('href', bookmarkNode.url); | ||
anchor.text(bookmarkNode.title); | ||
/* | ||
* When clicking on a bookmark in the extension, a new tab is fired with | ||
* the bookmark url. | ||
*/ | ||
anchor.click(function() { | ||
chrome.tabs.create({url: bookmarkNode.url}); | ||
}); | ||
var span = $('<span>'); | ||
var options = bookmarkNode.children ? | ||
$('<span>[<a href="#" id="addlink">Add</a>]</span>') : | ||
$('<span>[<a id="editlink" href="#">Edit</a> <a id="deletelink" ' + | ||
'href="#">Delete</a>]</span>'); | ||
var edit = bookmarkNode.children ? $('<table><tr><td>Name</td><td>' + | ||
'<input id="title"></td></tr><tr><td>URL</td><td><input id="url">' + | ||
'</td></tr></table>') : $('<input>'); | ||
// Show add and edit links when hover over. | ||
span.hover(function() { | ||
span.append(options); | ||
$('#deletelink').click(function() { | ||
$('#deletedialog').empty().dialog({ | ||
autoOpen: false, | ||
title: 'Confirm Deletion', | ||
resizable: false, | ||
height: 140, | ||
modal: true, | ||
overlay: { | ||
backgroundColor: '#000', | ||
opacity: 0.5 | ||
}, | ||
buttons: { | ||
'Yes, Delete It!': function() { | ||
chrome.bookmarks.remove(String(bookmarkNode.id)); | ||
span.parent().remove(); | ||
$(this).dialog('destroy'); | ||
}, | ||
Cancel: function() { | ||
$(this).dialog('destroy'); | ||
} | ||
} | ||
}).dialog('open'); | ||
}); | ||
$('#addlink').click(function() { | ||
$('#adddialog').empty().append(edit).dialog({autoOpen: false, | ||
closeOnEscape: true, title: 'Add New Bookmark', modal: true, | ||
buttons: { | ||
'Add' : function() { | ||
chrome.bookmarks.create({parentId: bookmarkNode.id, | ||
title: $('#title').val(), url: $('#url').val()}); | ||
$('#bookmarks').empty(); | ||
$(this).dialog('destroy'); | ||
window.dumpBookmarks(); | ||
}, | ||
'Cancel': function() { | ||
$(this).dialog('destroy'); | ||
} | ||
}}).dialog('open'); | ||
}); | ||
$('#editlink').click(function() { | ||
edit.val(anchor.text()); | ||
$('#editdialog').empty().append(edit).dialog({autoOpen: false, | ||
closeOnEscape: true, title: 'Edit Title', modal: true, | ||
show: 'slide', buttons: { | ||
'Save': function() { | ||
chrome.bookmarks.update(String(bookmarkNode.id), { | ||
title: edit.val() | ||
}); | ||
anchor.text(edit.val()); | ||
options.show(); | ||
$(this).dialog('destroy'); | ||
}, | ||
'Cancel': function() { | ||
$(this).dialog('destroy'); | ||
} | ||
}}).dialog('open'); | ||
}); | ||
options.fadeIn(); | ||
}, | ||
// unhover | ||
function() { | ||
options.remove(); | ||
}).append(anchor); | ||
} | ||
var li = $(bookmarkNode.title ? '<li>' : '<div>').append(span); | ||
if (bookmarkNode.children && bookmarkNode.children.length > 0) { | ||
li.append(dumpTreeNodes(bookmarkNode.children, query)); | ||
} | ||
return li; | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
dumpBookmarks(); | ||
}); |
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,12 @@ | ||
// Copyright (c) 2011 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Called when the user clicks on the browser action. | ||
chrome.browserAction.onClicked.addListener(function(tab) { | ||
// No tabs or host permissions needed! | ||
console.log('Turning ' + tab.url + ' red!'); | ||
chrome.tabs.executeScript({ | ||
code: 'document.body.style.backgroundColor="red"' | ||
}); | ||
}); |
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,16 @@ | ||
{ | ||
"name": "Page Redder", | ||
"description": "Make the current page red", | ||
"version": "2.0", | ||
"permissions": [ | ||
"activeTab" | ||
], | ||
"background": { | ||
"scripts": ["background.js"], | ||
"persistent": false | ||
}, | ||
"browser_action": { | ||
"default_title": "Make this page red" | ||
}, | ||
"manifest_version": 2 | ||
} |
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 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Called when the user clicks on the browser action. | ||
chrome.browserAction.onClicked.addListener(function(tab) { | ||
chrome.tabs.executeScript( | ||
tab.id, | ||
{code: 'window.print();'}); | ||
}); |
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,17 @@ | ||
{ | ||
"name": "Print this page", | ||
"description": "Adds a print button to the browser.", | ||
"version": "1.2", | ||
"background": { | ||
"scripts": ["background.js"], | ||
"persistent": false | ||
}, | ||
"permissions": [ | ||
"activeTab" | ||
], | ||
"browser_action": { | ||
"default_title": "Print this page", | ||
"default_icon": "print_16x16.png" | ||
}, | ||
"manifest_version": 2 | ||
} |
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,27 @@ | ||
// Copyright (c) 2011 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
'use strict'; | ||
|
||
chrome.runtime.onInstalled.addListener(function() { | ||
chrome.storage.sync.set({number: 1}, function() { | ||
console.log('The number is set to 1.'); | ||
}); | ||
}); | ||
|
||
function updateIcon() { | ||
chrome.storage.sync.get('number', function(data) { | ||
var current = data.number; | ||
chrome.browserAction.setIcon({path: 'icon' + current + '.png'}); | ||
current++; | ||
if (current > 5) | ||
current = 1; | ||
chrome.storage.sync.set({number: current}, function() { | ||
console.log('The number is set to ' + current); | ||
}); | ||
}); | ||
}; | ||
|
||
chrome.browserAction.onClicked.addListener(updateIcon); | ||
updateIcon(); |
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.
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,14 @@ | ||
{ | ||
"name": "A browser action which changes its icon when clicked", | ||
"description": "Click browser action icon to change color!", | ||
"version": "1.3", | ||
"background": { | ||
"scripts": ["background.js"], | ||
"persistent": false | ||
}, | ||
"permissions": ["storage"], | ||
"browser_action": { | ||
"name": "Click to change the icon's color" | ||
}, | ||
"manifest_version": 2 | ||
} |
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,14 @@ | ||
{ | ||
"name": "A browser action with a popup that changes the page color", | ||
"description": "Change the current page color", | ||
"version": "1.0", | ||
"permissions": [ | ||
"activeTab" | ||
], | ||
"browser_action": { | ||
"default_title": "Set this page's color.", | ||
"default_icon": "icon.png", | ||
"default_popup": "popup.html" | ||
}, | ||
"manifest_version": 2 | ||
} |
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,55 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Set Page Color Popup</title> | ||
<style> | ||
body { | ||
overflow: hidden; | ||
margin: 0px; | ||
padding: 0px; | ||
background: white; | ||
} | ||
|
||
div:first-child { | ||
margin-top: 0px; | ||
} | ||
|
||
div { | ||
cursor: pointer; | ||
text-align: center; | ||
padding: 1px 3px; | ||
font-family: sans-serif; | ||
font-size: 0.8em; | ||
width: 100px; | ||
margin-top: 1px; | ||
background: #cccccc; | ||
} | ||
div:hover { | ||
background: #aaaaaa; | ||
} | ||
#red { | ||
border: 1px solid red; | ||
color: red; | ||
} | ||
#blue { | ||
border: 1px solid blue; | ||
color: blue; | ||
} | ||
#green { | ||
border: 1px solid green; | ||
color: green; | ||
} | ||
#yellow { | ||
border: 1px solid yellow; | ||
color: yellow; | ||
} | ||
</style> | ||
<script src="popup.js"></script> | ||
</head> | ||
<body> | ||
<div id="red">red</div> | ||
<div id="blue">blue</div> | ||
<div id="green">green</div> | ||
<div id="yellow">yellow</div> | ||
</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 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
'use strict'; | ||
|
||
function click(e) { | ||
chrome.tabs.executeScript(null, | ||
{code:"document.body.style.backgroundColor='" + e.target.id + "'"}); | ||
window.close(); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
var divs = document.querySelectorAll('div'); | ||
for (var i = 0; i < divs.length; i++) { | ||
divs[i].addEventListener('click', click); | ||
} | ||
}); |
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,13 @@ | ||
{ | ||
"name" : "BrowsingData API: Basics", | ||
"version" : "1.1", | ||
"description" : "A trivial usage example.", | ||
"permissions": [ | ||
"browsingData" | ||
], | ||
"browser_action": { | ||
"default_icon": "icon.png", | ||
"default_popup": "popup.html" | ||
}, | ||
"manifest_version": 2 | ||
} |
Oops, something went wrong.