Last active
October 17, 2022 22:21
-
-
Save vladimirgamalyan/45ace6c858278f529668262a660f81d4 to your computer and use it in GitHub Desktop.
Пример скрипта для расширения хрома User JavaScript and CSS для вывода счетчиков waterius нужном формате.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-family: monospace; | |
font-size: 12pt; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SEPARATOR | |
function findChannel(data, name) { | |
for (const device of data) { | |
for (const channel of device.channels) { | |
if (channel.serial === name) { | |
return channel; | |
} | |
} | |
} | |
} | |
function abbrChannelType(s) { | |
if (s === 'Горячая вода') { | |
return 'ГВС'; | |
} | |
if (s === 'Холодная вода') { | |
return 'ХВС'; | |
} | |
return s; | |
} | |
function getChannelText(data, name) { | |
const channel = findChannel(data, name); | |
const channelType = abbrChannelType(channel.type); | |
return channelType + ' ' + name + ' ' + Math.round(channel.value); | |
} | |
document.addEventListener('DOMContentLoaded', function(event) { | |
const str = document.body.textContent.split('//SEPARATOR', 1) | |
const data = JSON.parse(str); | |
html = getChannelText(data, '09-0023744') + '<br>'; | |
html += getChannelText(data, '09-0062686') + '<br>'; | |
html += getChannelText(data, '09-0023921') + '<br>'; | |
html += getChannelText(data, '09-0047243') + '<br>'; | |
document.body.innerHTML = html; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment