File tree Expand file tree Collapse file tree 6 files changed +81
-0
lines changed
how-to-make-chrome-extensions Expand file tree Collapse file tree 6 files changed +81
-0
lines changed Original file line number Diff line number Diff line change
1
+ # How To Make Chrome Extensions
2
+
3
+ > [ https://youtu.be/Ipa58NVGs_c ] ( https://youtu.be/Ipa58NVGs_c )
4
+
5
+ * Go to ` chrome://extensions/ `
6
+ * Enable Developer mode
7
+ * Load unpacked and select the ` bear ` folder from this project.
8
+
Original file line number Diff line number Diff line change
1
+ window . bears = { }
2
+ chrome . runtime . onMessage . addListener ( function ( request , sender , sendResponse ) {
3
+ window . bears [ request . url ] = request . count
4
+ } )
5
+
6
+ chrome . browserAction . onClicked . addListener ( function ( tab ) {
7
+ chrome . tabs . create ( { url : 'popup.html' } )
8
+ } )
Original file line number Diff line number Diff line change
1
+ //alert('Grrr.')
2
+ // chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
3
+ // const re = new RegExp('bear', 'gi')
4
+ // const matches = document.documentElement.innerHTML.match(re)
5
+ // sendResponse({count: matches.length})
6
+ // })
7
+
8
+ const re = new RegExp ( 'bear' , 'gi' )
9
+ const matches = document . documentElement . innerHTML . match ( re )
10
+ chrome . runtime . sendMessage ( {
11
+ url : window . location . href ,
12
+ count : matches . length
13
+ } )
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " bear" ,
3
+ "version" : " 1.0" ,
4
+ "manifest_version" : 2 ,
5
+ "content_scripts" : [
6
+ {
7
+ "matches" : [" <all_urls>" ],
8
+ "js" : [" content.js" ]
9
+ }
10
+ ],
11
+ "browser_action" : {
12
+ "default_title" : " Bear"
13
+ },
14
+ "background" : {
15
+ "scripts" : [" background.js" ]
16
+ },
17
+ "permissions" : [" tabs" ]
18
+ }
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Document</ title >
6
+ </ head >
7
+ < body >
8
+ <!-- <button>Count Bears</button> -->
9
+ < script src ="popup.js " charset ="utf-8 "> </ script >
10
+ </ body >
11
+ </ html >
Original file line number Diff line number Diff line change
1
+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
2
+
3
+ const bg = chrome . extension . getBackgroundPage ( )
4
+ Object . keys ( bg . bears ) . forEach ( function ( url ) {
5
+ const div = document . createElement ( 'div' )
6
+ div . textContent = `${ url } : ${ bg . bears [ url ] } `
7
+ document . body . appendChild ( div )
8
+ } )
9
+
10
+ // document.querySelector('button').addEventListener('click', onclick, false)
11
+ //
12
+ // function onclick () {
13
+ // chrome.tabs.query({currentWindow: true, active: true}, function (tabs) {
14
+ // chrome.tabs.sendMessage(tabs[0].id, 'hi', setCount)
15
+ // })
16
+ // }
17
+ //
18
+ // function setCount (res) {
19
+ // const div = document.createElement('div')
20
+ // div.textContent = `${res.count} bears`
21
+ // document.body.appendChild(div)
22
+ // }
23
+ } , false )
You can’t perform that action at this time.
0 commit comments