Got it, it was actually pretty simple : 

I had to use same query for both titles tags, then get the tag H2 or H3 as 
a variable, then use this one for conditionnal behaviour. Then use the 
existing "i" value to get incremented anchors and links
a) (querySelectorAll("div.block>h2", "div.block>h3");
b) var titletag = allCats[i].nodeName;
c) if (titletag == "H2") and else, for each specific code. 
d) CatsAnchor.setAttribute('id', 'title' + i); and the same for the link



Le lundi 24 novembre 2014 13:22:10 UTC+1, psyto san a écrit :
>
> Hi everyone, 
>
> I'm a complete noob in working with JS, i just started yesterday to work 
> on a userscript by studying and adapting some code i found...
>
> I want to create a quicklinks TOC of a div content which contains many H2, 
> H3 and tables with no class or id at all, otherwise there's no fun :)
> H2 and H3 inner HTML is not identical, as h2 titles only are enclosed in 
> spans
> Some H3 are identicals (same title), so i guess i'd better use incremented 
> numeric anchors and links for the code and my TOC to make them work
> Some H2 spans contains a lot of spaces, i don't care about the display for 
> now, links would work with numbers as well
>
> For now, i managed to get the list of H2 titles, add anchors and create a 
> TOC with the corresponding list in a div
> I did the same for H3 titles in another div
> The anchor and links work with the inner content (the titles), in which i 
> replaced spaces by -
>
> Here's the code : http://jsfiddle.net/psyto/0n2so4ae/
>
> Js basically looks like : 
>
> For each h2 : 
> * do the h2 span anchor and links
> For each h3 : 
> * do the h3 anchor and links
>
> So my questions are : 
>
> 1)  how can i order the links in a single list ?
>
> How can i express 
> For each h2 : 
> * do the h2 span anchor and links
> * For each h3 until the next h2 : 
> ** do the anchor and links
>
> 2)  how can i set numerical values for the anchor id and links href ? 
> Something like "cat##" for h2, and "cat##-subcat##" for h3 ?
>
> Thanks in advance for your help
>

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to