├── README.md ├── browser_action ├── _locales │ └── en │ │ └── messages.json ├── background.js ├── content.css ├── content.js ├── key.pem ├── manifest.json └── popup │ ├── popup.css │ ├── popup.html │ └── popup.js ├── devtools ├── background.js ├── devtools.html ├── devtools.js ├── manifest.json ├── pane │ └── pane.html └── panel │ ├── panel.css │ ├── panel.html │ └── panel.js ├── override ├── manifest.json ├── newtab.html └── newtab.js └── page_action ├── background.js └── manifest.json /README.md: -------------------------------------------------------------------------------- 1 | ### Tuts+ Course: Building Chrome Extensions 2 | **Instructor: Dan Wellman** 3 | 4 | Learn how to create extensions for Google's Chrome browser. In this course we'll learn everything we need to know in order to extend the functionality of the browser with custom extensions. We'll look at the different types of extension that we can build, and see the different kinds of extension architecture. 5 | 6 | The source files directory contains four sub-directories - one for each of the different extensions that we'll build throughout the course. Each subdirectory contains at minimum a manifest file that describes that extension and one or more JS, CSS and or HTML files. Several of the extensions also contain subdirectories that contain additional resources used by the extension in question. 7 | 8 | 9 | These are source files for the Tuts+ course: [Building Chrome Extensions](https://code.tutsplus.com/courses/building-a-chrome-extension) 10 | 11 | **Take this course on [Tuts+](https://code.tutsplus.com/courses)** 12 | -------------------------------------------------------------------------------- /browser_action/_locales/en/messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "extensionName": { 3 | "message": "browser_action", 4 | "description": "Extension name" 5 | }, 6 | "extensionDescription": { 7 | "message": "An example browser action extension", 8 | "description": "Extension description" 9 | }, 10 | "popupTitle": { 11 | "message": "My awesome popup!", 12 | "description": "Popup title" 13 | } 14 | } -------------------------------------------------------------------------------- /browser_action/background.js: -------------------------------------------------------------------------------- 1 | function handleButtonClick() { 2 | chrome.tabs.create({ 3 | index: 0, 4 | url: 'http://google.co.uk' 5 | }, function (tab) { 6 | console.log(tab.url); 7 | }); 8 | } 9 | 10 | chrome.runtime.onMessage.addListener(function (message, sender, response) { 11 | console.log(message, sender); 12 | response({ status: 'success!' }); 13 | }); 14 | 15 | chrome.runtime.onConnect.addListener(function (messagePort) { 16 | messagePort.onMessage.addListener(function (message) { 17 | console.log(message.h2); 18 | messagePort.postMessage({ status: 'received!' }); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /browser_action/content.css: -------------------------------------------------------------------------------- 1 | body { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /browser_action/content.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 'use strict'; 3 | 4 | var h1 = document.getElementsByTagName('h1')[0]; 5 | if (h1) { 6 | chrome.runtime.sendMessage({ 7 | firstHeading: h1.textContent 8 | }, function (response) { 9 | console.log(response.status); 10 | }); 11 | } 12 | 13 | var messagePort = chrome.runtime.connect({ name: 'headings' }); 14 | 15 | var h2s = Array.prototype.slice.call(document.getElementsByTagName('h2')); 16 | h2s.forEach(function (h2) { 17 | messagePort.postMessage({ h2: h2.textContent }); 18 | }); 19 | 20 | messagePort.onMessage.addListener(function (message) { 21 | console.log(message.status); 22 | }); 23 | }()); 24 | -------------------------------------------------------------------------------- /browser_action/key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDI5fP8av3g4lMU 3 | WKD+I6RcaMdwI5AB7b3j6X9owrkSWc1tT8aFmjDyDR09GB2No1WdLcCM7Fh8BIUE 4 | Kd6RP0tRXf6cBQnkWJubuGUFxXxzqK7HZ4kh9SGTjv4bUGD/ZBBLjjqolEcuyrxE 5 | 9WeXq8A+y4iSaJ7N28n0IaBC41X9n6HdFO4fq2vQXfbtDBDLJCOFmAawnFtU1P9D 6 | dBu13e1oSAvrfXQIX00LoVxqmMWWID6oFy+6cO3eMQppfJTRNlSCiDLYtVE2a/y2 7 | tmSwCnl43b/so4fyLaJq5LjcoDI74O2TqsZ9b7ZeoTGnVQV2EB6a/blBzVDDoLfa 8 | VagvZvO5AgMBAAECggEAbzEfLplFNR/vHbbEPIUbpm3z3LRCM18Tl76X3zLPXkHH 9 | +nWKCk5CQuZRRYxAZ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nSaQPl29 25 | ATT5ePJ3uzp7QArdpSwHl+tbXCbijVeTjLXXXq0y4sBZkiqoSmGTh1DK8irVlokp 26 | Io5AqaIGrHZl8EBj5sxKCfJDD+8xY1IEYuLgcTpZg7qoEH2BekNM4d8o5jTMYiVB 27 | nMrvFltiSSW70Y8TQOwAZw== 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /browser_action/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 2, 3 | "name": "__MSG_extensionName__", 4 | "version": "0.1.0", 5 | "description": "__MSG_extensionDescription__", 6 | "author": "Dan Wellman", 7 | "browser_action": { 8 | "default_title": "Use this to open the popup", 9 | "default_popup": "popup/popup.html" 10 | }, 11 | "background": { 12 | "scripts": [ "background.js" ], 13 | "persistent": false 14 | }, 15 | "permissions": [ "tabs", "http://numbersapi.com/" ], 16 | "content_scripts": [ 17 | { 18 | "matches": [ "*://*/*" ], 19 | "js": [ "content.js" ], 20 | "css": [ "content.css" ] 21 | } 22 | ], 23 | "default_locale": "en", 24 | "content_security_policy": "script-src 'self' 'unsafe-eval' https://code.jquery.com; object-src 'self'" 25 | } -------------------------------------------------------------------------------- /browser_action/popup/popup.css: -------------------------------------------------------------------------------- 1 | body { margin: 1em 2em; } 2 | h1 { white-space: nowrap; padding-bottom:.5em; border-bottom: 1px solid #eee; } 3 | label { margin: .25em 0 1.5em; float: left; } 4 | button { float: right; } 5 | a { display: block; border-top: 1px solid #eee; border-bottom: 1px solid #eee; padding: 1em 0 1.5em; clear: both; } 6 | p { margin-bottom: 1.5em; } 7 | -------------------------------------------------------------------------------- /browser_action/popup/popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |Or any other mark-up that you want!
13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /browser_action/popup/popup.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 'use strict'; 3 | 4 | var backgroundpage = chrome.extension.getBackgroundPage(); 5 | 6 | document.querySelector('button').addEventListener('click', function () { 7 | backgroundpage.handleButtonClick(); 8 | }); 9 | 10 | var title = chrome.i18n.getMessage("popupTitle"); 11 | document.getElementsByTagName('h1')[0].textContent = title; 12 | console.log(chrome.i18n.getMessage('@@extension_id')); 13 | console.log(chrome.i18n.getMessage('@@ui_locale')); 14 | 15 | eval('console.log("bad");'); 16 | console.log(window.$); 17 | 18 | var xhr = new XMLHttpRequest(); 19 | xhr.onload = function () { 20 | console.log(xhr.responseText); 21 | }; 22 | xhr.open('GET', 'http://numbersapi.com/random'); 23 | xhr.send(); 24 | }()); 25 | -------------------------------------------------------------------------------- /devtools/background.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 'use strict'; 3 | 4 | chrome.runtime.onConnect.addListener(function (devtoolsPort) { 5 | devtoolsPort.onMessage.addListener(function (message) { 6 | console.log(message.greeting); 7 | }); 8 | }); 9 | }()); 10 | -------------------------------------------------------------------------------- /devtools/devtools.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |