Skip to content

Instantly share code, notes, and snippets.

@abdorah
Created September 24, 2022 16:32
Show Gist options
  • Save abdorah/51953c9a6ecd450504a226494d41dd05 to your computer and use it in GitHub Desktop.
Save abdorah/51953c9a6ecd450504a226494d41dd05 to your computer and use it in GitHub Desktop.
Inspatch
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="main.css">
<script src="store.js" defer type="module"></script>
<script src="script.js" defer type="module"></script>
<title>Document</title>
</head>
<body>
<h1>test</h1>
<form>
<input type="text" id="a" placeholder="50">
=<output name="x0" for="a"></output>
=<output name="x1" for="a"></output>
=<output name="x2" for="a"></output>
=<output name="x3" for="a"></output>
</form>
<ul style="display: hidden;">
<li>Lorem</li>
<li>ipsum</li>
<li>dolor</li>
<li>sit</li>
<li>amet</li>
<li>consectetur</li>
<li>adipisicing</li>
<li>elit</li>
<li>Quo</li>
<li>vero</li>
<li>deserunt</li>
<li>accusamus</li>
<li>ut</li>
<li>eos</li>
<li>quos</li>
<li>dolor</li>
<li>laborum</li>
<li>repellendus</li>
<li>officia</li>
<li>iste</li>
<li>fugit</li>
<li>expedita</li>
<li>dolores</li>
<li>tempore</li>
<li>dicta</li>
<li>earum</li>
<li>hic</li>
<li>vitae</li>
<li>ipsa</li>
<li>sapiente</li>
</ul>
</body>
</html>
import { sequences } from "./store.js";
const input = document.getElementById("a");
const output0 = document.getElementsByName("x0");
const output1 = document.getElementsByName("x1");
const output2 = document.getElementsByName("x2");
const output3 = document.getElementsByName("x3");
// const batchs = document.getElementsByTagName("li");
const batchs = sequences;
input.addEventListener("input", () => {
const regex = new RegExp(input.value + ".*", 'gi');
if (regex.toString() == new RegExp(".*","gi")) {
output0.item(0).value = "";
output1.item(0).value = "";
output2.item(0).value = "";
output3.item(0).value = "";
}
else {
let buffer = [];
let result = [];
// for (const i in batchs) {
// if (Object.hasOwnProperty.call(batchs, i)) {
// const batch = batchs[i].textContent;
// buffer.push(batch);
// }
// }
batchs.executedSequences.map(sequence => sequence.sequenceName).forEach(name => buffer.push(name));
buffer.filter(element => {
return regex.test(element) && element.length < 10;
}).forEach(element => result.push(element));
output0.item(0).value = result[0] == undefined ? "" : result[0];
output1.item(0).value = result[1] == undefined ? "" : result[1];
output2.item(0).value = result[2] == undefined ? "" : result[2];
output3.item(0).value = result[3] == undefined ? "" : result[3];
}
});
export var sequences = {
"folder-name": "16/04/2000",
"count-all": "666",
"count-ok": "200",
"count-ko": "404",
"executedSequences": [
{
"sequenceName": "HDEVIL",
"reportPath": "path/to/hell"
},
{
"sequenceName": "HRANDOM",
"reportPath": "path/to/cahos"
},
{
"sequenceName": "HORACL",
"reportPath": "path/to/paradis"
}
, {
"sequenceName": "HPROMIS",
"reportPath": "path/to/neverland"
}
]
};
@abdorah
Copy link
Author

abdorah commented Sep 24, 2022

This gist is an example of the use of multiple modules to feed a static html file using js modules. I used two js files to supply the data.
script.js file manipulates the dom and inject the data. Whereas store.js file contains the data in JSON format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment