Search code examples
javascriptgoogle-chrome-extension

Extract Google Slide numbers in presenter view from div which requires dropdown to be open before they load


I would like to extract the Slide numbers from Google Slide Presenter View.

They all get listed under goog-menuitem-checkbox but only when once clicked on the slide selection dropdown.

Is there any way I could trigger this with javascript to already load them so i can extract them?

Drop down when presenter view is loaded

<div class="goog-inline-block goog-flat-menu-button jfk-select" role="listbox" aria-expanded="false" tabindex="0" aria-haspopup="true" aria-activedescendant=":2p" style="user-select: none;"><div class="goog-inline-block goog-flat-menu-button-caption" id=":2p" role="option" aria-selected="true" aria-setsize="19" aria-posinset="1">Slide 1 </div><div class="goog-inline-block goog-flat-menu-button-dropdown" aria-hidden="true">&nbsp;</div></div>

Dropdown when clicked/opened

<div class="goog-inline-block goog-flat-menu-button jfk-select" role="listbox" aria-expanded="false" tabindex="0" aria-haspopup="true" style="user-select: none;" aria-activedescendant=":2p"><div class="goog-inline-block goog-flat-menu-button-caption" id=":2p" role="option" aria-selected="true" aria-setsize="19" aria-posinset="1">Slide 1 </div><div class="goog-inline-block goog-flat-menu-button-dropdown" aria-hidden="true">&nbsp;</div></div>

console.log(document.getElementsByClassName('goog-menuitem-checkbox')[0].nextSibling.data); 

Solution

  • Well it's interesting that I came across this exact problem while trying to extract published google slides, so I can share what I used.

    You don't actually need to trigger open the slide selection menu, the html of the div itself has two attributes for the same:

    • aria-posinset : For Current Slide Index
    • aria-setsize : For Total Slides count in the presentation

    Reading it something like this should get you what you need:

    document.querySelectorAll('[class$="-caption"]')[0].getAttribute("aria-setsize")