This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // import puppeteer เข้ามา | |
| const puppeteer = require('puppeteer'); | |
| (async () => { | |
| // เปิด Browser ขึ้นมา | |
| const browser = await puppeteer.launch(); | |
| // เปิด page ขึ้นมา | |
| const page = await browser.newPage(); | |
| // เข้าเว็บซักเว็บนึง | |
| await page.goto('https://www.kapook.com'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (async function () { | |
| firebase.initializeApp({ | |
| apiKey: '### FIREBASE API KEY ###', | |
| authDomain: '### FIREBASE AUTH DOMAIN ###', | |
| projectId: '### CLOUD FIRESTORE PROJECT ID ###', | |
| } | |
| ) | |
| let offlineEnable = await firebase.firestore().enablePersistence() | |
| // Initialize Cloud Firestore through firebase | |
| let db = firebase.firestore() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Type "Hello World" then press enter. | |
| var robot = require("robotjs"); | |
| // Type "Hello World". | |
| robot.typeString("Hello World"); | |
| // Press enter. | |
| robot.keyTap("enter"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| // เอาทั้งหมดนี่ไปใส่ใน Footer.php ของ theme | |
| if (‘serviceWorker’ in navigator) { | |
| window.addEventListener(‘load’, () => { | |
| navigator.serviceWorker.register(‘/sw.js’); | |
| }); | |
| } | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Import workbox ก่อน | |
| importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js") | |
| workbox.routing.registerRoute( | |
| new RegExp('.*\.js'), | |
| workbox.strategies.staleWhileRevalidate({ | |
| cacheName: 'js-cache', | |
| }) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| workbox.routing.registerRoute( | |
| new RegExp('^((?!wp-admin|wp-login).)*$'), | |
| workbox.strategies.staleWhileRevalidate({ | |
| cacheName: 'page-cache', | |
| plugins: [ | |
| new workbox.expiration.Plugin({ | |
| maxEntries: 10, | |
| maxAgeSeconds: 7 * 24 * 60 * 60 | |
| }) | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js") | |
| workbox.setConfig({ | |
| debug: false | |
| }) | |
| workbox.routing.registerRoute( | |
| new RegExp('.*(?:googleapis|gstatic)\.com.*$'), | |
| workbox.strategies.staleWhileRevalidate(), | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js") | |
| workbox.setConfig({ | |
| debug: false | |
| }) | |
| workbox.routing.registerRoute( | |
| new RegExp('.*(?:googleapis|gstatic)\.com.*$'), | |
| workbox.strategies.staleWhileRevalidate(), | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function addToCache(urls) { | |
| const pageCache = await window.caches.open('page-cache'); | |
| await pageCache.addAll(urls); | |
| } | |
| // Check that service workers are registered | |
| if ('serviceWorker' in navigator) { | |
| // Use the window load event to keep the page load performant | |
| window.addEventListener('load', () => { | |
| addToCache(['/hello-world/', '/main-page/']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| workbox.routing.setCatchHandler(({ url, event, params }) => { | |
| return caches.match('/offline/') | |
| }) |