content.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (function () {
  2. if (window.top !== window.self) {
  3. const onCopyClicked = function (_from) {
  4. const values = [], year = $('#dateTag').text().split(' ')[1];
  5. $('#monthlySummaryChartArea text').each(function () {
  6. if ($(this).attr('id') && $(this).attr('id').indexOf('averageGlucoseValue') !== -1) {
  7. const parts = $(this).attr('id').split('-');
  8. const day = +parts[2];
  9. if(day >= _from) {
  10. values.push({
  11. value: $(this).text(),
  12. day: parts[2],
  13. month: parts[1],
  14. year: year,
  15. });
  16. }
  17. }
  18. });
  19. const json = JSON.stringify(values);
  20. navigator.clipboard.writeText(json);
  21. alert('Copied to clipboard');
  22. }
  23. // try and detect #monthlySummaryReportSpace
  24. const $monthlySummaryReportSpace = $('#monthlySummaryReportSpace');
  25. if ($monthlySummaryReportSpace.length) {
  26. const copyAll = $('<span class="copy all"><b>Copy All</b></span>')
  27. .click(function() {
  28. onCopyClicked(1);
  29. });
  30. const copyFrom = $('<span class="copy from"><b>Copy From</b></span>')
  31. .click(function() {
  32. let fromDay = prompt('From date (just the day, for ex: 7):');
  33. fromDay = $.trim(fromDay);
  34. if(isNaN(fromDay)) {
  35. alert('Not a valid day');
  36. return;
  37. }
  38. fromDay = +fromDay;
  39. onCopyClicked(fromDay);
  40. });
  41. jQuery('<div/>').html('Auto-detected Monthly Summary - ')
  42. .addClass('lv-ms-detected')
  43. .append(copyAll)
  44. .append('&nbsp;-&nbsp;')
  45. .append(copyFrom)
  46. .appendTo($monthlySummaryReportSpace);
  47. }
  48. }
  49. })();