Skip to content

Commit

Permalink
feat: create extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tshakalekholoane committed Nov 25, 2023
0 parents commit 318581a
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
15 changes: 15 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2023 Tshaka Lekholoane

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Invert

A Chrome extension to invert the colours of a web page.

## Usage

Click the extension button or use the shortcut ⌃ + B or ⌘ + B on macOS to toggle the colours on the page in the current tab.

## Installation

1. Go to the extensions page by entering `chrome://extensions` in a new tab.
2. Enable Developer Mode by clicking the toggle switch in the upper right corner.
3. Click the **Load unpacked** button and select the extension directory.
29 changes: 29 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
chrome.runtime.onInstalled.addListener(() => {
chrome.action.setBadgeText({ text: "OFF" });
});

const toggle = (state) => state === "ON" ? "OFF" : "ON";

chrome.action.onClicked.addListener(async (tab) => {
let state = await chrome.action.getBadgeText({ tabId: tab.id });
state = toggle(state);

await chrome.action.setBadgeText({
tabId: tab.id,
text: state,
});

const details = {
files: ["invert.css"],
target: { tabId: tab.id },
};

switch (state) {
case "ON":
await chrome.scripting.insertCSS(details);
break;
case "OFF":
await chrome.scripting.removeCSS(details);
break;
}
});
Binary file added icons/128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions invert.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
html {
filter: invert(90%);
}
35 changes: 35 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"manifest_version": 3,
"name": "Invert",
"description": "Invert the colour of web pages.",
"version": "1.0",
"icons": {
"16": "icons/16.png",
"32": "icons/32.png",
"48": "icons/48.png",
"128": "icons/128.png"
},
"background": {
"service_worker": "background.js"
},
"action": {
"default_icon": {
"16": "icons/16.png",
"32": "icons/32.png",
"48": "icons/48.png",
"128": "icons/128.png"
}
},
"permissions": [
"scripting",
"activeTab"
],
"commands": {
"_execute_action": {
"suggested_key": {
"default": "Ctrl + B",
"mac": "Command + B"
}
}
}
}

0 comments on commit 318581a

Please sign in to comment.