Skip to content

Instantly share code, notes, and snippets.

View diwao's full-sized avatar

Daisuke Iwao diwao

View GitHub Profile
@diwao
diwao / deleteFiles.js
Last active September 21, 2019 14:09
Delete files in directory.
'use strict';
const fs = require('fs');
const dir = './src/diff';
fs.readdir(dir, function(err, files){
if(err){
throw err;
}
files.forEach(function(file){
@diwao
diwao / getBrowser.js
Last active August 6, 2018 02:34
get browser (type and version) from user agent.
export default () => {
const ua = window.navigator.userAgent.toLowerCase();
const obj = {};
//ieかどうか判定
obj.isIE = (ua.indexOf('msie') >= 0 || ua.indexOf('trident') >= 0);
//firefoxかどうかの判定
obj.isFirefox = (ua.indexOf('firefox') >= 0);
//chromeかどうかの判定
obj.isChrome = (ua.indexOf('chrome') >= 0);
//safariかどうかの判定
@diwao
diwao / clickFlg.js
Created August 6, 2018 02:27
state management of click
export default class {
constructor() {
this.flg = false;
}
toggle() {
return this.flg = !this.flg;
}
get() {
@diwao
diwao / cookie.js
Created August 6, 2018 02:25
cookie class
@diwao
diwao / ua.js
Created August 6, 2018 02:21
check user agent
export default class {
constructor() {
this.ua = window.navigator.userAgent.toLowerCase();
}
isIE() {
return this.ua.indexOf('msie') >= 0 || this.ua.indexOf('trident') >= 0;
}
isFF() {
@diwao
diwao / get.js
Last active August 6, 2018 02:20
get data use promise
const Promise = require('es6-promise').Promise;
export default (path, param) => {
return new Promise(function(resolve, reject) {
$.ajax({
url: path,
data: param,
type: 'GET',
timeout: 60000,
datatype: 'json'
// ドメインを取得
export default () => {
return location.protocol + '//' + location.host;
}
@diwao
diwao / getParam.js
Last active August 6, 2018 02:02
get parameter from url
export default (name) => {
const url = location.href;
let params;
let param = [];
let str = url.replace(/[?&]/g, '<>');
params = str.split('<>');
for (let i = 0; i < params.length; i++) {
param.push(params[i].split('='));
}
for (let i = 0; i < param.length; i++) {
@diwao
diwao / getDirPath.js
Last active August 6, 2018 01:58
script about location
// ファイル名やパラメータを除いたパス(ディレクトリ止まり)を取得
export default () => {
return location.pathname.replace(location.pathname.match(/[^/]+?$/g), '');
}
@diwao
diwao / test.js
Created October 21, 2016 02:21
testです
window.onload = function(){
console.log('hello, world');
};