|
25 | 25 | import {
|
26 | 26 | connectExtensionHost,
|
27 | 27 | LookerExtensionSDK40,
|
28 |
| -} from '@looker/extension-sdk' |
| 28 | +} from '@looker/extension-sdk'; |
29 | 29 |
|
30 |
| -;(async () => { |
| 30 | +(async () => { |
31 | 31 | const extensionSdk = await connectExtensionHost()
|
32 | 32 | const sdk40 = LookerExtensionSDK40.createClient(extensionSdk)
|
33 | 33 | const result = await sdk40.me()
|
34 | 34 | const name = result.ok ? result.value.display_name : 'Unknown'
|
| 35 | + |
| 36 | + // Write the HTML content |
35 | 37 | document.write(`
|
36 | 38 | <style>
|
37 | 39 | body {
|
@@ -59,10 +61,32 @@ import {
|
59 | 61 | <h1>Looker Counter Extension</h1>
|
60 | 62 | <h2>Welcome ${name}</h2>
|
61 | 63 | <h3>This number will increase by one upon every click:</h3>
|
62 |
| - <div class="butt" onclick="event.target.innerHTML = +event.target.innerHTML + (event.shiftKey ? -1 : 1); event.preventDefault |
63 |
| - ()">0</div> |
| 64 | + <div class="butt" id="counterButton">0</div> |
64 | 65 | <h3>I hope you had fun with this Looker extension.</h3>
|
65 | 66 | <img width="200" src="https://docs.looker.com/assets/site_images/looker-logo.svg" />
|
66 | 67 | </div>
|
67 |
| -`) |
| 68 | +`); |
| 69 | + |
| 70 | +// Set up the click handler directly (without waiting for DOMContentLoaded) |
| 71 | +const counterButton = document.getElementById('counterButton'); |
| 72 | + |
| 73 | +if (!counterButton) { |
| 74 | + console.error('Counter button not found!') |
| 75 | + return |
| 76 | +} else { |
| 77 | + console.log('Counter button found:', counterButton) |
| 78 | +} |
| 79 | + |
| 80 | +counterButton.addEventListener('click', (event) => { |
| 81 | + console.log('Button clicked!') |
| 82 | + console.log('Current counter value:', counterButton.innerHTML) |
| 83 | + |
| 84 | + // Update the counter value |
| 85 | + counterButton.innerHTML = +counterButton.innerHTML + (event.shiftKey ? -1 : 1) |
| 86 | + |
| 87 | + console.log('Updated counter value:', counterButton.innerHTML) |
| 88 | + event.preventDefault() |
| 89 | +}); |
| 90 | + |
| 91 | + |
68 | 92 | })()
|
0 commit comments