Skip to content

Instantly share code, notes, and snippets.

View letswritetw's full-sized avatar
🎯
Focusing

Let's Write - August letswritetw

🎯
Focusing
View GitHub Profile
@letswritetw
letswritetw / line-rich-menu-create.sh
Last active March 10, 2024 14:18
line-rich-menu
curl -v -X POST https://api.line.me/v2/bot/richmenu \
-H 'Authorization: Bearer {token}' \
-H 'Content-Type: application/json' \
-d \
'{
"size": {
"width": 2500,
"height": 843
},
"selected": false,
@letswritetw
letswritetw / line-signature-demo.js
Last active January 17, 2024 03:54
line-signature
const lineConfig = {
channelAccessToken: 'XXXXXXXXXXX',
channelSecret: 'XXXXXXXXXXX'
};
const crypto = require('crypto');
const channelSecret = lineConfig.channelSecret;
app.post('/webhook', line.middleware(lineConfig), (req, res) => {
// 給 LINE 的 body 要是 string
@letswritetw
letswritetw / work.js
Created November 5, 2023 01:57
web-worker.js
// 引用 axios
importScripts('../dist/axios.min.js');
// 設定最大並行請求數限制
const MAX_CONCURRENT_REQUESTS = 5;
let activeRequests = 0;
let queue = [];
self.onmessage = e => {
@letswritetw
letswritetw / github-imoprt.js
Last active August 18, 2023 14:18
gas-import-postman-collections
const postmanApiKey = '請貼上 Postman API Key';
const githubToken = '請貼上 GitHub Access Token';
const repoOwner = '請貼上 GitHub 帳號名稱';
// 以下請貼上要匯進 Postman Collection 的清單
const repoList = [
{
repoName: 'postman-backup-demo',
filePath: 'Postman Collections/postman-backup-demo.json'
}
@letswritetw
letswritetw / gitlab-imoprt.js
Last active August 18, 2023 14:17
gas-import-postman-collections
const gitLabToken = '請貼上 GitHub Access Token';
const postmanApiKey = '請貼上 Postman API Key';
// 以下請貼上要匯進 Postman Collection 的清單
const repoList = [
{
projectId: '48419806',
filePath: 'Postman_Collections/postman-backup-demo.json'
}
];
@letswritetw
letswritetw / index.js
Created July 14, 2023 13:07
gas-backup-postman-collections
// 存進雲端
function saveJsonToDrive({ name, json }) {
const today = getToday({ divider: '-' });
const folderName = name; // 資料夾名稱
const time = new Date().getTime();
const fileName = `${time}_backup.json`; // 檔案名稱
// 取得「備份」資料夾
{
"name": "Let's Write",
"short_name": "Let's Write",
"description": "前端工程師 August 的學習筆記 — solving problems, in simple ways.",
"start_url": "./?utm_source=PWA&utm_medium=home_screen&utm_campaign=pwa",
"id": "/?utm_source=PWA&utm_medium=home_screen&utm_campaign=pwa",
"display": "standalone",
"background_color": "#FAFAFA",
"theme_color": "#00A7E5",
"orientation": "portrait-primary",
@letswritetw
letswritetw / pwa-use-sw.js
Last active January 14, 2023 14:51
pwa-use
var preCacheFile = 'pre-v1.1.0'; // 存在 Cache Storage 的資料夾名,預存用
var autoCacheFile = 'letswrite-v1.1.0'; // 存在 Cache Storage 的資料夾名稱,自動存用
// 一定要存下的檔案清單
// 比如 404.html、logo.svg,不會自動出現在每頁的 request 上,但當使用者是 offline 時又必要會看到的
const assets = [
'/?utm_source=PWA&utm_medium=home_screen&utm_campaign=pwa',
'/cdn/logo/72.png',
'/cdn/logo/96.png',
'/cdn/logo/128.png',
<script async src="https://telegram.org/js/telegram-widget.js?14"
data-telegram-login="Telegram 機器人的「使用者名稱」"
data-size="large"
data-auth-url="要轉去哪個 URL 做後端處理"
data-request-access="write"></script>
@letswritetw
letswritetw / IntersectionObserver-basic.js
Last active October 27, 2022 19:38
IntersectionObserver
// new IntersectionObserver = 觀察器
// new IntersectionObserver 的 callback 會產生 IntersectionObserverEntry,就是被獵物
/*
3步驟:
1 建立觀察器(observer),如果觀察器的鏡頭(root)沒有指定,就是指 window:
const observer = new IntersectionObserver(callback, [option])
2 指定觀察器要觀察的目標: observer.observe(el)
2 用callback看觀察目標進入到觀察器了沒?
entry[0].isIntersecting || !entry[0].isIntersecting
3 目標進入後,要不要停止觀察目標? observer.unobserve(el)