-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e25e4f
commit 7cda06b
Showing
8 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# Project exclude paths | ||
/dist/ | ||
/node_modules/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>Getting Started</title> | ||
</head> | ||
<body> | ||
<script src="main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<link rel="stylesheet" href="url.css"/> | ||
</head> | ||
|
||
<body> | ||
<div id="popup-content"> | ||
<input id="qr_text" type="text" /> | ||
<div class="button create">Create</div> | ||
<div class="button reset">Reset</div> | ||
</div> | ||
<div id="error-content" class="hidden"> | ||
<p>Can't add QR code to this web page.</p><p>Try a different page.</p> | ||
</div> | ||
<script src="popup.js"></script> | ||
</body> | ||
|
||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "EmbedQR", | ||
"version": "1.0", | ||
|
||
"description": "Adds a QR code to the webpage.", | ||
|
||
"permissions": [ | ||
"activeTab" | ||
], | ||
|
||
"browser_action": { | ||
"default_icon": "icons/qr32.png", | ||
"default_title": "EmbedQR", | ||
"default_popup": "insert_url.html" | ||
}, | ||
|
||
"content_scripts": [ | ||
{ | ||
"matches": ["<all_urls>"], | ||
"js": ["main.js"] | ||
} | ||
] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
|
||
/** | ||
* Listen for clicks on the buttons, and send the appropriate message to | ||
* the content script in the page. | ||
*/ | ||
function listenForClicks() { | ||
document.addEventListener("click", (e) => { | ||
|
||
|
||
/** | ||
* Insert the page-hiding CSS into the active tab, | ||
* then get the beast URL and | ||
* send a "beastify" message to the content script in the active tab. | ||
*/ | ||
function create(tabs) { | ||
txt_qr = document.getElementById('qr_text'); | ||
console.log(txt_qr.value); | ||
browser.tabs.sendMessage(tabs[0].id, { | ||
command: "dispqr", | ||
qrText: txt_qr.value | ||
}); | ||
// browser.tabs.insertCSS({code: hidePage}).then(() => { | ||
// let url = beastNameToURL(e.target.textContent); | ||
// browser.tabs.sendMessage(tabs[0].id, { | ||
// command: "beastify", | ||
// beastURL: url | ||
// }); | ||
// }); | ||
} | ||
|
||
/** | ||
* Remove the page-hiding CSS from the active tab, | ||
* send a "reset" message to the content script in the active tab. | ||
*/ | ||
function reset(tabs) { | ||
browser.tabs.sendMessage(tabs[0].id, { | ||
command: "reset", | ||
}); | ||
} | ||
|
||
/** | ||
* Just log the error to the console. | ||
*/ | ||
function reportError(error) { | ||
console.error(`Could not beastify: ${error}`); | ||
} | ||
|
||
/** | ||
* Get the active tab, | ||
* then call "beastify()" or "reset()" as appropriate. | ||
*/ | ||
if (e.target.classList.contains("create")) { | ||
browser.tabs.query({active: true, currentWindow: true}) | ||
.then(create) | ||
.catch(reportError); | ||
} | ||
else if (e.target.classList.contains("reset")) { | ||
browser.tabs.query({active: true, currentWindow: true}) | ||
.then(reset) | ||
.catch(reportError); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* There was an error executing the script. | ||
* Display the popup's error message, and hide the normal UI. | ||
*/ | ||
function reportExecuteScriptError(error) { | ||
document.querySelector("#popup-content").classList.add("hidden"); | ||
document.querySelector("#error-content").classList.remove("hidden"); | ||
console.error(`Failed to execute qr content script: ${error.message}`); | ||
} | ||
|
||
/** | ||
* When the popup loads, inject a content script into the active tab, | ||
* and add a click handler. | ||
* If we couldn't inject the script, handle the error. | ||
*/ | ||
browser.tabs.executeScript({file: "main.js"}) | ||
.then(listenForClicks) | ||
.catch(reportExecuteScriptError); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
html, body { | ||
width: 100px; | ||
} | ||
|
||
.hidden { | ||
display: none; | ||
} | ||
|
||
.button { | ||
margin: 3% auto; | ||
padding: 4px; | ||
text-align: center; | ||
font-size: 1.5em; | ||
cursor: pointer; | ||
} | ||
|
||
.create:hover { | ||
background-color: #CFF2F2; | ||
} | ||
|
||
.create { | ||
background-color: #E5F2F2; | ||
} | ||
|
||
.reset { | ||
background-color: #FBFBC9; | ||
} | ||
|
||
.reset:hover { | ||
background-color: #EAEA9D; | ||
} |