Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
anleitungen:software:peertube:peertube_-_menu_enhancer [2024/01/24 16:39] – angelegt mike | anleitungen:software:peertube:peertube_-_menu_enhancer [Unbekanntes Datum] (aktuell) – Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== PeerTube - Menu Enhancer ====== | ||
+ | < | ||
+ | /** === LINKS === | ||
+ | * Simple add your links into the MENU_LINKS array following the example format | ||
+ | * It will be added to the menu in the same order as you defined it | ||
+ | */ | ||
+ | |||
+ | /** === SEPARATOR === | ||
+ | * Like our example, use {name: " | ||
+ | */ | ||
+ | |||
+ | /** === ICONS === | ||
+ | * You can use https:// | ||
+ | * Else, you can use https:// | ||
+ | * Just import the CSS manually. | ||
+ | **/ | ||
+ | |||
+ | // EDIT HERE | ||
+ | var MENU_LINKS = [ | ||
+ | { | ||
+ | name: " | ||
+ | url: "/ | ||
+ | icon: " | ||
+ | }, | ||
+ | { | ||
+ | name: " | ||
+ | url: "/ | ||
+ | icon: " | ||
+ | }, | ||
+ | { name: " | ||
+ | { | ||
+ | name: " | ||
+ | url: " | ||
+ | target: " | ||
+ | icon: " | ||
+ | }, | ||
+ | { | ||
+ | name: "Pixel - Partagez vos photos", | ||
+ | url: " | ||
+ | target: " | ||
+ | icon: " | ||
+ | }, | ||
+ | { name: " | ||
+ | { | ||
+ | name: " | ||
+ | url: " | ||
+ | target: " | ||
+ | icon: " | ||
+ | } | ||
+ | ] | ||
+ | |||
+ | // END EDIT -- DO NOT TOUCH AFTER | ||
+ | |||
+ | /** | ||
+ | * Wait for the DOM to be loaded | ||
+ | * Then, init the custom menu | ||
+ | */ | ||
+ | window.addEventListener(" | ||
+ | const wait__menuCustomInterval = setInterval(() => { | ||
+ | let firstLink = document.querySelectorAll( | ||
+ | ' | ||
+ | ); | ||
+ | if (firstLink.length > 0) { | ||
+ | clearInterval(wait__menuCustomInterval); | ||
+ | initCustomMenu(firstLink[0]); | ||
+ | } | ||
+ | }, 500); | ||
+ | }); | ||
+ | |||
+ | /** | ||
+ | * Init the custom menu | ||
+ | * @param {HTMLElement} firstLink The first link of the menu | ||
+ | * @returns {void} | ||
+ | */ | ||
+ | function initCustomMenu(linkTemplate) { | ||
+ | //Parent node which contains ' | ||
+ | const menuContainer = linkTemplate.parentNode; | ||
+ | // Define head element | ||
+ | const head = document.head; | ||
+ | |||
+ | // Define and ADD custom CSS | ||
+ | const customCSS = ` | ||
+ | hr { | ||
+ | background-color: | ||
+ | } | ||
+ | | ||
+ | a.menu-link i { | ||
+ | margin-right: | ||
+ | } | ||
+ | `; | ||
+ | const style = document.createElement(" | ||
+ | style.type = " | ||
+ | style.appendChild(document.createTextNode(customCSS)); | ||
+ | head.appendChild(style); | ||
+ | |||
+ | // Define separator | ||
+ | const separator = document.createElement(" | ||
+ | separator.setAttribute(" | ||
+ | separator.setAttribute(" | ||
+ | separator.setAttribute(" | ||
+ | separator.setAttribute(" | ||
+ | separator.setAttribute(" | ||
+ | |||
+ | //Adding links | ||
+ | MENU_LINKS.forEach((link) => { | ||
+ | if (link.name === " | ||
+ | // Adding separator | ||
+ | menuContainer.appendChild(separator.cloneNode()); | ||
+ | } else { | ||
+ | // Adding link | ||
+ | |||
+ | // Manage icon (automatically import if start with gg-*** from https:// | ||
+ | let icon = ""; | ||
+ | if (link.icon.startsWith(" | ||
+ | icon = `<i class=" | ||
+ | const ggName = link.icon.replace(" | ||
+ | |||
+ | // Inject css in the head | ||
+ | const cssLink = document.createElement(" | ||
+ | cssLink.type = " | ||
+ | cssLink.rel = " | ||
+ | cssLink.href = `https:// | ||
+ | head.appendChild(cssLink); | ||
+ | } else { | ||
+ | icon = `<i class=" | ||
+ | } | ||
+ | |||
+ | // Create link | ||
+ | const linkNode = linkTemplate.cloneNode(); | ||
+ | linkNode.setAttribute(" | ||
+ | linkNode.setAttribute(" | ||
+ | linkNode.setAttribute(" | ||
+ | linkNode.innerHTML = icon + " " + link.name; | ||
+ | |||
+ | // Add link to the menu | ||
+ | menuContainer.appendChild(linkNode); | ||
+ | } | ||
+ | }); | ||
+ | } | ||
+ | </ |