Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Jan 5, 2019
0 parents commit 19e9fcb
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 0 deletions.
17 changes: 17 additions & 0 deletions background_script.js
@@ -0,0 +1,17 @@
browser.runtime.onMessage.addListener(message => {
let {
idea,
charge
} = message

if (idea == 'person did a do') {
let {
host,
javascript
} = charge

browser.storage.local.set({
[host]: javascript
})
}
})
12 changes: 12 additions & 0 deletions browserAction/index.html
@@ -0,0 +1,12 @@
<!doctype html>
<meta charset=utf-8>
<link href=style.css rel=stylesheet>

<p>
javascript
</p>

<textarea id=javascript rows=20>
</textarea>

<script src=script.js></script>
Binary file added browserAction/reem-kufi.woff2
Binary file not shown.
35 changes: 35 additions & 0 deletions browserAction/script.js
@@ -0,0 +1,35 @@
let javascript = document.getElementById('javascript')
let defaultCode =
`// enter some
// javascript here
// and it will
// run on every page
// on this domain (location.host)`

async function getActiveTab () {
let tabs = await browser.tabs.query({
active: true,
currentWindow: true
})

return tabs[0]
}

async function getHost () {
let {url} = await getActiveTab()
let {host} = new URL(url)
return host
}

getHost().then(async host => {
let store = await browser.storage.local.get()
let code = store[await getHost()] || defaultCode
javascript.value = code
})

javascript.addEventListener('input', async event => {
let host = await getHost()
browser.storage.local.set({
[host]: javascript.value
})
})
30 changes: 30 additions & 0 deletions browserAction/style.css
@@ -0,0 +1,30 @@
@font-face {
font-family: "Reem Kufi";
font-style: normal;
font-display: swap;
font-weight: 400;
src:
local('Reem Kufi Regular '),
local('Reem Kufi-Regular'),
url('./reem-kufi.woff2') format('woff2');
}

* {
box-sizing: border-box;
}

body {
background: #f7df1e;
font-family: neutra text, neutra text bold, reem kufi, sans-serif;
font-weight: 900;
min-width: 25vw;
}

textarea {
border: none;
width: 100%;
background: #f7df1e;
font-weight: bold;
border: 2px dotted black;
padding: .5em;
}
11 changes: 11 additions & 0 deletions content_script.js
@@ -0,0 +1,11 @@
browser.storage.local.get().then(store => {
let javascript = store[location.host]

if (!javascript) {
return
}

let script = document.createElement('script')
script.textContent = javascript
document.body.append(script)
})
Binary file added icons/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions manifest.json
@@ -0,0 +1,39 @@
{
"manifest_version": 2,
"name": "javascript",
"description": "add javascript that will run on this domain",
"version": "0.0.1",
"icons": {
"64": "icons/icon.png"
},
"permissions": [
"activeTab",
"storage",
"unlimitedStorage"
],
"background": {
"scripts": [
"background_script.js"
]
},
"content_scripts": [
{
"matches": [
"*://*/*"
],
"js": [
"content_script.js"
]
}
],
"browser_action": {
"default_icon": {
"64": "icons/icon.png"
},
"default_popup": "browserAction/index.html",
"default_title": "javascript"
},
"options_ui": {
"page": "options/index.html"
}
}
6 changes: 6 additions & 0 deletions options/index.html
@@ -0,0 +1,6 @@
<!doctype html>
<html lang="en">
<meta charset="UTF-8">
<link href="style.css" rel="stylesheet" />
<h1 id="myHeading">My content</h1>
<script src="script.js"></script>
1 change: 1 addition & 0 deletions options/script.js
@@ -0,0 +1 @@
document.getElementById('myHeading').style.color = 'red'
3 changes: 3 additions & 0 deletions options/style.css
@@ -0,0 +1,3 @@
h1 {
font-style: italic;
}
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19e9fcb

Please sign in to comment.