Difference between revisions of "Chrome extension"
From Publication Station
m (made more simple) |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Creating a Chrome browser extension can | Creating a Chrome browser extension can simple. | ||
https://developer.chrome.com/extensions/getstarted provides a good starting point tutorial. But I'll try provide a simpler tutorial, on how to create a extensions that turns the background of pages red and rotates all the elements. | https://developer.chrome.com/extensions/getstarted provides a good starting point tutorial. But I'll try provide a simpler tutorial, on how to create a extensions that turns the background of pages red and rotates all the elements. | ||
We'll start by creating | We'll start by creating a folder | ||
And adding to it the following files: | And adding to it the following files: | ||
Line 9: | Line 9: | ||
* <code>icon.png</code> the icon of the extension | * <code>icon.png</code> the icon of the extension | ||
* <code>popup.html</code> content shown when user clicks the extension icon | * <code>popup.html</code> content shown when user clicks the extension icon | ||
* <code>jquery-3.1.1.min.js</code> a jquery library [https://code.jquery.com/jquery-3.1.1.min.js | * <code>jquery-3.1.1.min.js</code> a jquery library [https://code.jquery.com/jquery-3.1.1.min.js download this] | ||
* <code>content.js</code> JavasScript file where we'll add the action we'll like the extension to perform | * <code>content.js</code> JavasScript file where we'll add the action we'll like the extension to perform | ||
==files== | |||
==manifest.json== | ===manifest.json=== | ||
<source lang="javascript"> | <source lang="javascript"> | ||
{ | { | ||
Line 38: | Line 38: | ||
</source> | </source> | ||
==popup.html== | ===popup.html=== | ||
<source lang="html4strict"> | <source lang="html4strict"> | ||
<!doctype html> | <!doctype html> | ||
Line 66: | Line 66: | ||
</source> | </source> | ||
==content.js== | ===content.js=== | ||
<source lang="JavaScript"> | <source lang="JavaScript"> | ||
console.log('hello from red extension'); | console.log('hello from red extension'); | ||
/* make body background red; all elements ('*') with blue color and rotated 180deg */ | |||
$('body').css('background', 'red', 'important'); | $('body').css('background', 'red', 'important'); | ||
$('*').css('color','blue', 'important'); | $('*').css('color','blue', 'important'); | ||
$('*').css('-webkit-transform','rotate(180deg)', 'important') | $('*').css('-webkit-transform','rotate(180deg)', 'important') | ||
</source> | </source> | ||
==load the extension== | |||
To load the extension: | |||
* visit chrome://extensions in your brows | |||
* Ensure that the Developer mode checkbox in the top right-hand corner is checked. | |||
* Click Load unpacked extension… to pop up a file-selection dialog. | |||
* Navigate to the directory in which your extension files live, and select it. | |||
* Alternatively, you can drag and drop the directory where your extension files live onto chrome://extensions in your browser to load it. | |||
* If the extension is valid, it'll be loaded up and active right away! If it's invalid, an error message will be displayed at the top of the page. Correct the error, and try again. | |||
=Examples= | |||
Raphael Rozendall [http://www.abstractbrowsing.net/ Abstract Browsing ] | |||
[https://chrome.google.com/webstore/detail/text-free-browsing/ioglfbphilinnhdmfbmfljmhemegfcdg/related?utm_source=vk/ Text Free Browsing ] | |||
[https://chrome.google.com/webstore/detail/cornify-unicorn-and-rainb/ghdnfbmfflgelndafnlgabneckbmfpla?utm_source=vk/ Cornify ] | |||
[[Category:Research]] | |||
[[Category:Tutorial]] |
Latest revision as of 13:28, 31 March 2020
Creating a Chrome browser extension can simple.
https://developer.chrome.com/extensions/getstarted provides a good starting point tutorial. But I'll try provide a simpler tutorial, on how to create a extensions that turns the background of pages red and rotates all the elements.
We'll start by creating a folder
And adding to it the following files:
manifest.json
a metadata file in JSON format containing properties of your extension: name, description, version numbericon.png
the icon of the extensionpopup.html
content shown when user clicks the extension iconjquery-3.1.1.min.js
a jquery library download thiscontent.js
JavasScript file where we'll add the action we'll like the extension to perform
files
manifest.json
{
"manifest_version": 2,
"name": "Communist extension",
"description": "This extension turns you page red",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [ ],
"content_scripts": [
{
"matches": ["<all_urls>" ],
"js": ["jquery-3.1.1.min.js", "content.js"]
}
]
}
popup.html
<!doctype html>
<!--
This page is shown when the extension button is clicked, because the
"browser_action" field in manifest.json contains the "default_popup" key with
value "popup.html".
-->
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
background:red;
color: white;
}
</style>
<!--
- JavaScript and HTML must be in separate files: see our Content Security
-->
</head>
<body>
<h2>Red extention</h2>
</body>
</html>
content.js
console.log('hello from red extension');
/* make body background red; all elements ('*') with blue color and rotated 180deg */
$('body').css('background', 'red', 'important');
$('*').css('color','blue', 'important');
$('*').css('-webkit-transform','rotate(180deg)', 'important')
load the extension
To load the extension:
- visit chrome://extensions in your brows
- Ensure that the Developer mode checkbox in the top right-hand corner is checked.
- Click Load unpacked extension… to pop up a file-selection dialog.
- Navigate to the directory in which your extension files live, and select it.
- Alternatively, you can drag and drop the directory where your extension files live onto chrome://extensions in your browser to load it.
- If the extension is valid, it'll be loaded up and active right away! If it's invalid, an error message will be displayed at the top of the page. Correct the error, and try again.
Examples
Raphael Rozendall Abstract Browsing