Skip to content

Instantly share code, notes, and snippets.

@RobinDev
Last active June 11, 2024 11:48
Show Gist options
  • Save RobinDev/519b31f335355338530380c971edaa7f to your computer and use it in GitHub Desktop.
Save RobinDev/519b31f335355338530380c971edaa7f to your computer and use it in GitHub Desktop.
Bookmarklet - GA - Drupal 10 - Menu
javascript: (function () { function getIndentationLevel(row) {
const indentationDiv = row.querySelectorAll(".js-indentation");
return indentationDiv.length;
}
function getParentRow(row) {
const currentIndentLevel = getIndentationLevel(row);
console.log(currentIndentLevel);
let previousRow = row.previousElementSibling;
while (previousRow) {
const previousIndentLevel = getIndentationLevel(previousRow);
if (previousIndentLevel < currentIndentLevel) {
return previousRow;
}
previousRow = previousRow.previousElementSibling;
}
return null;
}
function injectParents() {
const rows = document.querySelectorAll("table#menu-overview tbody tr");
rows.forEach((row) => {
const parentRow = getParentRow(row);
if (parentRow) {
const parentLink = parentRow
.querySelector(".tabledrag-cell-content__item")
.textContent.trim();
const currentLink =
row.querySelector(".tabledrag-cell-content__item span") ||
row.querySelector(".tabledrag-cell-content__item a");
if (currentLink)
currentLink.innerHTML =
`${currentLink.innerHTML.trim()}` +
(currentLink.querySelectorAll("br").length !== 0 ? "" : "<br>") +
` <small style="color:rgb(34, 35, 48)">\\ ${parentLink}</small>`;
}
});
}
function removeDisabledItems() {
var elements = document.querySelectorAll("tr.menu-disabled");
elements.forEach(function (element) {
element.parentNode.removeChild(element);
});
}
removeDisabledItems();
injectParents();
})();
javascript: (function () {
var location = window.location;
var hostname = location.hostname;
if (hostname === "www.grandangle.fr") {
var newUrl = location.href.replace(
"www.grandangle.fr",
"grandangle2023.votre-projet.com"
);
window.location.href = newUrl;
} else if (hostname === "grandangle2023.votre-projet.com") {
var newUrl = location.href.replace(
"grandangle2023.votre-projet.com",
"www.grandangle.fr"
);
window.location.href = newUrl;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment