Skip to content

Commit 9b727b5

Browse files
[Add] disable states of buttons
1 parent 5de6fad commit 9b727b5

File tree

4 files changed

+34
-42
lines changed

4 files changed

+34
-42
lines changed

Apps/Web/AI_Recorder/background/back.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -165,30 +165,3 @@ browserAppData.runtime.onInstalled.addListener(function (details) {
165165
console.log("Recorder Installed");
166166
}
167167
});
168-
169-
browserAppData.runtime.onMessage.addListener(
170-
function(request, sender, sendResponse) {
171-
if (request.apiName == 'ai_single_action') {
172-
var url = `${metaData.url}/ai_record_single_action/`
173-
fetch(url, {
174-
method: "POST",
175-
headers: {
176-
// "Content-Type": "application/json",
177-
"X-Api-Key": metaData.apiKey,
178-
},
179-
body: request.data,
180-
})
181-
.then(response => response.json())
182-
.then(text => {
183-
console.log(text);
184-
sendResponse(text);
185-
})
186-
.catch(error => {
187-
console.error(error);
188-
sendResponse("error");
189-
})
190-
191-
return true; // Will respond asynchronously.
192-
}
193-
}
194-
);

Apps/Web/AI_Recorder/background/back_reocrder.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
var metaData = {};
32

43
fetch("./data.json")
@@ -56,6 +55,10 @@ async function fetchAIData(idx, command, value, url, document){
5655
})
5756
return;
5857
}
58+
recorded_actions[idx] = 'empty';
59+
browserAppData.storage.local.set({
60+
recorded_actions: recorded_actions,
61+
})
5962
let validate_full_text_by_ai = false
6063
if (command === 'validate full text by ai'){
6164
command = 'validate full text';
@@ -85,17 +88,11 @@ async function fetchAIData(idx, command, value, url, document){
8588
let response = resp.ai_choices;
8689

8790
if (validate_full_text_by_ai){
88-
// let text_classifier = await browserAppData.runtime.sendMessage({
89-
// action: 'classify',
90-
// text: value,
91-
// });
9291
let text_classifier = await browserAppData.runtime.sendMessage({
9392
action: 'content_classify',
9493
text: value,
9594
});
9695

97-
// let text_classifier = await classify(value);
98-
9996
console.log("text_classifier", text_classifier);
10097
let label = text_classifier[0].label;
10198
label = label.charAt(0).toUpperCase() + label.slice(1).toLowerCase();

Apps/Web/AI_Recorder/panel/assets/js/background/recorder.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ class BackgroundRecorder {
1414
this.contentWindowId = -1;
1515
this.attached = false;
1616
this.rebind();
17+
setInterval(async ()=>{
18+
if (!this.attached) return;
19+
browserAppData.storage.local.get(null, function (result) {
20+
if (result.recorded_actions.length === 0) return;
21+
console.log("Opacity =================", result.recorded_actions);
22+
for(let i = 0; i < result.recorded_actions.length; i++){
23+
if (result.recorded_actions[i] === 'empty'){
24+
console.log("Opacity 2222 =================", result.recorded_actions);
25+
$("#record_label").text("Waiting...");
26+
$("#record").attr('disabled', true).css('opacity',0.5);
27+
return;
28+
}
29+
}
30+
$("#record").removeAttr('disabled').css('opacity',1);
31+
$("#record_label").text("Stop");
32+
})
33+
return;
34+
}, 500)
1735
}
1836

1937
/* Bind initial time */

Apps/Web/AI_Recorder/panel/assets/js/custom.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ var CustomFunction = {
428428
// This Function is called when Record_stop button is pressed
429429
SaveCaseDataAsJson() {
430430
setTimeout(()=>{ // Setting 0.5 sec so that the last action is saved properly in storage.local
431-
chrome.storage.local.get(null, function (result) {
431+
browserAppData.storage.local.get(null, function (result) {
432432
try {
433433
if (!result.recorded_actions) return;
434434
CustomFunction.FetchChromeCaseData()
@@ -1021,7 +1021,7 @@ var CustomFunction = {
10211021

10221022
async FetchChromeCaseData() {
10231023
CustomFunction.caseDataArr = {};
1024-
result = await chrome.storage.local.get(null);
1024+
result = await browserAppData.storage.local.get(null);
10251025
try {
10261026
if (result.case_data) {
10271027
CustomFunction.caseDataArr = result.case_data;
@@ -1296,7 +1296,7 @@ var CustomFunction = {
12961296

12971297
/* Mange playing speed */
12981298
/* initial time set speed */
1299-
chrome.storage.local.get(null, function (result) {
1299+
browserAppData.storage.local.get(null, function (result) {
13001300
try {
13011301
if (result.speed_data) {
13021302
var speed_data = result.speed_data;
@@ -1389,6 +1389,7 @@ var CustomFunction = {
13891389
/* Save all newlly recorded actions with old actions and auto naming */
13901390
$(document).on('click', '#save_button', async function () {
13911391
$('#save_label').text('Saving...');
1392+
$("#save_button").attr('disabled', true).css('opacity',0.5);
13921393
CustomFunction.FetchChromeCaseData()
13931394
.then(async ()=>{
13941395
var result = await browserAppData.storage.local.get(["meta_data"]);
@@ -1418,7 +1419,10 @@ var CustomFunction = {
14181419
success: function(response) {
14191420
console.log(response);
14201421
$('#save_label').text('Success!');
1421-
setTimeout(()=>$('#save_label').text('Save'),1500)
1422+
setTimeout(()=>{
1423+
$('#save_label').text('Save');
1424+
$("#save_button").removeAttr('disabled').css('opacity',1);
1425+
},1500)
14221426
},
14231427
error: function(jqXHR, textStatus, errorThrown) {
14241428
console.log(errorThrown);
@@ -1819,7 +1823,7 @@ var CustomFunction = {
18191823
selectedCase = $(this).data('mainindex'); //action
18201824
selectedStep = $(this).data('stepindex');
18211825

1822-
/* Update the chrome case date as disable */
1826+
/* Update the browserAppData case date as disable */
18231827
var textValue = 1;
18241828
var case_command = 'is_disable';
18251829
var case_index = $(this).data('mainindex');
@@ -1881,7 +1885,7 @@ var CustomFunction = {
18811885

18821886
if (!$('.parent_step' + selectedStep).hasClass('disabled-case')) {
18831887

1884-
/* Update the chrome case date as disable */
1888+
/* Update the browserAppData case date as disable */
18851889
var textValue = 0;
18861890
var case_command = 'is_disable';
18871891
var case_index = $(this).data('mainindex');
@@ -2327,7 +2331,7 @@ var CustomFunction = {
23272331
document.getElementById(section).style.display = "block";
23282332
})
23292333

2330-
chrome.storage.local.get(null, function (result) {
2334+
browserAppData.storage.local.get(null, function (result) {
23312335
try {
23322336
if (result.is_initial_app_open) {
23332337
$('.close_main_page').trigger('click');
@@ -2342,7 +2346,7 @@ var CustomFunction = {
23422346

23432347
InitialTimeCheckAuthUserOrNot() {
23442348
/* fetch username and password for browser storage */
2345-
chrome.storage.local.get(null, function (result) {
2349+
browserAppData.storage.local.get(null, function (result) {
23462350
try {
23472351
if (result.auth_data) {
23482352
var auth_data = result.auth_data;

0 commit comments

Comments
 (0)