Skip to content

Commit

Permalink
Changed the injection process to improve its compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
basicx-StrgV committed Dec 23, 2023
1 parent cc904c4 commit c33aed9
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions doxygen-custom-page-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Created by basicx-StrgV //
// https://github.com/basicx-StrgV/ //
//--------------------------------------------------//
// Version: 1.0.0 //
// Version: 1.0.1 //
//--------------------------------------------------//
document.addEventListener("DOMContentLoaded", () => {
// Get the injection wrapper element and nav to value
Expand Down Expand Up @@ -39,27 +39,32 @@ document.addEventListener("DOMContentLoaded", () => {
}

// Get the div that contains the content
let containerChildren = document.getElementById("doc-content").children;
let contentDiv;
for (let i = 0; i < containerChildren.length; i++) {
if (
containerChildren[i].classList.length <= 0 &&
containerChildren[i].id.trim() == ""
) {
// The content div has no classes or id
contentDiv = containerChildren[i];
}
}
let contentContainer = document.getElementById("doc-content");

// Exit if no content div was found and display error message
if (contentDiv == null) {
if (contentContainer == null) {
document.body.innerHTML = "";
document.body.innerText = "Failed to load custom page";
return;
}

// Replace document content
contentDiv.innerHTML = injectionWrapper.innerHTML;
// Clear the content div
for (let i = 0; i < contentContainer.children.length; i++) {
if (
contentContainer.children[i].id.trim() != "MSearchSelectWindow" &&
contentContainer.children[i].id.trim() != "MSearchResultsWindow"
) {
// Remove element from content if it does not belong to the layout
contentContainer.removeChild(contentContainer.children[i]);
}
}

// Create a content wrapper element and add the custom content
let contentWrapper = document.createElement("div");
contentWrapper.innerHTML = injectionWrapper.innerHTML;

// Appand the content wrapper to the content container
contentContainer.appendChild(contentWrapper);
});

// Replace and close document
Expand Down

0 comments on commit c33aed9

Please sign in to comment.