Skip to content

Instantly share code, notes, and snippets.

View chnbohwr's full-sized avatar
🐳
Enjoy development fun 享受開發樂趣

HsuChing(Hyman) chnbohwr

🐳
Enjoy development fun 享受開發樂趣
View GitHub Profile
const { parentPort } = require('worker_threads');
let b = 0;
for (let i = 0; i < 1000; i++) {
b += i;
}
parentPort.postMessage(b);
const { Worker } = require('worker_threads');
const path = require('path');
const worker1 = new Worker(path.resolve('./worker.js'));
worker1.on('message', (message) => {
console.log('main thread get message', message);
});
state = {
list: []
};
clickBtn = () => {
this.state.list.push({
id: Math.random(),
name: randomStr.generate(4)
});
this.setState(this.state);
const ele = document.querySelector('body > div.hero > div > div.test-wrapper.ng-scope > div');
let flag = true;
const mouseDownEvent = document.createEvent('MouseEvents');
mouseDownEvent.initEvent('mousedown', true, true);
const observer = new MutationObserver((mutations) => {
mutations.every((mutation) => {
if(mutation.target.classList.contains('view-go') && flag){
ele.dispatchEvent(mouseDownEvent);
flag = false;
return false;
const mouseDownEvent = document.createEvent('MouseEvents');
mouseDownEvent.initEvent('mousedown', true, true);
class MsgItem extends React.PureComponent {
render() {
return <li style={{ margin: "10px" }}> {this.props.msg} </li>;
}
}
import React, { Component } from 'react';
class MsgItem extends Component {
render() {
return <li style={{ margin: "10px" }}> {this.props.msg} </li>;
}
}
export default class App extends Component {
state = { messages: [] }
@chnbohwr
chnbohwr / webpack.config.js
Created March 21, 2018 03:12
webpack4 base config
const path = require('path');
const HtmlWebPackPlugin = require("html-webpack-plugin");
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
},
@chnbohwr
chnbohwr / ampExample.amp.html
Created February 22, 2018 03:19
amp html example
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title>Hello AMP world</title>
<link rel="canonical" href="hello-world.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-anim
const selectSize = (size) => {
const selector = document.querySelector('#exp-pdp-buying-tools-container > form > div.exp-pdp-size-and-quantity-container > div > div.exp-pdp-size-dropdown-container.nsg-form--drop-down--option-container.selectBox-options.nsg-form--drop-down.exp-pdp-size-dropdown.exp-pdp-dropdown.two-column-dropdown.selectBox-dropdown-menu > ul');
const children = Array.from(selector.children);
children.forEach(ele => {
const rel = ele.getAttribute('rel');
if (rel.substring(rel.indexOf(':'), rel.length) === `:${size}`) {
console.log('find ele', ele);
$('select[name="skuAndSize"]').val(rel);
$('#buyingtools-add-to-cart-button').click();
}