Skip to content

Commit

Permalink
added dist
Browse files Browse the repository at this point in the history
  • Loading branch information
aniquetahir committed Sep 1, 2020
1 parent 7e25e4f commit 7cda06b
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Project exclude paths
/dist/
/node_modules/
Binary file added dist/icons/qr32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions dist/index.html
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>
20 changes: 20 additions & 0 deletions dist/insert_url.html
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>
16 changes: 16 additions & 0 deletions dist/main.js

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions dist/manifest.json
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"]
}
]

}
83 changes: 83 additions & 0 deletions dist/popup.js
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);
31 changes: 31 additions & 0 deletions dist/url.css
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;
}

0 comments on commit 7cda06b

Please sign in to comment.