Skip to content

Commit

Permalink
Fix recent problems
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzyla committed Apr 3, 2022
1 parent d5c2424 commit b34c2c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
23 changes: 17 additions & 6 deletions source/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,26 @@ function createLink(name: string, value: string): Element {
}

function handleKibanaDetected() {
console.log("Kibana detected");
console.log("KibanaClicker: Kibana is detected");
IS_KIBANA_DETECTED = true;
}

function handleDocumentViewer(viewer: Element) {
function handleDocumentViewer(viewer: Element, iteration = 0) {
if (iteration > 10) {
console.log("KibanaClicker: More than expected iterations");
return;
}
if (viewer.getAttribute(KIBANA_CLICKER_INJECTED_ATTRIBUTE) != null) {
return;
}

const rows = viewer.querySelectorAll("table tr td div[data-test-subj^='tableDocViewRow-']");
const rows = viewer.querySelectorAll("table div[data-test-subj^='tableDocViewRow-']");
if (rows.length === 0) {
setTimeout(
() => handleDocumentViewer(viewer, iteration + 1),
1000,
);
return;
}
rows.forEach((row) => {
const fieldName = getFieldName(row);
if (!fieldName) {
Expand Down Expand Up @@ -71,8 +81,9 @@ function handleNewNode(node: Node) {
return handleDocumentViewer(node);
}

if (node.querySelector(".kbnDocViewer") !== null) {
return handleDocumentViewer(node);
const viewer = node.querySelector(".kbnDocViewer");
if (viewer !== null) {
return handleDocumentViewer(viewer);
}

}
Expand Down
3 changes: 0 additions & 3 deletions source/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@
"content.css"
]
}
],
"permissions": [
"activeTab"
]
}

0 comments on commit b34c2c7

Please sign in to comment.