Skip to content

Commit

Permalink
Chrome extension build script, doc, and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepsinn committed Nov 19, 2023
1 parent 618187b commit d26ae8e
Show file tree
Hide file tree
Showing 43 changed files with 209 additions and 143 deletions.
4 changes: 2 additions & 2 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ FILTER_REGEX_EXCLUDE: tsconfig.json
EXCLUDED_DIRECTORIES:
[
.obsidian,
plugins/optomitron-real-time-decision-support-plugin/analysis-data,
plugins/optomitron-real-time-decision-support-plugin/analysis-data/*,
plugins/optomitron-decision-support-notifications-plugin/analysis-data,
plugins/optomitron-decision-support-notifications-plugin/analysis-data/*,
.git,
.github,
.vscode,
Expand Down
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ This [monorepo](docs/contributing/repo-structure.md) contains libraries and tool

# 😕 Why are we doing this?

Billions of people are suffering and dying from chronic diseases.
The current system of clinical research, diagnosis, and treatment is failing the billions of people are suffering from chronic diseases.

👉 [Learn why the current system is failing...](docs/stuff-that-sucks.md)
[👉 Problems we're trying to fix...](docs/stuff-that-sucks.md)

# 🧪 Our Hypothesis

Expand Down Expand Up @@ -43,9 +43,15 @@ Our crazy theory is that we can accomplish the same great feat in the realm of c

</details>

# 🖥️ dFDA Framework
# 🖥️ dFDA Framework Components

This is a very high-level overview of the architecture. It's a work in progress. Please contribute!
This is a very high-level overview of the architecture.

The dFDA is intended to be:
- a set of modular libraries and tools that can be reused in any project
- an abstract framework of core primitive components rather than a specific implementation
- a directory of existing open-source projects that can be used to fulfill the requirements of each primitive or component
- a collaborative effort, so please feel free to [contribute](docs/contributing.md)!

![dfda-stack-diagram-white-background.svg](docs/images/dfda-stack-diagram-white-background.svg)

Expand Down Expand Up @@ -142,11 +148,11 @@ dFDa-1 is an initial prototype of the decentralized FDA located in [apps/dfda-1]

<p align="center">

<img src="apps/dfda-1/public/app/public/img/screenshots/all-ionic-quantimodo-screenshots.png" width="800" alt="dFDA screenshots">
<img src="apps/dfda-1/public/app/public/img/screenshots/record-inbox-import-connectors-analyze-study.png" width="800" alt="dFDA screenshots">
&nbsp
</p>
<p align="center">
<img src="apps/dfda-1/public/app/public/img/screenshots/ionic-inbox-screenshot-bg.png" width="300" alt="Reminder Inbox">
<img src="apps/dfda-1/public/app/public/img/screenshots/reminder-inbox-screenshot-no-text.png" width="300" alt="Reminder Inbox">
</p>

Collects and aggregate data on symptoms, diet, sleep, exercise, weather, medication, and anything else from dozens
Expand All @@ -159,11 +165,11 @@ Web and mobile push notifications with action buttons.

![web notification action buttons](docs/components/data-collection/web-notification-action-buttons.png)

## Chrome Extension
## Browser Extensions

By using the Chrome Extension, you can track your mood, symptoms, or any outcome you want to optimize in a fraction of a second using a unique popup interface.
By using the Browser Extension, you can track your mood, symptoms, or any outcome you want to optimize in a fraction of a second using a unique popup interface.

![Chrome Extension](docs/components/browser-extension/chrome-extension.png)
![Chrome Extension](docs/components/browser-extension/browser-extension.png)

## Data Analysis

Expand All @@ -181,19 +187,21 @@ It then pairs every combination of variables and identifies likely causal relati

### Real-time Decision Support Notifications

![](docs/components/real-time-decision-support/notifications-screenshot.png)
![](docs/components/decision-support-notifications/notifications-screenshot-slide.png)

[More info about real time decision support](docs/components/outcome-labels/outcome-labels.md)

### 📈 Predictor Search Engine

![Predictor Search](docs/components/predictor-search-engine/predictor-search-simple-list-zoom.png)
[![Predictor Search Engine](docs/components/predictor-search-engine/predictor-search-simple-list-zoom.png)](docs/components/predictor-search-engine/predictor-search-engine.md)

[👉 More info about the predictor search engine...](docs/components/predictor-search-engine/predictor-search-engine.md)

### Auto-Generated Observational Studies

![](docs/components/observational-studies/observational-studies.png)

[More info about observational studies](docs/components/observational-studies/observational-studies.md)
[👉 More info about observational studies...](docs/components/observational-studies/observational-studies.md)

## Prototype Demos

Expand Down Expand Up @@ -230,3 +238,6 @@ It's our goal to avoid any duplication of effort. So please include existing pro

**[👉 Click Here to Contribute](docs/contributing.md)**

# 🛟 Support

If you have any questions or need help, please [create an issue](https://github.com/decentralized-fda/decentralized-fda/issues/new) instead of emailing us so that others can benefit from the discussion.
6 changes: 3 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
The following table displays the versions of the Decentralized FDA project currently being supported with security updates:

| Version | Supported |
| ------- | ------------------ |
|---------|--------------------|
| 1.0.x | :white_check_mark: |
| < 1.0 | :x: |

Expand All @@ -18,11 +18,11 @@ To report a security vulnerability within the Decentralized FDA project, follow
3. In the email, include a detailed description of the vulnerability, along with the affected component(s) and version(s) of the project.
4. Optionally, provide a proof of concept, screenshots, or any other relevant information to help us understand and reproduce the issue.

The CUREDAO security team will acknowledge receipt of your vulnerability report within 48 hours and will provide an estimated timeline for addressing the issue. Once the vulnerability has been resolved, the security team will coordinate with you to disclose the issue publicly, if appropriate.
The security team will acknowledge receipt of your vulnerability report within 48 hours and will provide an estimated timeline for addressing the issue. Once the vulnerability has been resolved, the security team will coordinate with you to disclose the issue publicly, if appropriate.

## Security Update Process

The CUREDAO team is committed to addressing security vulnerabilities in a timely manner. Once a vulnerability has been reported, the following process will be followed:
The team is committed to addressing security vulnerabilities in a timely manner. Once a vulnerability has been reported, the following process will be followed:

1. The security team will evaluate the reported vulnerability and assign a severity level based on the potential impact.
2. The security team will work on developing a fix for the vulnerability.
Expand Down
13 changes: 7 additions & 6 deletions apps/dfda-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ The main purpose is to make it easier, cheaper, and faster to


## Features
* [Outcome Labels](https://www.curedao.org/blog/outcome-labels-plugind)
* [Predictor Search Engines](https://www.curedao.org/blog/predictor-search-engine-plugin)
* [Root Cause Analysis Reports](https://www.curedao.org/blog/root-cause-analysis-plugins)
* [Observational Mega-Studies](https://www.curedao.org/blog/observational-studies-plugin)
* [Real-Time Decision Support Notifications](https://www.curedao.org/blog/optomitron)
* [No Code Health App Builder](https://www.curedao.org/blog/no-code-health-app-builder)
[outcome-labels.md](../../docs/components/outcome-labels/outcome-labels.md)
* [Outcome Labels](../../docs/components/outcome-labels/outcome-labels.md)
* [Predictor Search Engine](../../docs/components/predictor-search-engine/predictor-search-engine.md)
* [Root Cause Analysis Reports](../../docs/components/root-cause-analysis-reports/root-cause-analysis-reports.md)
* [Observational Mega-Studies](../../docs/components/observational-studies/observational-studies.md)
* [Real-Time Decision Support Notifications](../../docs/components/decision-support-notifications/decision-support-notifications.md)
* [No Code Health App Builder](../../docs/components/no-code-app-builder/no-code-app-builder.md)
* [AI Robot Doctor](https://www.curedao.org/blog/optomitron)
* [Chrome Extension](https://www.curedao.org/blog/chrome-extension)

Expand Down
Empty file.
86 changes: 86 additions & 0 deletions apps/dfda-1/public/app/public/chrome_build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const cheerio = require('cheerio');

const downloadFile = async (url, filePath) => {
const dir = path.dirname(filePath);
if (!fs.existsSync(dir)) {
console.log(`Creating directory: ${dir}`);
fs.mkdirSync(dir, { recursive: true });
}

console.log(`Downloading ${url}...`);
const writer = fs.createWriteStream(filePath);
const response = await axios({
url,
method: 'GET',
responseType: 'stream'
});

response.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on('finish', () => {
console.log(`Downloaded and saved to ${filePath}`);
resolve();
});
writer.on('error', reject);
});
};

const generateSafeFilename = (url) => {
const urlObj = new URL(url);
let baseName = path.basename(urlObj.pathname);
if (urlObj.search) {
// Handling query strings
baseName += '_' + encodeURIComponent(urlObj.search).replace(/%/g, '');
}
return baseName;
};

const processHTML = async (htmlFilePath) => {
console.log(`Processing HTML file: ${htmlFilePath}`);
const htmlContent = fs.readFileSync(htmlFilePath, 'utf8');
const $ = cheerio.load(htmlContent);

// Handle script tags
const scriptTags = $('script[src]');
for (let i = 0; i < scriptTags.length; i++) {
const src = scriptTags[i].attribs.src;
if (src.startsWith('http')) {
const filename = generateSafeFilename(src);
const localPath = `./local-libs/${filename}`;
try {
await downloadFile(src, localPath);
$(scriptTags[i]).attr('src', localPath);
} catch (error) {
console.error(`Error downloading ${src}: ${error.message}`);
}
}
}

// Handle link tags for CSS
const linkTags = $('link[rel="stylesheet"]');
for (let i = 0; i < linkTags.length; i++) {
const href = linkTags[i].attribs.href;
if (href && href.startsWith('http')) {
const filename = generateSafeFilename(href);
const localPath = `./local-libs/${filename}`;
try {
await downloadFile(href, localPath);
$(linkTags[i]).attr('href', localPath);
} catch (error) {
console.error(`Error downloading ${href}: ${error.message}`);
}
}
}

const modifiedHtml = $.html();
const newHtmlFilePath = './chrome_index.html';
fs.writeFileSync(newHtmlFilePath, modifiedHtml);
console.log(`Created modified HTML file: ${newHtmlFilePath}`);
};

processHTML('./index.html').catch(error => {
console.error(`An error occurred: ${error.message}`);
});
1 change: 1 addition & 0 deletions apps/dfda-1/public/app/public/data/qmStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,7 @@ var qmStates = [
]
if (typeof window !== "undefined") {
window.qmStates = qmStates;
window.qm = window.qm || {};
window.qm.qmStaticData = window.qm.qmStaticData || {};
window.qm.qmStaticData.states = qmStates;
} else {
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion apps/dfda-1/public/app/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<link rel="shortcut icon"
href="img/icons/icon_16.png">
<!-- build:js scripts/combined-head-libraries.js -->
<script src="https://static.quantimo.do/lib/q/q.js"></script>
<script defer src="https://static.quantimo.do/lib/bugsnag/dist/bugsnag.js"></script>
<script src="js/psychedelic-loader-ionic.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/89/three.min.js"></script>
Expand Down Expand Up @@ -156,7 +157,7 @@
<script defer src="https://static.quantimo.do/lib/pouchdb/dist/pouchdb.min.js"></script>
<script defer src="https://static.quantimo.do/lib/pouchdb-upsert/dist/pouchdb.upsert.js"></script>
<script defer src="https://static.quantimo.do/lib/quagga/dist/quagga.js"></script>
<script defer src="https://static.quantimo.do/lib/q/q.js"></script>

<script defer src="https://static.quantimo.do/lib/compromise/builds/compromise.js"></script> <!-- compromise produces errors when minified for some reason -->
<script defer src="https://static.quantimo.do/lib/Bravey/build/bravey.js"></script> <!-- Bravey produces errors when minified for some reason -->
<script async src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
Expand Down
16 changes: 14 additions & 2 deletions apps/dfda-1/public/app/public/js/qmChrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,28 @@ window.qm.chrome = {
}
};
if(typeof screen !== "undefined"){
var qmChrome = window.qm.chrome;
debugger
// TODO: Remove this redundant definition when you figure out why it's not available
qm.chrome.multiplyScreenHeight = function (factor){
if(typeof screen === "undefined"){return false;}
return parseInt(factor * screen.height);
}
qm.chrome.multiplyScreenWidth = function (factor){
if(typeof screen === "undefined"){return false;}
return parseInt(factor * screen.width);
}
qm.chrome.windowParams = {
introWindowParams: { url: "index.html#/app/intro", type: 'panel', top: multiplyScreenHeight(0.2), left: multiplyScreenWidth(0.4), width: 450, height: 750, focused: true},
introWindowParams: { url: "index.html#/app/intro", type: 'panel', top: qm.chrome.multiplyScreenHeight(0.2), left: qm.chrome.multiplyScreenWidth(0.4), width: 450, height: 750, focused: true},
facesWindowParams: { url: "android_popup.html", type: 'panel', top: screen.height - 150, left: screen.width - 380, width: 390, height: 110, focused: true},
loginWindowParams: { url: "index.html#/app/login", type: 'panel', top: multiplyScreenHeight(0.2), left: multiplyScreenWidth(0.4), width: 450, height: 750, focused: true},
loginWindowParams: { url: "index.html#/app/login", type: 'panel', top: qm.chrome.multiplyScreenHeight(0.2), left: qm.chrome.multiplyScreenWidth(0.4), width: 450, height: 750, focused: true},
fullInboxWindowParams: { url: "index.html#/app/reminders-inbox", type: 'panel', top: screen.height - 800, left: screen.width - 455, width: 450, height: 750},
compactInboxWindowParams: { url: "index.html#/app/reminders-inbox-compact", type: 'panel', top: screen.height - 360 - 30, left: screen.width - 350, width: 350, height: 360},
inboxNotificationParams: { type: "basic", title: "How are you?", message: "Click to open reminder inbox", iconUrl: "img/icons/icon_700.png", priority: 2},
signInNotificationParams: { type: "basic", title: "How are you?", message: "Click to sign in and record a measurement", iconUrl: "img/icons/icon_700.png", priority: 2},
};
}
qm.chrome.initialize();
if(qm.platform.isChromeExtension()){
qm.chrome.initialize();
}
4 changes: 4 additions & 0 deletions apps/dfda-1/public/app/public/js/qmHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ var qm = {
},
getQMOrigin: function(){
var origin;
if(qm.platform.isChromeExtension()){
return "https://app.quantimo.do";
}
//return "https://app.quantimo.do";
if(qm.appMode.isBackEnd()){
origin = process.env.QM_API_ORIGIN || "https://app.quantimo.do";
Expand Down Expand Up @@ -11189,6 +11192,7 @@ var qm = {
return fullUrl;
},
validateUrl: function(url){
return; // Not sure what this was for but it breaks chrome_index.html
if(url.indexOf('index.html') !== -1 &&
url.indexOf('2Findex.html') === -1 &&
url.indexOf('/index.html') === -1){
Expand Down
2 changes: 1 addition & 1 deletion apps/dfda-1/public/app/public/js/services/qmService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6078,7 +6078,7 @@ angular.module('starter').factory('qmService', ["$http", "$q", "$rootScope", "$i
} else {
psychedelicLoader.start();
}
debugger
//debugger
// var templateUrl = "templates/loaders/triangles-loader.html"
// I think the high GPU usage crashes the browser
// $ionicLoading.show({templateUrl: templateUrl, duration: duration * 1000});
Expand Down
2 changes: 1 addition & 1 deletion apps/dfda-1/public/app/public/manifest-chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"background": {
"scripts": [
"qmChromeBackground.js"
"js/qmChrome.js"
],
"persistent": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html><head></head><body>
<script src="data/qmStates.js"></script>
<script src="lib/q/q.js"></script>
<script src="custom-lib/bugsnag.js"></script>
<script src="js/qmLogger.js"></script>
<script src="js/qmHelpers.js"></script>
<script src="js/qmChrome.js"></script>
</body></html>
15 changes: 15 additions & 0 deletions docs/components/browser-extension/browser-extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Browser Extension

By using the Browser Extension, you can track your mood, symptoms, or any outcome you want to optimize in a fraction of a second using a unique popup interface.

![Chrome Extension](browser-extension.png)

# 💻 Code

For development, you need to copy manifest-chrome.json into manifest.json and then load the [apps/dfda-1/public/app/public](../../../apps/dfda-1/public/app/public) folder as an unpacked extension in Chrome.

[👉 Code here...](../../../apps/dfda-1/public/app/public)

# 🛟 Support

If you have any questions or need help, please [create an issue](https://github.com/decentralized-fda/decentralized-fda/issues/new) instead of emailing us so that others can benefit from the discussion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d26ae8e

Please sign in to comment.