Skip to content

Commit

Permalink
import old samples
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed Dec 3, 2020
1 parent d0fee21 commit b4cd5d4
Show file tree
Hide file tree
Showing 846 changed files with 44,473 additions and 0 deletions.
130 changes: 130 additions & 0 deletions README.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions README.txt
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
Binary file added api/bookmarks/basic/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions api/bookmarks/basic/manifest.json
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'"
}
13 changes: 13 additions & 0 deletions api/bookmarks/basic/popup.html
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>
128 changes: 128 additions & 0 deletions api/bookmarks/basic/popup.js
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();
});
12 changes: 12 additions & 0 deletions api/browserAction/make_page_red/background.js
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"'
});
});
16 changes: 16 additions & 0 deletions api/browserAction/make_page_red/manifest.json
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
}
10 changes: 10 additions & 0 deletions api/browserAction/print/background.js
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();'});
});
17 changes: 17 additions & 0 deletions api/browserAction/print/manifest.json
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
}
Binary file added api/browserAction/print/print_16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions api/browserAction/set_icon_path/background.js
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();
Binary file added api/browserAction/set_icon_path/icon1.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 added api/browserAction/set_icon_path/icon2.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 added api/browserAction/set_icon_path/icon3.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 added api/browserAction/set_icon_path/icon4.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 added api/browserAction/set_icon_path/icon5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions api/browserAction/set_icon_path/manifest.json
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
}
Binary file added api/browserAction/set_page_color/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions api/browserAction/set_page_color/manifest.json
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
}
55 changes: 55 additions & 0 deletions api/browserAction/set_page_color/popup.html
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>
18 changes: 18 additions & 0 deletions api/browserAction/set_page_color/popup.js
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);
}
});
Binary file added api/browsingData/basic/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions api/browsingData/basic/manifest.json
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
}
Loading

0 comments on commit b4cd5d4

Please sign in to comment.