Skip to content

Commit

Permalink
✨ Add context menu buttons
Browse files Browse the repository at this point in the history
feat: Add context menu buttons for search on brainly and google
	modified:   README.md
	modified:   manifest.json
	modified:   src/main.js
	modified:   src/popup.js
  • Loading branch information
pedrinslzx committed Sep 23, 2020
1 parent 13f2cee commit d7f3434
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](blob/master/LICENCE)
[![Twitter: pedrinho_lemes](https://img.shields.io/twitter/follow/pedrinho_lemes.svg?style=social)](https://twitter.com/pedrinho_lemes)

> Tools dor your classroom
> Tools for your classroom
### [🏠 Homepage](https://github.com/pedrinholemes/class-tools#readme)

### [✨ Demo](https://github.com/pedrinholemes/class-tools#readme)

## Install

```sh
```
Open chrome
```

## Usage

```sh
```
Enter in form
```

Expand Down
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "Class Tools",
"version": "0.0.2",
"version": "0.0.3",
"description": "Tools for your classroom",
"manifest_version": 2,
"permissions": [
"activeTab",
"storage",
"declarativeContent"
"declarativeContent",
"contextMenus"
],
"page_action": {
"default_popup": "src/popup.html"
Expand Down
25 changes: 24 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,34 @@ var rule2 = {
},
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
actions: [new chrome.declarativeContent.ShowPageAction(), createContextMenuItems()]
};
chrome.runtime.onInstalled.addListener(function (details) {
console.log(details)
chrome.declarativeContent.onPageChanged.removeRules(undefined, function () {
chrome.declarativeContent.onPageChanged.addRules([rule2]);
});
});
function searchOnBrainly(info, tab) {
chrome.tabs.create({
url: "https://brainly.com.br/app/ask?q=" + info.selectionText
});
}
function searchOnGoogle(info, tab) {
chrome.tabs.create({
url: "https://google.com/search?q=" + info.selectionText
});
}
function createContextMenuItems() {
chrome.contextMenus.create({
title: "Pesquisar no Brainly",
contexts: ["selection"],
onclick: searchOnBrainly
});
chrome.contextMenus.create({
title: "Pesquisar no Google",
contexts: ["selection"],
onclick: searchOnGoogle
});
}

14 changes: 9 additions & 5 deletions src/popup.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
const input = document.querySelector('input[name="question"]')
const buttons = {
const btn = {
brainly: document.querySelector('button#brainly'),
google: document.querySelector('button#google')
}

buttons.brainly.addEventListener('click', function () {
window.open(`https://brainly.com.br/app/ask?q=${encodeURI(input.value)}`)
btn.brainly.addEventListener('click', function () {
if (confirm('Tem certeza?')) {
window.open(`https://brainly.com.br/app/ask?q=${encodeURI(input.value)}`)
}
})
buttons.google.addEventListener('click', function () {
window.open(`https://google.com/search?q=${encodeURI(input.value)}`)
btn.google.addEventListener('click', function () {
if (confirm('Tem certeza?')) {
window.open(`https://google.com/search?q=${encodeURI(input.value)}`)
}
})

document.querySelector('form').addEventListener('submit', e => e.preventDefault())

0 comments on commit d7f3434

Please sign in to comment.