Skip to content

Commit

Permalink
2:10
Browse files Browse the repository at this point in the history
  • Loading branch information
AP authored and AP committed Apr 16, 2020
1 parent 6a60e3b commit 0a5eff9
Show file tree
Hide file tree
Showing 6 changed files with 5,832 additions and 23 deletions.
64 changes: 43 additions & 21 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@

chrome.runtime.onInstalled.addListener(function() {
chrome.tabs.executeScript({
file: 'contentScript.js'
});
chrome.contextMenus.create({
"id": "ContextMenu",
"title": "Context Menu",
"contexts": ["selection"]
});
});
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'developer.chrome.com'},
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);

function commentsPopup() {
chrome.tabs.executeScript({
code: 'console.log(document)'
// code: 'comment();'
// file: 'contentScript.js',
// code: `let menu = document.createElement("div");
// menu.innerHTML = ('<div id="comment-menu">
// <input id="comment-field"></input>
// <button>Add comment</button>
// </div>');
// document.body.appendChild(menu);
// console.log(document)`
});

let comment = prompt('enter a comment');
}

chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
"id": "ContextMenu",
"title": "Annotate",
"contexts": ["all"],
});
});

chrome.contextMenus.onClicked.addListener(function() {
commentsPopup();
});

chrome.runtime.onMessage.addListener(function() {
chrome.tabs.executeScript({
file: 'contentScript.js'
});
});

// document.querySelector('#button').addEventListener('click', function() {
// console.log(this);
// })
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'developer.chrome.com'},
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
11 changes: 10 additions & 1 deletion contentScript.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

function comment() {
let menu = document.createElement("div");
menu.innerHTML = (`<div id="comment-menu">
<input id="comment-field"></input>
<button>Add comment</button>
console.log(document)
</div>`);
document.body.appendChild(menu);
}
comment();

console.log(document)
6 changes: 6 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"content_scripts": [
{
"matches": ["http://www.google.com/*"],
"js": ["contentScript.js"]
}
],
"manifest_version": 2
}
2 changes: 1 addition & 1 deletion popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let x = db
});
})
.then(function (data) {
data.forEach((doc) => {
data.docs.forEach((doc) => {
const a = document.createElement('a')
a.target = '_blank';
a.href = doc.url
Expand Down
Loading

0 comments on commit 0a5eff9

Please sign in to comment.