Discussions » Creation Requests
mega.nz - Set tab titles based on content
getElementsByClassName
returns an array-like collection so you need to add [0]
to get the first element: document.getElementsByClassName("filename")[0].innerText
however it's easier to use querySelector
instead and specify the class name in CSS notation with a dot: document.querySelector(".filename").innerText
Superb! Thank you for your help. <3
mega.nz - Set tab titles based on content
I've been trying to figure out how to do this for several hours but my Javascript knowledge is extremely limited and I can't get anything to work properly.
My problem is that with multiple tabs open containing shared Mega files and folders they all look like this:
This is quite unhelpful and I’d really like something more descriptive based on the tabs’ contents.
I've found there seem to be two main scenarios: single files and folders.
With single files the script would need to get the text from
<span class="filename">
and set it as the page title.When there are folders there is a breadcrumb showing the file path (
<div class="fm-breadcrumbs-block"
). Ideally it would be nice to show the full path in the title – i.e. in the example I posted the page title would show asexample folder/1/2/3
– and for it to update as different folders are selected, but otherwise being able to show just the outermost folder would obviously be simpler and still useful.Based on bits taken from other scripts and looking stuff up I tried making this (for the single file scenario), but it only sets the page title to undefined :/. I can't tell if that's because I'm just overlooking something simple, or if the whole needs doing differently.