|
2 | 2 | // Created by basicx-StrgV // |
3 | 3 | // https://github.com/basicx-StrgV/ // |
4 | 4 | //--------------------------------------------------// |
5 | | -// Version: 1.0.0 // |
| 5 | +// Version: 1.0.1 // |
6 | 6 | //--------------------------------------------------// |
7 | 7 | document.addEventListener("DOMContentLoaded", () => { |
8 | 8 | // Get the injection wrapper element and nav to value |
@@ -39,27 +39,32 @@ document.addEventListener("DOMContentLoaded", () => { |
39 | 39 | } |
40 | 40 |
|
41 | 41 | // Get the div that contains the content |
42 | | - let containerChildren = document.getElementById("doc-content").children; |
43 | | - let contentDiv; |
44 | | - for (let i = 0; i < containerChildren.length; i++) { |
45 | | - if ( |
46 | | - containerChildren[i].classList.length <= 0 && |
47 | | - containerChildren[i].id.trim() == "" |
48 | | - ) { |
49 | | - // The content div has no classes or id |
50 | | - contentDiv = containerChildren[i]; |
51 | | - } |
52 | | - } |
| 42 | + let contentContainer = document.getElementById("doc-content"); |
53 | 43 |
|
54 | 44 | // Exit if no content div was found and display error message |
55 | | - if (contentDiv == null) { |
| 45 | + if (contentContainer == null) { |
56 | 46 | document.body.innerHTML = ""; |
57 | 47 | document.body.innerText = "Failed to load custom page"; |
58 | 48 | return; |
59 | 49 | } |
60 | 50 |
|
61 | | - // Replace document content |
62 | | - contentDiv.innerHTML = injectionWrapper.innerHTML; |
| 51 | + // Clear the content div |
| 52 | + for (let i = 0; i < contentContainer.children.length; i++) { |
| 53 | + if ( |
| 54 | + contentContainer.children[i].id.trim() != "MSearchSelectWindow" && |
| 55 | + contentContainer.children[i].id.trim() != "MSearchResultsWindow" |
| 56 | + ) { |
| 57 | + // Remove element from content if it does not belong to the layout |
| 58 | + contentContainer.removeChild(contentContainer.children[i]); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + // Create a content wrapper element and add the custom content |
| 63 | + let contentWrapper = document.createElement("div"); |
| 64 | + contentWrapper.innerHTML = injectionWrapper.innerHTML; |
| 65 | + |
| 66 | + // Appand the content wrapper to the content container |
| 67 | + contentContainer.appendChild(contentWrapper); |
63 | 68 | }); |
64 | 69 |
|
65 | 70 | // Replace and close document |
|
0 commit comments