Skip to content

Instantly share code, notes, and snippets.

@Phalacrocorax
Last active August 14, 2020 17:03
Show Gist options
  • Select an option

  • Save Phalacrocorax/f41f98432ad02a22e337cfdeeab768b5 to your computer and use it in GitHub Desktop.

Select an option

Save Phalacrocorax/f41f98432ad02a22e337cfdeeab768b5 to your computer and use it in GitHub Desktop.
[snippets] javascripts/js

console Logger

export default function logger() {
    var logger = function logger(){
    };

    logger.LEVEL = {
        RUN   : 0,
        ERROR : 1,
        WARN  : 2,
        LOG   : 3,
        INFO  : 4,
        DEBUG : 5,
        FULL  : 5,
    };
    logger.level = logger.LEVEL.FULL;

    logger.debug = function(msg){ (this.level >= this.LEVEL.DEBUG) && console.debug(msg); };
    logger.info  = function(msg){ (this.level >= this.LEVEL.INFO) && console.info("%c "+ msg, "color: green"); };
    logger.log   = function(msg){ (this.level >= this.LEVEL.LOG) && console.log(msg); };
    logger.warn  = function(msg){ (this.level >= this.LEVEL.WARN) && console.warn(msg); };
    logger.error = function(msg){ (this.level >= this.LEVEL.ERROR) && console.error(msg); };
    return logger;
}

JS 从入门到放弃

叨叨叨=babel?

Fashion frontend uh-huh

从gulp, sass, webpack, AMD, CommonJS, vuejs, vuex, es2015, babel, transpile 层出不穷。 本来npm这些nodejs之流就苦手 但是12条专业的JavaScript规则 | kancloud中有提到JS应该自动构建,实际使用中也确实的体会到了方便之处, 比如用了sass之后,再去改css简直就是折磨。

transpile

JavaScript Transpilers: What They Are & Why We Need Them

JS报错

JavaScript 调试常见报错以及修复方法

Uncaught TypeError / Uncaught RangeError / Uncaught URIError / InvalidStateError 有个一个自己常见的error: uncaught(in promise) message(The message port closed before a response was received)
目前只找到一篇讲promise的文章: You're Missing the Point of Promises

@Phalacrocorax
Copy link
Author

Grab Data | js

755 daily latest posting time analysis

<a class="_2pN-CR8- Link" href="/okada-nana/18950" data-reactid="415"><time datetime="2018-04-25T10:19:40+09:00" data-reactid="416">1分前</time></a>
<a class="_2pN-CR8- Link" href="/okada-nana/18947" data-reactid="301"><time datetime="2018-04-24T22:31:26+09:00" data-reactid="302">11時間前</time></a>
var time = document.getElementsByTagName('time');
var savedata = '';
for(var i=time.length-1;i>=0;i--)
{
	savedata+=time[i].dateTime+'\n';
}

setTimeout(function(){
  window.scrollTo( 0, 0 );
}, 500);

export_raw('okd.csv', savedata)
export_raw('yuiri.csv', savedata)

# export into table
select substr(post,1,10),max(substr(post,12,16)),max(post) from test_20180425
where substr(post,12,16) >= '14:00' or substr(post,12,16) <= '04:00'
group by substr(post,1,10)
order by substr(post,1,10)

Get tweets with replies

var texts = [];
//node = document.querySelectorAll('article,span,time');
node = document.querySelectorAll('div[lang="ja"],*[dir="auto"],time');
for(i = 0;i < node.length; i++)
{
    if(node[i].nodeName == "TIME"){
        texts.push(node[i].getAttribute("datetime"));
    }else{
        texts.push(node[i].textContent);
    }
}
var saveData = texts.join("\n");
console.log(saveData);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment