generated from Debdut/browser-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb26797
commit bf97ec0
Showing
11 changed files
with
81 additions
and
63 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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
xcode/ | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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,59 +1,68 @@ | ||
import React from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import { JiraIssue } from "@src/lib/jira"; | ||
import browser from 'webextension-polyfill'; | ||
import autocomplete, { AutocompleteItem } from "autocompleter"; | ||
|
||
import "./style.css"; | ||
|
||
async function init() { | ||
console.log(document.URL) | ||
|
||
if (!document.URL.startsWith("https://frontend.minute7.com")) { | ||
return; | ||
async function getDescriptionField(): Promise<HTMLTextAreaElement> | ||
{ | ||
var te: HTMLTextAreaElement | null = null; | ||
while (te == null) { | ||
te = document.getElementsByTagName("textarea")[0]; | ||
await new Promise(r => setTimeout(r, 100)); | ||
} | ||
|
||
const issues: JiraIssue[] = await browser.runtime.sendMessage({ type: "jiraSuggestions" }); | ||
|
||
console.log(issues); | ||
type MyItem = JiraIssue & AutocompleteItem; | ||
const te = document.getElementsByTagName("textarea")[0]; | ||
return te; | ||
} | ||
|
||
async function init() { | ||
if (!document.URL.startsWith("https://frontend.minute7.com")) { | ||
return; | ||
} | ||
|
||
const autocompleteContainer = document.createElement("div"); | ||
autocompleteContainer.classList.add("autocomplete"); | ||
autocompleteContainer.role = "listbox"; | ||
autocompleteContainer.style.backgroundColor = "white"; | ||
autocompleteContainer.style.zIndex = "1"; | ||
document.body.appendChild(autocompleteContainer); | ||
|
||
|
||
const textArea = await getDescriptionField(); | ||
type MyItem = JiraIssue & AutocompleteItem; | ||
autocomplete<MyItem>({ | ||
input: te, | ||
input: textArea, | ||
emptyMsg: "No issues found", | ||
fetch: (text: string, update: (items: JiraIssue[]) => void) => { | ||
text = text.toLowerCase(); | ||
const suggestions = issues.filter(n => n.summary.toLowerCase().includes(text)); | ||
update(suggestions); | ||
browser.runtime.sendMessage({ type: "jiraSuggestions", text: text }).then( | ||
(response: JiraIssue[]) => { | ||
update(response); | ||
} | ||
); | ||
}, | ||
onSelect: (item: JiraIssue) => { | ||
te.value = `${item.key} - ${item.summary}`; | ||
textArea.value = `${item.key} - ${item.summary.replaceAll('<b>', '').replaceAll('</b>', '')}`; | ||
}, | ||
render: (item: JiraIssue, currentValue: string) => { | ||
const div = document.createElement("div"); | ||
div.classList.add("autocomplete-entry"); | ||
div.textContent = `${item.key} - ${item.summary}`; | ||
|
||
const img = document.createElement("img"); | ||
img.src = item.iconUrl; | ||
div.appendChild(img); | ||
|
||
const p = document.createElement("div"); | ||
|
||
p.innerHTML = `${item.key} - ${item.summary}`; | ||
if (item.assignee) { | ||
div.textContent += ` (${item.assignee})`; | ||
p.innerHTML += ` (${item.assignee})`; | ||
} | ||
|
||
div.appendChild(p); | ||
|
||
return div; | ||
}, | ||
click: e => e.fetch(), | ||
container: autocompleteContainer, | ||
}); | ||
|
||
|
||
|
||
} | ||
|
||
document.addEventListener("DOMContentLoaded", init); |
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