Skip to content

Commit

Permalink
Add extenstion code
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiuionescu committed Aug 7, 2019
1 parent 99b9e6d commit e31cc8f
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 95 deletions.
Binary file added dist/icon-gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
13 changes: 6 additions & 7 deletions dist/js/background.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.tabs.executeScript({
file: 'dist/js/content.js'
});
chrome.tabs.insertCSS({
file: 'dist/css/dropdown.min.css'
});
chrome.tabs.onActivated.addListener(function(tabId, selectInfo) {
chrome.browserAction.setIcon({path:"dist/icon-gray.png"});
});
chrome.tabs.onUpdated.addListener(function(tabId, selectInfo) {
chrome.browserAction.setIcon({path:"dist/icon-gray.png"});
});


53 changes: 27 additions & 26 deletions dist/js/content.js

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions dist/js/options.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
function refresh() {
chrome.storage.local.get(['active', 'attachInput', 'attachTextarea', 'key'], function (result) {
document.getElementById('active').checked = result.active;
chrome.storage.local.get(['attachInput', 'attachTextarea', 'key'], function (result) {
document.getElementById('attach-to-input').checked = result.attachInput;
document.getElementById('attach-to-textarea').checked = result.attachTextarea;
document.getElementById('key').value = result.key;
});
}
refresh();

document.getElementById('active').addEventListener('change', function(){
chrome.storage.local.set({active: document.getElementById('active').checked}, function() {
refresh();
});

chrome.tabs.executeScript({
file: 'dist/js/content.js'
});
chrome.tabs.insertCSS({
file: 'dist/css/dropdown.min.css'
});

document.getElementById('attach-to-input').addEventListener('change', function(){
chrome.storage.local.set({attachInput: document.getElementById('attach-to-input').checked}, function() {
refresh();
Expand All @@ -27,4 +29,6 @@ document.getElementById('key').addEventListener('blur', function(){
chrome.storage.local.set({key: document.getElementById('key').value}, function() {
refresh();
});
});
});

chrome.browserAction.setIcon({path:"icon.png"});
53 changes: 53 additions & 0 deletions dist/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html style="font-size: 0.7em; background-color: gray;">
<head>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
/>
</head>
<body>
<div style="min-width: 400px;" class="p-1">
<form>
<ul class="list-group list-group-flush">
<li class="list-group-item list-group-item-action">
<div class="form-check">
<input
type="checkbox"
id="attach-to-input"
name="attach-to-input"
class="form-check-input"
/>
<label for="attach-to-input" style="display: block;" class="form-check-label"
>Attach to input elements</label
>
</div>
</li>
<li class="list-group-item list-group-item-action">
<div class="form-check">
<input
type="checkbox"
id="attach-to-textarea"
name="attach-to-textarea"
class="form-check-input"
/>
<label for="attach-to-textarea" style="display: block;" class="form-check-label"
>Attach to textarea elements</label
>
</div>
</li>
<li class="list-group-item list-group-item-action">
<div class="form-group">
<label for="key">Model Key</label>
<input type="text" id="key" name="key" class="form-control" />
</div>
</li>
</ul>
</form>
</div>

<script src="/dist/js/options.js"></script>
</body>
</html>
11 changes: 6 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"name": "TypeLikeMe Typing Assistant",
"version": "0.1.0",
"description": "Chrome extention for leveraging text predictions based on machine learning models trained via typelike.me.",
"version": "0.3.0",
"description": "Chrome extension for leveraging text predictions based on machine learning models trained via typelike.me.",
"manifest_version": 2,
"permissions": ["storage", "activeTab"],
"background": {
"scripts": ["dist/js/background.js"],
"persistent": true
"persistent": false
},
"options_page": "dist/options.html",
"browser_action": {
"default_icon": "favicon.png",
"default_popup": "dist/popup.html",
"default_icon": "dist/icon-gray.png",
"default_title": "Enable TypeLikeMe Assistant"
},
"icons": {
"32": "favicon.png"
"32": "dist/icon.png"
}
}
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typelikeme/chrome-extenstion",
"version": "1.0.0",
"version": "0.2.0",
"description": "Chrome extention for leveraging text predictions based on machine learning models trained via typelike.me",
"main": "src/js/index.ts",
"repository": {
Expand Down Expand Up @@ -31,6 +31,6 @@
"rollup-plugin-node-resolve": "^5.2.0"
},
"dependencies": {
"@typelikeme/tlmjs": "^1.0.3"
"@typelikeme/tlmjs": "^1.0.4"
}
}
41 changes: 18 additions & 23 deletions src/js/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import { Tlm } from "@typelikeme/tlmjs/src/js/tlm";
import { predictor } from "@typelikeme/tlmjs/src/js/index.ts";

let tlm = [];
chrome.storage.local.get(["key", "attachInput", "attachTextarea"], function(
result
) {
let tlm = predictor(result.key);

chrome.storage.local.get(
["active", "key", "attachInput", "attachTextarea"],
function(result) {
let isActive = result.active;
let key = result.key;
let attachToInput = result.attachInput;
let attachToTextarea = result.attachTextarea;

if (isActive) {
let tlm = new Tlm(key);
if (attachToTextarea) {
let textareaList = document.getElementsByTagName("textarea");
for (var i = 0; i < textareaList.length; i++) {
tlm.attach(textareaList[i]);
}
if (result.attachTextarea) {
let textareaList = document.getElementsByTagName("textarea");
for (var i = 0; i < textareaList.length; i++) {
if (!textareaList[i].hasOwnProperty("data-autosuggest_is-input")) {
tlm.attach(textareaList[i]);
}
if (attachToInput) {
let inputList = document.querySelectorAll("input[type=text]");
for (var i = 0; i < inputList.length; i++) {
tlm.attach(inputList[i]);
}
}
}
if (result.attachInput) {
let inputList = document.querySelectorAll("input[type=text]");
for (var i = 0; i < inputList.length; i++) {
if (!inputList[i].hasOwnProperty("data-autosuggest_is-input")) {
tlm.attach(inputList[i]);
}
}
}
);
});
2 changes: 1 addition & 1 deletion tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
</head>
<body>
<textarea></textarea>
<input />
<input type="text"/>
</body>
</html>

0 comments on commit e31cc8f

Please sign in to comment.