added notify-link-clicks, and applications key to beastify

This commit is contained in:
Will Bamberg
2015-09-16 16:51:50 -07:00
parent 418f3bb636
commit 9ccecbf206
9 changed files with 49 additions and 80 deletions

View File

@@ -4,6 +4,12 @@
"name": "Beastify",
"version": "1.0",
"applications": {
"gecko": {
"id": "beastify@mozilla.org"
}
},
"permissions": [
"activeTab"
],

View File

@@ -1 +0,0 @@
insertControls(document.getElementById("right-column"), "Content script controls");

View File

@@ -1,60 +0,0 @@
function insertControls(parentElement, titleText) {
var title = document.createElement("strong");
title.textContent = titleText;
var highlightParaButton = makeButton(
"highlight-para",
"Highlight the paragraph",
toggleParaHighlight);
var showFooButton = makeButton(
"show-foo",
"Get the value of window.foo",
showFoo);
var callConfirmButton = makeButton(
"call-window.confirm",
"Call window.confirm()",
callConfirm);
parentElement.appendChild(title);
parentElement.appendChild(document.createElement("br"));
parentElement.appendChild(highlightParaButton);
parentElement.appendChild(document.createElement("br"));
parentElement.appendChild(showFooButton);
parentElement.appendChild(document.createElement("br"));
parentElement.appendChild(callConfirmButton);
parentElement.appendChild(document.createElement("br"));
}
function makeButton(buttonId, buttonValue, buttonCommand) {
var button = document.createElement("input");
button.setAttribute("type", "button");
button.setAttribute("id", buttonId);
button.setAttribute("value", buttonValue);
button.addEventListener("click", buttonCommand)
return button;
}
// the actual actions
function toggleParaHighlight() {
var pageScriptPara = document.getElementById("page-script-para");
var bgColor = pageScriptPara.style.backgroundColor;
if (bgColor == "blue") {
pageScriptPara.style.backgroundColor = "white";
}
else {
pageScriptPara.style.backgroundColor = "blue";
}
}
function showFoo() {
var output = document.getElementById("output");
output.textContent = "window.foo=" + window.foo;
}
function callConfirm() {
window.confirm("Are you sure?");
}

View File

@@ -1,19 +0,0 @@
{
"manifest_version": 2,
"name": "Content scripting",
"version": "1.0",
"applications": {
"gecko": {
"id": "content-scripts@mozilla.org"
}
},
"content_scripts": [
{
"matches": ["https://mdn.github.io/webextensions-examples/"],
"js": ["insert-controls.js", "content-script.js"]
}
]
}

View File

@@ -0,0 +1 @@
The "link.png" icon is taken from the Geomicons iconset, and is used here under the MIT license: http://opensource.org/licenses/MIT.

View File

@@ -0,0 +1,10 @@
chrome.runtime.onMessage.addListener(notify);
function notify(message) {
chrome.notifications.create({
"type": "basic",
"iconUrl": chrome.extension.getURL("link.png"),
"title": "You clicked a link!",
"message": message.url
});
}

View File

@@ -0,0 +1,8 @@
window.addEventListener("click", notifyExtension);
function notifyExtension(e) {
if (e.target.tagName != "A") {
return;
}
chrome.runtime.sendMessage({"url": e.target.href});
}

BIN
notify-link-clicks/link.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B

View File

@@ -0,0 +1,24 @@
{
"manifest_version": 2,
"name": "Content scripting",
"version": "1.0",
"applications": {
"gecko": {
"id": "notify-link-clicks@mozilla.org"
}
},
"permissions": ["notifications"],
"background": {
"scripts": ["background-script.js"]
},
"content_scripts": [
{
"matches": ["*://*.mozilla.org/*"],
"js": ["content-script.js"]
}
]
}