Files
chrome-extensions-samples/functional-samples/tutorial.quick-api-reference/content.js
Pasquale Riello b9df791e76 Fix #1084: quick-api-reference sample (#1099)
* Add README.md

* Fix issue related to website update

Updated CSS selector and tweaked the TIP button

* Update content.js

Keeping newline

* Update CSS styles

Change padding, height and font sizes to make the button style more consistent with the navigation bar

* Update functional-samples/tutorial.quick-api-reference/content.js

* Update functional-samples/tutorial.quick-api-reference/README.md

* Update functional-samples/tutorial.quick-api-reference/README.md

---------

Co-authored-by: Oliver Dunk <oliver@oliverdunk.com>
2024-02-27 14:07:16 +00:00

26 lines
841 B
JavaScript

// Popover API https://chromestatus.com/feature/5463833265045504
(async () => {
const nav = document.querySelector('.upper-tabs > nav');
const { tip } = await chrome.runtime.sendMessage({ greeting: 'tip' });
const tipWidget = createDomElement(`
<button type="button" popovertarget="tip-popover" popovertargetaction="show" style="padding: 0 12px; height: 36px;">
<span style="display: block; font: var(--devsite-link-font,500 14px/20px var(--devsite-primary-font-family));">Tip</span>
</button>
`);
const popover = createDomElement(
`<div id='tip-popover' popover style="margin: auto;">${tip}</div>`
);
document.body.append(popover);
nav.append(tipWidget);
})();
function createDomElement(html) {
const dom = new DOMParser().parseFromString(html, 'text/html');
return dom.body.firstElementChild;
}