Skip to content

Instantly share code, notes, and snippets.

View huchenme's full-sized avatar
🏃‍♂️

Hu Chen huchenme

🏃‍♂️
View GitHub Profile
@huchenme
huchenme / .travis.yml
Created April 18, 2018 09:45
Travis config for Gatsby automatically deployment
language: node_js
cache:
directories:
- ~/.npm
notifications:
email:
recipients:
- chen@huchen.me
on_success: always
on_failure: always
@huchenme
huchenme / manifest.json
Last active April 15, 2019 13:36
Hacker Tab
{
"manifest_version": 2,
"name": "Hacker Tab",
"author": "Hu Chen",
"version": "1.0.1",
"description": "Replace new tab screen with GitHub trending projects.",
"icons": {
"16": "16.png",
"48": "48.png",
"128": "128.png"
@huchenme
huchenme / index.html
Created February 19, 2019 15:30
hacker tab index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>New Tab</title>
<style>
@huchenme
huchenme / alltitles.js
Last active June 14, 2022 20:45
cheerio tutorial all titles
import cheerio from 'cheerio';
import fetch from 'node-fetch';
const data = await fetch('https://github.com/trending');
const $ = cheerio.load(await data.text());
const allTitles = $('.repo-list li')
.get()
.map(repo => {
const $repo = $(repo);
const title = $repo.find('h3').text();
@huchenme
huchenme / background.js
Created July 8, 2019 06:50
medium background script v1
chrome.runtime.onInstalled.addListener(() => {
console.log('onInstalled...');
// create alarm after extension is installed / upgraded
chrome.alarms.create('refresh', { periodInMinutes: 3 });
});
chrome.alarms.onAlarm.addListener((alarm) => {
console.log(alarm.name); // refresh
helloWorld();
});
@huchenme
huchenme / manifest.json
Created July 8, 2019 07:13
Medium background script article
{
"manifest_version": 2,
"name": "My Awesome Background script",
"version": "1.0.0",
"permissions": ["alarms"],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
@huchenme
huchenme / background.js
Last active May 30, 2021 09:46
medium background script fetch data
// create alarm for watchdog and fresh on installed/updated, and start fetch data
chrome.runtime.onInstalled.addListener(() => {
console.log('onInstalled....');
scheduleRequest();
scheduleWatchdog();
startRequest();
});
// fetch and save data when chrome restarted, alarm will continue running when chrome is restarted
chrome.runtime.onStartup.addListener(() => {