How can I call the Javascript that shows/hides the AI analysis?

Hello, in this related thread I learned how to use the GUI to show/hide the AI analysis.

Now, I would like to know what Javascript/Typescript function is called to show and hide it.

Why? Because I am trying to write a Chrome plugin that shows/hides the analysis as part of making flashcards - GitHub - metaperl/baduk-flash: Make flashcards of baduk/go/weiqi positions


It looks like it’s called toggleAIReview

defined further up


OK - but when I call that in the developer console I get this error:

Uncaught ReferenceError: toggleAIReview is not defined
    at <anonymous>:1:1

and it also is not callable from the Chrome plugin I am developing… any idea why?

I am on the online-go tab of my browser and I am in a game review looking at the analysis when I attempt to invoke toggleAIReview()

Furthermore, pressing shift-I does in act toggle the AI review. So the function is definitely in memory.

It’s not a global method, it’s a method of the Game component.

(Whether you can, and how to call that from the console I do not know, I haven’t tried to dig into that … I’m just explaining why you can’t simply say toggleAIReview() in the console. My initial guess is that “it may not be possible”. I had a quick google of “call react component method from console” and didn’t have an immediate solution… that’s the kind of direction you need to look in I think)


Presumably though one might be able to simulate clicking the show/hide button or pressing ctrl+i as part of some other bit of code.

So you have your plugin do something, and then it triggers clicking a button or pressing a keyboard shortcut?

(I haven’t tried writing a browser plugin before)

document.dispatchEvent(new KeyboardEvent('keydown', {
    key: 'i',
    keyCode: 73,
    shiftKey: true

shift+i yes!

Also cool :slight_smile:

1 Like

what worked is finding the anchor tag and then clicking it - baduk-flash/baduk_flash.js at main · metaperl/baduk-flash · GitHub

1 Like

Yes theoretically that should work. If I get the focus back to the tab. What did work was finding the anchor tag and clicking it - baduk-flash/baduk_flash.js at main · metaperl/baduk-flash · GitHub


Not really theoretical - you can enter that in the console and see :slight_smile:

    toggleAI() {
        let dock = document.getElementsByClassName('Dock')[0]
        let anchors = dock.getElementsByTagName('a')

Did you test this on a ladder/tournament game? I don’t think you can rely on AI review being the 3rd element…

1 Like

I did not. Yes, I had hoped to be able to locate the element by ID. Or, to locate it using the content of the anchor tag… the method i found for searching via anchor tag content did not work… perhaps because of the italicized content before the actual text.

1 Like

Ah, yes, i have now re-implemented toggleAI() to send the keypress event and it is working. Thanks for the feedback.