-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from roymckenzie/bugfix/runtime-error
Update for Google Chrome Extensions manifest v3
- Loading branch information
Showing
13 changed files
with
279 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.DS_Store | ||
.DS_Store | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"target": "ES2020", | ||
"checkJs": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"devDependencies": { | ||
"@types/chrome": "^0.0.248" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Builds a context menu in Chrome. | ||
* | ||
* @param {SanitizeAndCopyContextMenuMessage} message | ||
* | ||
* @since 0.0.2 | ||
*/ | ||
const handleContextMenu = (message) => { | ||
if (message.type !== "sanitizeAndCopyContextMenu") return; | ||
|
||
chrome.contextMenus.removeAll(); | ||
|
||
if (!message.shouldSanitizeSelection) { | ||
return; | ||
} | ||
|
||
chrome.contextMenus.create({ | ||
id: "sanitizeAndCopyContextMenuItem", | ||
title: "Sanitize and copy", | ||
type: "normal", | ||
contexts: ["selection"], | ||
}); | ||
|
||
chrome.contextMenus.onClicked.addListener((info, tab) => { | ||
if (!tab) return; | ||
if (!tab.id) return; | ||
if (info.menuItemId !== "sanitizeAndCopyContextMenuItem") return; | ||
|
||
chrome.tabs.sendMessage(tab.id, { | ||
type: "sanitizeAndCopyContextMenuItemAction", | ||
text: message.textSelection, | ||
}); | ||
}); | ||
}; | ||
|
||
chrome.runtime.onMessage.addListener(handleContextMenu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Removes zero-width characters from `text`. | ||
* | ||
* @param {string} text - String to sanitize. | ||
* @returns Sanitized string. | ||
*/ | ||
const sanitize = (text) => { | ||
return [...text] | ||
.filter((char) => { | ||
const unicodeCode = char.codePointAt(0); | ||
return !zeroWidthCharacterCodes.includes(unicodeCode); | ||
}) | ||
.join(""); | ||
}; | ||
|
||
// https://stackoverflow.com/a/18455088/6591929 | ||
/** | ||
* Copies `text` to clipboard. | ||
* | ||
* @param {string} text - String to copy to clipboard. | ||
*/ | ||
const copyTextToClipboard = (text) => { | ||
const textArea = document.createElement("textarea"); | ||
textArea.setAttribute("name", "copyTextArea"); | ||
textArea.textContent = text; | ||
|
||
const body = document.body; | ||
body.appendChild(textArea); | ||
|
||
textArea.select(); | ||
document.execCommand("copy"); | ||
|
||
body.removeChild(textArea); | ||
}; |
Oops, something went wrong.