mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-18 07:18:34 +02:00
added notify-link-clicks, and applications key to beastify
This commit is contained in:
@@ -4,6 +4,12 @@
|
||||
"name": "Beastify",
|
||||
"version": "1.0",
|
||||
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"id": "beastify@mozilla.org"
|
||||
}
|
||||
},
|
||||
|
||||
"permissions": [
|
||||
"activeTab"
|
||||
],
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
insertControls(document.getElementById("right-column"), "Content script controls");
|
||||
@@ -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?");
|
||||
}
|
||||
@@ -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"]
|
||||
}
|
||||
]
|
||||
}
|
||||
1
notify-link-clicks/LICENSE
Normal file
1
notify-link-clicks/LICENSE
Normal 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.
|
||||
10
notify-link-clicks/background-script.js
Normal file
10
notify-link-clicks/background-script.js
Normal 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
|
||||
});
|
||||
}
|
||||
8
notify-link-clicks/content-script.js
Normal file
8
notify-link-clicks/content-script.js
Normal 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
BIN
notify-link-clicks/link.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 596 B |
24
notify-link-clicks/manifest.json
Normal file
24
notify-link-clicks/manifest.json
Normal 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"]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user