-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
102 lines (87 loc) · 3.5 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
let localkey = "miles2";
/* ... */
document.addEventListener('DOMContentLoaded', function () {
let dictString = localStorage.getItem(localkey);
if (!dictString) {
const data = {
"conversation_data": {
"test": ["chhatri leni hai", "chats", [0, 20, 40, 50, 60, 70, 80], ""],
},
"toggleState": false,
"user_name": ''
}
localStorage.setItem(localkey, JSON.stringify(data));
dictString = localStorage.getItem(localkey);
}
const dict = JSON.parse(dictString)
if (dict.toggleState) {
document.getElementById('toggleInput').checked = true;
document.body.classList.add('show-content');
}
document.getElementById('toggleInput').addEventListener('change', function () {
document.body.classList.toggle('show-content');
var dictString = localStorage.getItem(localkey);
const dict = JSON.parse(dictString)
// Save the current toggle state to localStorage
dict.toggleState = this.checked; // Updating the original dict with the modified data
localStorage.setItem(localkey, JSON.stringify(dict));
});
// document.getElementById('openApp').addEventListener('click', function () {
// const url = chrome.runtime.getURL('build/index.html');
// window.open(url, '_blank');
// });
/* h3 */
var name = ''
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { geth3: true }, function (response) {
document.querySelector('h3').innerText = response.otherUserName;
name = response.otherUserName;
// name = otherUser;
if (name !== "" && dict.conversation_data[name]) {
const placeholderValue = dict.conversation_data[name][0];
document.getElementById('myInput').placeholder = placeholderValue;
}
else {
document.getElementById('myInput').placeholder = '';
}
});
});
/* GENERATE REPLY */
document.getElementById('backup').addEventListener('click', () => {
let goal = ''
if (dict.conversation_data[name]) { goal = dict.conversation_data[name][0] }
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { backup: true, goal: goal }, function (response) {
if (dict.conversation_data[name][1] == '') {
dict.conversation_data[name][1] = response.chats
const updatedData = JSON.stringify(dict);
localStorage.setItem(localkey, updatedData);
}
else {
if (dict.conversation_data[name][3] === response.chats) {
}
else {
dict.conversation_data[name][1] = dict.conversation_data[name][3]
dict.conversation_data[name][3] = response.chats
const updatedData = JSON.stringify(dict);
localStorage.setItem(localkey, updatedData);
}
}
});
});
});
/* ... */
chrome.runtime.onMessage.addListener(function (message) {
if (message.clickfrombg) {
let storedDataString = localStorage.getItem(localkey);
let storedData = JSON.parse(storedDataString);
// Assuming otherUserLabel and chats are part of the message
let otherUserLabel = message.otherUserLabel;
let chats = message.chats;
if (storedData.conversation_data[otherUserLabel]) {
storedData.conversation_data[otherUserLabel][3] = chats;
}
localStorage.setItem(localkey, JSON.stringify(storedData));
}
});
});