Skip to content

Commit

Permalink
disable button while working
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjleo committed Dec 28, 2019
1 parent 3981572 commit b9003a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions chrome-extension/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ async function classify(documentRepresentation, tab) {
const inputs = getInputs(documentRepresentation, words, tags);
const predictions = await model.predict(inputs).data();
chrome.tabs.sendMessage(tab.id, {text: 'visualize', predictions: predictions});
chrome.runtime.sendMessage({text: 'enableButton'});
}
2 changes: 1 addition & 1 deletion chrome-extension/src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</style>
</head>
<body>
<button id="extractContent">Extract content</button>
<button id="highlightContent">Highlight content</button>
<script src="popup.js"></script>
</body>
</html>
19 changes: 15 additions & 4 deletions chrome-extension/src/popup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
const extractContentButton = document.getElementById('extractContent');
const highlightContentButton = document.getElementById('highlightContent');

extractContentButton.onclick = function(_element) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {text: "sendDocumentRepresentation"});
highlightContentButton.onclick = function(_element) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {text: "sendDocumentRepresentation"});

// disable button
highlightContentButton.textContent = "Working...";
highlightContentButton.disabled = true;
});
};

chrome.runtime.onMessage.addListener(function (msg, sender, _sendResponse) {
if (msg.text === 'enableButton') {
highlightContentButton.textContent = "Highlight content";
highlightContentButton.disabled = false;
}
});

0 comments on commit b9003a3

Please sign in to comment.