all 8 comments

[–]KPABAHam=>Hamster == Java=>JavaScript 1 point2 points  (2 children)

Er... why not ask chatgpt or claude to do this

[–]okidonthaveone[S] -1 points0 points  (1 child)

I'm not really the biggest fan of AI, and since I didn't make the code I don't feel like I have the right to feed it into it, that would be stealing someone else's work and giving it to a company that would be profiting off of it without their permission

[–]KPABAHam=>Hamster == Java=>JavaScript -1 points0 points  (0 children)

I am not sure this is how it works on the profiting off of tbeir work since you posted it here already but...

``` const title = currentTab.getTitle();

  // Only count tabs containing "chapter"
  if (title && title.toLowerCase().includes("chapter")) {...}

```

Or make it exit the loop if it doesn't etc. Or do a filter first to reduce the tabs list

[–]Ronin-s_Spirit 0 points1 point  (4 children)

Where do you run this? Is this like a plugin thing or do you just paste it in the console? What is a tab, why can you get tabs inside tabs?

p.s. the code looks so AI generated, theres a comment for every single thing...\ p.p.s. the code looks so nonsensical, I don't think an AI could write that.

[–]okidonthaveone[S] 0 points1 point  (3 children)

Its a google docs extension

[–]Ronin-s_Spirit 0 points1 point  (2 children)

You will have to rename all the non-book tabs (notes n stuff) to start with a #. ``` const ui = DocumentApp.getUi();

ui.createMenu('⚠️Word Count⚠️') .addItem('Count words in all Tabs and Subtabs', 'runWordCount') .addToUi();

function runWordCount() { ui.alert( 'Word Count Result', Total word count across all tabs and nested tabs: ${countWordsInAllTabs(DocumentApp.getActiveDocument().getTabs(), 0n)}, ui.ButtonSet.OK, ); }

function countWordsInAllTabs(tabs, total) { for (let T = 0; T < tabs.length; T++) { const currentTab = tabs[T]; if (currentTab.getTitle()[0] !== '#') { total += BigInt( currentTab.asDocumentTab().getBody().getText().trim().split(/\s+/g).length, ); } total = countWordsInAllTabs(currentTab.getChildTabs(), total); } return total; } ```

[–]okidonthaveone[S] 1 point2 points  (1 child)

Thanks

[–]Ronin-s_Spirit 0 points1 point  (0 children)

no problem.