Skip to content

Instantly share code, notes, and snippets.

View thangman22's full-sized avatar

Warat Wongmaneekit thangman22

View GitHub Profile
<button popovertarget="my-popover" class="trigger-btn"> Open Popover </button>
<div id="my-popover" popover=manual>
<p>I am a popover with more information. Hit the close button or toggle to close me.<p>
<button class="close-btn" popovertarget="my-popover" popovertargetaction="hide">
<span aria-hidden="true">❌</span>
<span class="sr-only">Close</span>
</button>
</div>
<button popovertarget="my-popover"> Open Popover </button>
<div id="my-popover" popover>
<p>I am a popover with more information. Hit <kbd>esc</kbd> or click away to close me.<p>
</div>
const model = genAI.getGenerativeModel({ model: "gemini-pro" });
const prompt = `This is an article or news from website ${request.body.url}. Please summary to ${paragraph} paragraph in the ${language} lanaguage. This is full article ${plainContent}`;
const result = await model.generateContent([prompt]);
console.log(result.response.text());
@thangman22
thangman22 / extracts.js
Last active February 26, 2024 10:34
Extract content
import { extract } from '@extractus/article-extractor'
const input = 'https://travel.kapook.com/view241146.html'
try {
const article = await extract(input)
console.log(article)
// {
// "url": "https://travel.kapook.com/view241146.html",
// "title": "ร้านซาลาเปาเจ้าอร่อย กรุงเทพฯ ไส้แน่น พร้อมเดลิเวอรี่ถึงบ้าน",
@thangman22
thangman22 / inp.js
Created April 14, 2023 04:52
inp.js
// Use the attribution build:
import { onINP } from "web-vitals/attribution";
// Example reporting function that's passed to web-vitals:
const report = ({ name, value, attribution }) => {
 console.log(name);
 console.log(value);
 console.log(attribution.eventType);
 console.log(attribution.eventTarget);
};
// Pass the reporting function to the INP reporter:
const swReg = await navigator.serviceWorker.ready
const bgFetchRegistration = await swReg.backgroundFetch.fetch('postr-download', ['image.png'], {
title: 'Postr.me is capturing',
icons: [{
sizes: '512x512',
src: '/assets/img/icon-512.png',
type: 'image/png'
}],
downloadTotal: 60 * 1024 * 1024
})
addEventListener('backgroundfetchclick', async (event) => {
const bgFetch = event.registration
if (bgFetch.result === 'success') {
const cache = await caches.open('postr-download')
const records = await cache.matchAll()
const cacheList = []
for (const record of records) {
const recordDate = new Date(record.headers.get('date'))
cacheList.push({
url: record.url,
importScripts(
'https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js'
)
workbox.routing.registerRoute(
new workbox.routing.Route(({ request }) => {
return request.url.includes('/generate')
},
new workbox.strategies.CacheFirst({
// Use a custom cache name.
cacheName: 'postr-download',
addEventListener('backgroundfetchsuccess', event => {
event.updateUI({
title: 'Postr.me capturing sucessful',
icons: [{
sizes: '512x512',
src: '/assets/img/icon-512.png',
type: 'image/png'
}]
})
event.waitUntil(
const swReg = await navigator.serviceWorker.ready
if('BackgroundFetchManager' in self) {
await swReg.backgroundFetch.fetch('postr-download', ['image.png'], {
title: 'Postr.me is capturing',
icons: [{
sizes: '512x512',
src: '/assets/img/icon-512.png',
type: 'image/png'
}],
downloadTotal: 60 * 1024 * 1024