-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinjection.js
More file actions
63 lines (63 loc) · 3.37 KB
/
injection.js
File metadata and controls
63 lines (63 loc) · 3.37 KB
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
function getCourseBestChange(binCourses, cbrCourses){
let TableContent = document.body.querySelectorAll('#content_table tbody tr[onclick]'); // сбор всех строк из таблицы
let course_array = []; // массив объектов с данными из строк таблицы
for(let element of TableContent){
let courseValues = element.querySelectorAll('td.bi'); // содержит значения из поля отдаете
let exchange_info = { // заполнение свойств объекта значениями из таблицы
key: element.getAttribute('onclick'),
in_name: courseValues[0].querySelector('div.fs small').innerHTML,
out_name: courseValues[1].querySelector('small').innerHTML,
in: parseFloat(courseValues[0].querySelector('div.fs').innerHTML.replaceAll(" ", "")),
out: parseFloat(courseValues[1].innerHTML.replaceAll(" ", "")),
percent: null
};
course_array.push(exchange_info);
}
function getCourse(){
let inRub, outRub;
for(let value of binCourses){
if(value["name"] == course_array[0].in_name) inRub = parseFloat(value["price"]); // получаем значение курса в рублях отдаваемой валюты
else if(value["name"] == course_array[0].out_name) outRub = parseFloat(value["price"]); // получаем значение курса в рублях получаемой валюты
else{
if(course_array[0].in_name.startsWith(value["name"])) inRub = parseFloat(value["price"]);
if(course_array[0].out_name.startsWith(value["name"])) outRub = parseFloat(value["price"]);
}
if(inRub !== undefined && outRub !== undefined) break
}
cbrCourses.forEach(value => {
if(course_array[0].in_name.startsWith(value["name"])) inRub = parseFloat(value["price"]);
if(course_array[0].out_name.startsWith(value["name"])) outRub = parseFloat(value["price"]);
})
return [inRub, outRub]
}
let [incourse, outcourse] = getCourse()
for(let exchange of course_array){
let ExchangeRow = document.body.querySelectorAll('#content_table tbody tr[onclick="' + exchange.key + '"] td.bi');
let span_percent = document.createElement('span');
incourse > outcourse
? exchange.percent = ((exchange.out * 100 / (incourse/outcourse)) - 100).toFixed(2) + "%"
: exchange.percent = (100 - (exchange.in * 100 / (outcourse/incourse))).toFixed(2) + "%"
span_percent.innerText = " " + exchange.percent;
span_percent.className = "ExtVal";
span_percent.style.cssText = exchange.percent.includes('-') ? 'color:red;' : 'color:green;';
if(ExchangeRow[1].querySelector('span') != null){
const e = ExchangeRow[1].querySelector('span');
e.parentElement.removeChild(e);
}
ExchangeRow[1].appendChild(span_percent);
}
};
function getArrays(){
chrome.storage.local.get('BinCourses', ({ BinCourses }) => {
chrome.storage.local.get('CbrCourses', ({CbrCourses}) => {
getCourseBestChange(BinCourses, CbrCourses)
})
})
}
let observer = new MutationObserver(getArrays)
observer.observe(document.querySelector('#rates_block'), {
childList: true,
subtree: true,
characterData: true
});
getArrays()