Skip to content

Commit

Permalink
Prettier, tsconfig, types
Browse files Browse the repository at this point in the history
- add a prettier configuration file
- add a basic tsconfig to appease the typechecker
- added @types
- ran prettier on the files
- checked and confirmed that the builds worked
  • Loading branch information
nicolechung authored Sep 19, 2022
2 parents 9ec9aa9 + 20bd37f commit d89605c
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 48 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
},
"devDependencies": {
"@parcel/config-webextension": "2.7.0",
"@types/react": "^18.0.20",
"@types/react-dom": "^18.0.6",
"@types/webextension-polyfill": "^0.9.1",
"autoprefixer": "10.4.11",
"parcel": "2.7.0",
"postcss": "8.4.16",
Expand Down
3 changes: 0 additions & 3 deletions src/assets/icon.svg

This file was deleted.

15 changes: 7 additions & 8 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
async function getTab() {
const queryOptions = { active: true, currentWindow: true };
const [firstTab] = await chrome.tabs.query(queryOptions);
return firstTab;
const queryOptions = { active: true, currentWindow: true }
const [firstTab] = await chrome.tabs.query(queryOptions)
return firstTab
}

chrome.tabs.onUpdated.addListener(function () {
getTab().then((tab) => {
console.log({ tab });
chrome.scripting.executeScript({
target: { tabId: tab.id, allFrames: true },
file: ["contentScripts/index.tsx"],
});
});
});
files: ['contentScripts/index.tsx'],
})
})
})
44 changes: 21 additions & 23 deletions src/contentScripts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
import browser from "webextension-polyfill";
import browser from 'webextension-polyfill'

interface CustomWindow extends Window {
Run: boolean;
Run: boolean
}

declare let window: CustomWindow;

(function () {
declare let window: CustomWindow
;(function () {
if (window.Run) {
return;
return
}
window.Run = true;
window.Run = true

browser.runtime.onMessage.addListener(({ command }) => {
let url: string | null;
let url: string | null

switch (command) {
case "swap-with-cats":
case 'swap-with-cats':
url = browser.runtime.getURL(
"./up_/assets/nine-koepfer-lpgAlv8I7V8-unsplash.jpg"
);
break;
'./up_/assets/nine-koepfer-lpgAlv8I7V8-unsplash.jpg'
)
break

case "swap-with-dogs":
case 'swap-with-dogs':
url = browser.runtime.getURL(
"./up_/assets/ben-michel-Uyn3kXAaZX8-unsplash.jpg"
);
break;
'./up_/assets/ben-michel-Uyn3kXAaZX8-unsplash.jpg'
)
break

default:
url = null;
return;
url = null
return
}

if (url) {
var images = document.getElementsByTagName("img");
var images = document.getElementsByTagName('img')
for (var i = 0; i < images.length; i++) {
console.log("swapping with image: ", url);
images[i].src = url;
images[i].src = url
}
}
});
})();
})
})()
18 changes: 9 additions & 9 deletions src/popup/Popup.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import browser from "webextension-polyfill";
import browser from 'webextension-polyfill'

let currentTab: any;
let currentTab: any

browser.tabs
.query({ active: true, currentWindow: true })
.then((tabs) => (currentTab = tabs[0]));
.then((tabs) => (currentTab = tabs[0]))

export const Popup = () => {
const handleCats = () => {
browser.tabs.sendMessage(currentTab.id, { command: "swap-with-cats" });
};
browser.tabs.sendMessage(currentTab.id, { command: 'swap-with-cats' })
}

const handleDogs = () => {
browser.tabs.sendMessage(currentTab.id, { command: "swap-with-dogs" });
};
browser.tabs.sendMessage(currentTab.id, { command: 'swap-with-dogs' })
}
return (
<div className="flex flex-col items-center gap-3 justify-center w-48 p-3 bg-gradient-to-r min-h-full from-emerald-500 to-emerald-400">
<button
Expand All @@ -39,5 +39,5 @@ export const Popup = () => {
dogs
</button>
</div>
);
};
)
}
10 changes: 5 additions & 5 deletions src/popup/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRoot } from "react-dom/client";
import { Popup } from "./Popup";
import { createRoot } from 'react-dom/client'
import { Popup } from './Popup'

const container = document.getElementById("root");
const root = createRoot(container); // createRoot(container!) if you use TypeScript
root.render(<Popup />);
const container = document.getElementById('root')
const root = createRoot(container) // createRoot(container!) if you use TypeScript
root.render(<Popup />)
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"esModuleInterop": true
}
}
36 changes: 36 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,37 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/prop-types@*":
version "15.7.5"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==

"@types/react-dom@^18.0.6":
version "18.0.6"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.6.tgz#36652900024842b74607a17786b6662dd1e103a1"
integrity sha512-/5OFZgfIPSwy+YuIBP/FgJnQnsxhZhjjrnxudMddeblOouIodEQ75X14Rr4wGSG/bknL+Omy9iWlLo1u/9GzAA==
dependencies:
"@types/react" "*"

"@types/react@*", "@types/react@^18.0.20":
version "18.0.20"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.20.tgz#e4c36be3a55eb5b456ecf501bd4a00fd4fd0c9ab"
integrity sha512-MWul1teSPxujEHVwZl4a5HxQ9vVNsjTchVA+xRqv/VYGCuKGAU6UhfrTdF5aBefwD1BHUD8i/zq+O/vyCm/FrA==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/scheduler@*":
version "0.16.2"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39"
integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==

"@types/webextension-polyfill@^0.9.1":
version "0.9.1"
resolved "https://registry.yarnpkg.com/@types/webextension-polyfill/-/webextension-polyfill-0.9.1.tgz#fcb5c352e2e461d0287774db89bc326b15b47844"
integrity sha512-6aNzPIhqKlAV9t06nwSH3/veAceYE2dS2RVFZI8V1+UXHqsFNB6cRwxNmheiBvEGRc45E/gyZNzH0xAYIC27KA==

abortcontroller-polyfill@^1.1.9:
version "1.7.3"
resolved "https://registry.yarnpkg.com/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.3.tgz#1b5b487bd6436b5b764fd52a612509702c3144b5"
Expand Down Expand Up @@ -1015,6 +1046,11 @@ csso@^4.2.0:
dependencies:
css-tree "^1.1.2"

csstype@^3.0.2:
version "3.1.1"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.1.tgz#841b532c45c758ee546a11d5bd7b7b473c8c30b9"
integrity sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==

defined@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693"
Expand Down

0 comments on commit d89605c

Please sign in to comment.