-
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.
* Can type emoji name, up/down arrow, enter to copy to keyboard * TODO: Improve UI/UX, add more search terms for emojis to weighted index
- Loading branch information
Showing
11 changed files
with
286 additions
and
22 deletions.
There are no files selected for viewing
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
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,2 +1,110 @@ | ||
import '../img/icon-128.png' | ||
import '../img/icon-34.png' | ||
import '../resources/AllEmojis.txt' | ||
|
||
const $ = require("jquery"); | ||
import Fuse from 'fuse.js' | ||
|
||
var emojiJSON = null; | ||
var fuse = null; | ||
|
||
chrome.runtime.onConnect.addListener(function (port) { | ||
console.log(`Connected .....`); | ||
// console.log(port) | ||
|
||
port.onMessage.addListener(function (msg) { | ||
// console.log("message recieved: "); | ||
console.log(msg); | ||
switch (msg.command) { | ||
case 'fetchEmoji': | ||
getAllEmojis(emojiList => { | ||
port.postMessage(emojiList) | ||
}) | ||
case 'emojiMatchString': | ||
getMatchingEmojis(msg.data, matchingEmojiList => { | ||
port.postMessage(matchingEmojiList) | ||
}) | ||
break; | ||
default: | ||
getMatchingEmojis(msg) | ||
break; | ||
} | ||
// port.postMessage(getMatchingEmojis(msg)); | ||
}); | ||
}) | ||
chrome.runtime.onInstalled.addListener(e => { | ||
console.log("emoji-insterter background started up!") | ||
console.log(e) | ||
}) | ||
|
||
function getAllEmojis(callback) { | ||
if (emojiJSON != null) { | ||
callback(emojiJSON) | ||
} else { | ||
$.getJSON(chrome.runtime.getURL("./AllEmojis.txt"), data => { | ||
emojiJSON = data; | ||
callback(data); | ||
}) | ||
} | ||
} | ||
|
||
function getMatchingEmojis(string, callback) { | ||
var results = null; | ||
if (emojiJSON != null) { | ||
fuse = makeSearchIndex(fuse, emojiJSON); | ||
results = fuse.search(string) | ||
callback(results) | ||
} else { | ||
$.getJSON(chrome.runtime.getURL("./AllEmojis.txt"), data => { | ||
fuse = makeSearchIndex(fuse, data); | ||
results = fuse.search(string) | ||
callback(results) | ||
}) | ||
} | ||
} | ||
|
||
|
||
/** | ||
* | ||
* @param {Fuse} inIndexVar, a inValue fuse index, is either null or filled | ||
* @param {*} data , a textfile to be converted to a fuse search index in inIndexVar | ||
*/ | ||
function makeSearchIndex(inIndexVar, data) { | ||
|
||
if (inIndexVar == null) { | ||
const fuseOptions = { | ||
isCaseSensitive: false, | ||
// includeScore: false, | ||
// shouldSort: true, | ||
includeMatches: false, | ||
findAllMatches: true, | ||
// minMatchCharLength: 1, | ||
// location: 0, | ||
threshold: 0.3, | ||
distance: 10, | ||
useExtendedSearch: true, | ||
ignoreLocation: true, | ||
// ignoreFieldNorm: false, | ||
keys: [ | ||
"name" | ||
] | ||
}; | ||
inIndexVar = new Fuse(data, fuseOptions) | ||
} | ||
return inIndexVar; | ||
} | ||
|
||
function getSearchIndexMatches(string) { | ||
if (fuse == null) { | ||
fuse = new Fuse() | ||
} | ||
} | ||
|
||
|
||
// $.getJSON('../resources/AllEmojis.txt', data => { | ||
// console.log(data) | ||
// }) | ||
|
||
// $.getJSON(chrome.runtime.getURL("./AllEmojis.txt"), data => { | ||
// console.log(data) | ||
// }) |
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,2 @@ | ||
const fetchEmojiListPort = "fetchEmojiListPort"; | ||
export default fetchEmojiListPort; |
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
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
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
Large diffs are not rendered by default.
Oops, something went wrong.