Skip to content

Instantly share code, notes, and snippets.

View sorrycc's full-sized avatar
🌻
Working on UmiJS

chencheng (云谦) sorrycc

🌻
Working on UmiJS
View GitHub Profile
export function createRuntime(makoModules, entryModuleId) {
const modulesRegistry = {};
function requireModule(moduleId) {
if (modulesRegistry[moduleId] !== undefined) {
return modulesRegistry[moduleId].exports;
}
const module = {
exports: {},
// ==UserScript==
// @name YuQue x 霞鹜文楷
// @namespace http://sorrycc.com/
// @version 0.1
// @description 使用「霞鹜文楷」字体
// @author [email protected]
// @match https://yuque.antfin.com/*
// @match https://*.yuque.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none

任务二,

1、抓取 http://www.paulgraham.com/read.html 的内容
2、从中提取「标题」和「链接」,存成对象或者数组,保存到本地 articles.json
3、抓取每个「链接」的内容,并保存到 articles 目录下,比如 articles/read.html
4、分析其中的正文部分,保存到 pure-articles 目录下,比如 pure-articles/read.html
5、后面会做翻译(这个先不做)

一些常见问题(FAQ),

function getContainer(root) {
root ||= document.body;
if (!root.innerText) return null;
const totalWords = root.innerText.match(/\S+/g).length;
let ps = root.querySelectorAll('p');
if (!ps.length) ps = root.querySelectorAll('div');
if (!ps.length) return null;
@sorrycc
sorrycc / translator.js
Last active December 5, 2022 05:06
Translator
function getContainer(root) {
root ||= document.body;
if (!root.innerText) return null;
const totalWords = root.innerText.match(/\S+/g).length;
let ps = root.querySelectorAll('p');
if (!ps.length) ps = root.querySelectorAll('div');
if (!ps.length) return null;
import { useSyncExternalStore } from 'use-sync-external-store/shim'
import {
affectedToPathList,
createProxy as createProxyToCompare,
isChanged,
} from 'proxy-compare';
import {useCallback, useDebugValue, useEffect, useMemo, useRef} from "react";
type ProxyObject = {
listeners: Set<Function>;
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
function createStore(createState: Function) {
let state: any;
const listeners = new Set<Function>();
const setState = (partial: any, replace: any) => {
const nextState = typeof partial === 'function' ? partial(state) : partial;
if (nextState !== state) {
const previousState = state;
state = replace ? nextState : Object.assign({}, state, nextState);
import invariant from 'tiny-invariant';
import 'zx/globals';
import { event, info } from '../logger';
// Patched: use domino-ext instead of domino in turndown.umd.js
// ref: https://github.com/fgnass/domino/issues/146
// @ts-ignore
import TurndownService from 'turndown/lib/turndown.umd.js';
(async () => {
import invariant from 'tiny-invariant';
import 'zx/globals';
import { event, info } from '../logger';
const cwd = process.cwd();
const API_URL = 'http://localhost:8080/translate';
const cacheFile = path.join(__dirname, 'translate.cache.json');
const cacheData = fs.existsSync(cacheFile)
? JSON.parse(fs.readFileSync(cacheFile, 'utf-8'))
: {};
import { useCallback, useEffect, useSyncExternalStore } from 'react';
const defaultFetcher = (url: string) => {
return fetch(url).then((r) => r.json());
};
const cache = createCache(new Map());
initFocus(() => {
for (const key in EVENT_REVALIDATORS) {
if (EVENT_REVALIDATORS[key][0]) {