diff --git a/background_script.js b/background_script.js new file mode 100644 index 0000000..6b84016 --- /dev/null +++ b/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 + }) + } +}) diff --git a/browserAction/index.html b/browserAction/index.html new file mode 100644 index 0000000..94fb240 --- /dev/null +++ b/browserAction/index.html @@ -0,0 +1,12 @@ + + + + +

+ javascript +

+ + + + diff --git a/browserAction/reem-kufi.woff2 b/browserAction/reem-kufi.woff2 new file mode 100644 index 0000000..652b24f Binary files /dev/null and b/browserAction/reem-kufi.woff2 differ diff --git a/browserAction/script.js b/browserAction/script.js new file mode 100644 index 0000000..114f509 --- /dev/null +++ b/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 + }) +}) diff --git a/browserAction/style.css b/browserAction/style.css new file mode 100644 index 0000000..c3e7691 --- /dev/null +++ b/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; +} diff --git a/content_script.js b/content_script.js new file mode 100644 index 0000000..1b2119d --- /dev/null +++ b/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) +}) diff --git a/icons/icon.png b/icons/icon.png new file mode 100644 index 0000000..7b5ffab Binary files /dev/null and b/icons/icon.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..ac979fd --- /dev/null +++ b/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" + } +} diff --git a/options/index.html b/options/index.html new file mode 100644 index 0000000..c33ae33 --- /dev/null +++ b/options/index.html @@ -0,0 +1,6 @@ + + + + +

My content

+ diff --git a/options/script.js b/options/script.js new file mode 100644 index 0000000..58ffbf9 --- /dev/null +++ b/options/script.js @@ -0,0 +1 @@ +document.getElementById('myHeading').style.color = 'red' diff --git a/options/style.css b/options/style.css new file mode 100644 index 0000000..b6b9c78 --- /dev/null +++ b/options/style.css @@ -0,0 +1,3 @@ +h1 { + font-style: italic; +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..637ff55 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "typeface-reem-kufi": { + "version": "0.0.65", + "resolved": "https://registry.npmjs.org/typeface-reem-kufi/-/typeface-reem-kufi-0.0.65.tgz", + "integrity": "sha512-zW2BqCCouJTV2MoOdvrQH8UcRBGuiztVOgbSSN5kDqdnGJmqYQxDPW95ZhpyFG4F41tjoSrlahUK2d1mFCIZkA==" + } + } +}