-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
180 lines (151 loc) · 5.68 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
let MaterialGroup;
let Country;
let Price;
let PR;
let PRNumber;
let button = document.getElementById("onoffbutton");
let buttonState = 'on';
chrome.storage.sync.get(["PRNumber"], function (data) {
document.getElementById("prnumber").textContent = data.PRNumber;
PRNumber = data.PRNumber
});
chrome.storage.sync.get(["materialGroup"], function (data) {
document.getElementById("material-group").textContent = data.materialGroup;
MaterialGroup = data.materialGroup
});
chrome.storage.sync.get(["country"], function (data) {
if (data.country === 'Fed'){
document.getElementById("country").textContent = 'Russian Federation';
}
else{
document.getElementById("country").textContent = data.country;
}
Country = data.country
});
chrome.storage.sync.get(["price"], function (data) {
let number = parseInt(data.price, 10); // Converts the string to an integer
let formattedNumber = new Intl.NumberFormat('en-US', {
maximumFractionDigits: 0,
useGrouping: true,
groupingSeparator: ' '
}).format(number);
document.getElementById("price").textContent = formattedNumber;
Price = data.price
});
chrome.storage.sync.get(["valuta"], function (data) {
document.getElementById("valuta").textContent = data.valuta;
});
chrome.storage.sync.get(["MaterialGroupName"], function (data) {
document.getElementById("MaterialGroupName").textContent = data.MaterialGroupName;
});
// This function will be injected into the active tab
function pasteMaterialGroup() {
chrome.storage.sync.get(["materialGroup"], function (data) {
// Paste the MaterialGroup value wherever needed on www.howdoc.no
console.log("Material Group:", data.materialGroup);
});
chrome.storage.sync.get(["country"], function (data) {
// Paste the MaterialGroup value wherever needed on www.howdoc.no
console.log("county:", data.country);
});
chrome.storage.sync.get(["price"], function (data) {
// Paste the MaterialGroup value wherever needed on www.howdoc.no
console.log("price:", data.price);
});
}
//button copy at Material
let DownloadButtonCopyMaterial = document.getElementById("buttonmaterial")
DownloadButtonCopyMaterial.addEventListener("click", CopyMaterialFunction);
function CopyMaterialFunction()
{
let SpanBanner2 = document.getElementById("copied2banner")
SpanBanner2.classList.add("copied-info")
SpanBanner2.innerHTML = `\n \n <span>\n <img src="copiedinfo.png" /> </span>`
navigator.clipboard.writeText(MaterialGroup);
setTimeout(function(){
SpanBanner2.classList.remove("copied-info")
SpanBanner2.innerHTML = `\n \n <span>\n </span>`
},2500)
}
//button copy at Country
let DownloadButtonCopyCountry = document.getElementById("buttoncountry")
DownloadButtonCopyCountry.addEventListener("click", CopyCountryFunction);
function CopyCountryFunction()
{
let SpanBanner3 = document.getElementById("copied3banner")
SpanBanner3.classList.add("copied-info")
SpanBanner3.innerHTML = `\n \n <span>\n <img src="copiedinfo.png" /> </span>`
if (Country === 'Fed') {
navigator.clipboard.writeText('Russian Federation');
}
else {
navigator.clipboard.writeText(Country);
}
setTimeout(function(){
SpanBanner3.classList.remove("copied-info")
SpanBanner3.innerHTML = `\n \n <span>\n </span>`
},2500)
}
//Button copy at Price
let DownloadButtonCopyPrice = document.getElementById("buttonprice")
DownloadButtonCopyPrice.addEventListener("click", CopyPriceFunction);
function CopyPriceFunction()
{
let SpanBanner4 = document.getElementById("copied4banner")
SpanBanner4.classList.add("copied-info")
SpanBanner4.innerHTML = `\n \n <span>\n <img src="copiedinfo.png" /> </span>`
navigator.clipboard.writeText(Price);
setTimeout(function(){
SpanBanner4.classList.remove("copied-info")
SpanBanner4.innerHTML = `\n \n <span>\n </span>`
},2500)
}
//button copy PR
let DownloadButtonCopyPR = document.getElementById("buttonpr")
DownloadButtonCopyPR.addEventListener("click", CopyPRFunction);
function CopyPRFunction()
{
let SpanBanner1 = document.getElementById("copied1banner")
SpanBanner1.classList.add("copied-info")
SpanBanner1.innerHTML = `\n \n <span>\n <img src="copiedinfo.png" /> </span>`
navigator.clipboard.writeText('PR' + PRNumber);
setTimeout(function(){
SpanBanner1.classList.remove("copied-info")
SpanBanner1.innerHTML = `\n \n <span>\n </span>`
},2500)
}
//Button on and off On startup, set button state
chrome.storage.sync.get(['buttonState'], function(result) {
buttonState = result.buttonState || 'on';
});
// Attach event listener to the button
button.addEventListener('click', function() {
// Toggle button state
buttonState = buttonState === 'on' ? 'off' : 'on';
// Store button state only if it is 'off'
if(buttonState === 'off')
{
chrome.storage.sync.set({buttonState: buttonState}, function() {
});
}
if(buttonState === 'on')
{
chrome.storage.sync.set({buttonState: buttonState}, function() {
});
}
});
function CheckButtonState()
{
let IconDownload = document.getElementById("buttononofficon");
if (buttonState === 'off')
{
IconDownload.classList = ''
IconDownload.classList = 'no-active';
}
if (buttonState === 'on')
{
IconDownload.classList = '';
IconDownload.classList = 'active';
}
}
setInterval(CheckButtonState, 500)