Posts related to programming category

How to trigger click event in Gmail

If you want to hack Gmail UI, to build web extension or any other similar tool that works on top of Gmail, you always want or need to trigger some DOM events in Gmail UI, like you want to click on some buttons/icons, to send out email, to make the compose window pop out, etc.You can't do it by simply use `click` function, either by Vanilla JS or jQuery, either `click` or `trigger` function can not achieve your goal.You need to do this by using [`Document.createEvent()`](https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent).Take `click` for example, you want to click an `icon`:```javascript const mouseDown = document.createEvent('MouseEvents') mouseDown.initEvent('mousedown', true, false) icon.dispatchEvent(mouseDown)const mouseUp = document.createEvent('MouseEvents') mouseUp.initEvent('mouseup', true, false) icon.dispatchEvent(mouseUp) ```You may want to make it as a function so that you can use it click any element.

Read More

Boost your Frontend development speed in China

Waiting for something is wasting time, especially when development, you always need to wait for compiling, wait for install dependencies...And if you are in China, this waiting time will be much longer because of some well known reason.Here are some changes that will save you some time in China if you are doing frontend development.## Ruby and Railschange your gem source to China mirror, source: https://ruby-china.org/```bash gem source -a https://gems.ruby-china.com ```## npmchange your npm source to China mirror, source , source: https://developer.aliyun.com/mirror/NPM```bash npm config set registry https://registry.npm.taobao.org ```or you can also install a `cnpm`, use `cnpm` rather than `npm`, to avoid change the source url permanently.```bash $ npm install -g cnpm --registry=https://registry.npm.taobao.org ```## yarnSame as npm.```bash yarn config set registry https://registry.npm.taobao.org --global ```there is no `cyarn` though## ubuntuchange sourcelist, check [this post](/change-ubuntu-18-04-source-to-china-mirror)## homebrewchange homebrew core source and repo to USTC (University of Science and Technology of China) [Mirror](https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git).- change brew.git: ```bash cd "$(brew --repo)" git remote set-url origin https://mirrors.ustc.edu.cn/brew.git ```- change homebrew-core.git ```bash cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git ```- change homebrew bottles source for `bash` user ```bash echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile ``` for `zsh` user ```bash echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc source ~/.zshrc ```

Read More