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
interface Window { | |
isbn: string | |
systemNames: any | |
} | |
declare var window: Window |
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
const getQueryString = () => { | |
const params = {} | |
location.search.substring(1).split('&').forEach((param) => { | |
const [key, value] = param.split('=') | |
// @ts-ignore | |
params[key] = decodeURIComponent(value) | |
}) | |
return params | |
} |
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 React, { useState} from 'react' | |
import useSWR from 'swr' | |
import { fetcher } from './fetcher' | |
const ENDPOINT = 'https://unitrad.calil.jp/v1/' | |
const REGION = 'recipe' | |
export const useSwr = (q: string) => { | |
const [url, setUrl] = useState(`${ENDPOINT}/search?region=${REGION}&free=${encodeURIComponent(q)}`) | |
const [interval, setPollingInterval] = useState(100) |
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
// taken from http://stackoverflow.com/questions/3665115/create-a-file-in-memory-for-user-to-download-not-through-server | |
function download(filename, text) { | |
const element = document.createElement("a"); | |
element.setAttribute( | |
"href", | |
"data:text/csv;charset=utf-8,\ufeff" + encodeURIComponent(text) | |
); | |
element.setAttribute("download", filename); | |
element.style.display = "none"; |
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
// モジュラス10 ウェイト2・1分割(Luhn formula)(M10W21) | |
// 1.数値の各桁に、下の桁から2・1・2・1・…の順番に係数(ウェイト)を掛けます。 | |
// 2.各桁の結果が2桁の場合には、十の位と一の位を分けて足し合わせます(分割)。 | |
// 3.それぞれの合計を求めます。 | |
// 4.合計を10で割り、余りを求めます(モジュラス)。 | |
// 5.この余りを 10 から引いたもの(10 - 余り)がチェックデジットです。ただし余りが0の場合はチェックデジットも「0」になります。 | |
const calcCheckDigit = (code: number) => { | |
const dividedNumber = code.toString().split('').reverse().map((n, index) => { | |
const number = parseInt(n) | |
if (index % 2 === 0) { |
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
const { WebClient } = require('@slack/web-api'); | |
require('dotenv').config(); | |
const token = process.env.SLACK_TOKEN; | |
console.log('token', token) | |
const web = new WebClient(token); | |
const slack = async (text) => { | |
const result = await web.chat.postMessage({ | |
text: text, | |
channel: '#bot', |
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
'use strict' | |
const fs = require('fs'); | |
require('dotenv').config() | |
const Gyazo = require('gyazo-api'); | |
const client = new Gyazo(process.env.GYAZO_TOKEN); | |
const gyazo = async (path) => { | |
return new Promise((resolve, reject) => { | |
client.upload(path, { |
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
function scrollWindowBy(value: number, duration: number, easingFunc: (t: number) => number) { | |
let startTime: number | |
const startPos: number = window.scrollY | |
const clientHeight: number = window.innerHeight | |
const maxScroll = document.body.scrollHeight - clientHeight; | |
const scrollIntendedDestination = startPos + value; | |
// low and high bounds for possible scroll destinations | |
const scrollEndValue = Math.min(Math.max(scrollIntendedDestination, 0), maxScroll) | |
// create recursive function to call every frame | |
const scroll = (timestamp: number) => { |
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 getOpenBDInfo(item): Promise<any> { | |
const books = await fetch('https://api.openbd.jp/v1/get?isbn='+item.isbn).then(r => r.json()).catch(error => console.log(error)) | |
if (books.length>0) { | |
const book = books[0] | |
console.log(book) | |
// 紹介・目次 | |
let description = null | |
let descriptionLong = null | |
let tableOfContents = null | |
const CollateralDetails = book.onix.CollateralDetail.TextContent |
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
// 144ページで、写真に使えるのは142ページ(1ページ目はタイトル) | |
// 2020は、captionData.length - 142 = 41 | |
// 後期は、A5サイズの44ページで | |
// | |
let captionData = [] |
NewerOlder