Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Let's Write - Augustus letswritetw

🎯
Focusing
View GitHub Profile
@letswritetw
letswritetw / vuepress-document-style-component.vue
Last active Apr 8, 2021
vuepress-document-style-component
View vuepress-document-style-component.vue
<template lang="pug">
a.btn.btn-main(:href="uri" target="_blank") {{ title }}
</template>
<script>
export default {
data: () => {
return {}
},
props: ['title', 'uri']
View dayjs-last-week-month.js
let currentYear = dayjs().year(); // 本年
let currentMonth = dayjs().month() + 1; // 本月,dayjs 的月份值是「該月 - 1」,因此要 +1 回來
// 本月如果是 1 月,上個月就要是 12 月,並且年份減 1
let lastMonth;
if(currentMonth === 1) {
lastMonth = 12;
currentYear -= 1;
} else {
lastMonth = currentMonth - 1;
View ig-oembed-full.html
<div id="ig-iframe"></div>
<script src="https://www.instagram.com/embed.js"></script>
<script>
const getToken = '部署完取得的網址';
const igUri = 'IG 貼文的網址';
const hideCaption = true; // 選填,要不要隱藏描述,true 隱藏、false 不隱藏,預設為 false
const maxWidth = 400; // 選填,貼文的最大寬度是多少
fetch(getToken)
View ig-oembed-content.js
const getToken = '部署完取得的網址';
const igUri = 'IG 貼文的網址';
const hideCaption = true; // 要不要隱藏描述,true 隱藏、false 不隱藏
fetch(getToken)
.then(response => response.json())
.then(response => response.access_token)
.then(token => {
fetch(`https://graph.facebook.com/v9.0/instagram_oembed?url=${igUri}&access_token=${token}&hidecaption=${hideCaption}`)
.then(response => response.json())
View ig-oembed-get-token.js
const getToken = '部署完取得的網址';
fetch(getToken)
.then(response => response.json())
.then(response => {
console.log(response);
})
View ig-oembed-token.js
var appId = '從 FB 後台取得的「應用程式編號」';
var secret = '從 FB 後台取得的「應用程式密鑰」';
var uri = 'https://graph.facebook.com/oauth/access_token?client_id=' + appId + '&client_secret=' + secret + '&grant_type=client_credentials';
function doGet(e) {
var response = UrlFetchApp.fetch(uri);
return ContentService.createTextOutput(response).setMimeType(ContentService.MimeType.JSON);
}
View firebase-auth-fb.js
const provider = new firebase.auth.FacebookAuthProvider();
firebase
.auth()
.signInWithPopup(provider)
.then((result) => {
var credential = result.credential;
var user = result.user;
var accessToken = credential.accessToken;
})
.catch((error) => {
View firebase-auth-google-redirect.js
firebase.auth()
.getRedirectResult()
.then((result) => {
if (result.credential) {
var credential = result.credential;
var token = credential.accessToken;
}
var user = result.user;
}).catch((error) => {
var errorCode = error.code;
@letswritetw
letswritetw / firebase-auto-google.js
Last active Feb 1, 2021
firebase-auth-google-fb
View firebase-auto-google.js
const provider = new firebase.auth.GoogleAuthProvider();
firebase.auth()
.signInWithPopup(provider)
.then((result) => {
var credential = result.credential;
var token = credential.accessToken;
var user = result.user;
}).catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
View telegram-login-redirect.html
<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>