Skip to content

Instantly share code, notes, and snippets.

@julenwang
julenwang / useAsyncBlocker.ts
Created April 11, 2023 10:25
useAsyncBlocker for react-router v6.7+
import { useCallback, useRef } from 'react';
import { unstable_useBlocker as useBlocker, useBeforeUnload, useNavigate } from 'react-router-dom';
function useAsyncBlocker(isBlockFn: () => Promise<boolean>) {
const navigate = useNavigate();
const isBlockRef = useRef(true);
const blockerArgsRef = useRef<Parameters<Exclude<Parameters<typeof useBlocker>[0], boolean>>[0]>();
const willBlock = useCallback(async () => {
@julenwang
julenwang / extract-subtitles-from-mkv.md
Created April 8, 2023 14:04 — forked from pavelbinar/extract-subtitles-from-mkv.md
Extract subtitles from .mkv files on Mac OS X
// ==UserScript==
// @name copyNcRawsAllUrls.js
// @version 0.3.0
// @description 2023/06/29
// @author Julen
// @match https://ouo.si/*
// @grant none
// ==/UserScript==
(function () {
// ==UserScript==
// @name copyLilithAllUrls.js
// @version 0.1.0
// @description 2022/05/05
// @author Julen
// @match https://*.lilith001.workers.dev
// @grant none
// ==/UserScript==
(function () {
@julenwang
julenwang / salaDictCustom.css
Last active March 26, 2024 12:11
sala dict custom css
.dictPanel-FloatBox-Container.saladict-theme .dictPanel-Root {
transform: translate(0px, 70px);
}
.dictPanel-FloatBox-Container.saladict-theme .dictPanel-Head {
display: none;
}
.dictPanel-FloatBox-Container.saladict-theme .mtaBox-DrawerBtn {
display: none;
}
.dictPanel-FloatBox-Container.saladict-theme .waveformBox {
@julenwang
julenwang / ComposeSharp.ts
Last active November 1, 2022 09:23
Merge two types, overlapping part use union
type IsPartial<T> = T extends Required<T> ? false : true;
type NoPartial<Sharp1, Sharp2> = IsPartial<Sharp1> & IsPartial<Sharp2> extends true ? false : true;
// Merge two types, overlapping part use union
export type ComposeSharp<
Sharp1,
Sharp2,
InterKeys extends keyof Sharp1 & keyof Sharp2 = keyof Sharp1 & keyof Sharp2
> = UnionToIntersection<
InterKeys extends unknown
? NoPartial<Pick<Sharp1, InterKeys>, Pick<Sharp2, InterKeys>> extends true
payload:
- IP-CIDR,8.8.8.8/32
# - IP-CIDR,1.1.1.1/32
@julenwang
julenwang / useStateWithCallback.ts
Created June 2, 2022 05:56
useStateWithCallback.ts
import React, { useEffect, useRef, useState } from 'react';
export const useStateWithCallback = <T>(
initialState: T
): [state: T, setState: (updatedState: React.SetStateAction<T>, callback?: (updatedState: T) => void) => void] => {
const [state, setState] = useState<T>(initialState);
const callbackRef = useRef<(updated: T) => void>();
const handleSetState = (updatedState: React.SetStateAction<T>, callback?: (updatedState: T) => void) => {
callbackRef.current = callback;
@julenwang
julenwang / copyDmhyAllMagnet.js
Last active May 20, 2022 05:12
copy dmhy all magnet urls
// ==UserScript==
// @name copyDmhyAllMagnet.js
// @version 0.1.1
// @description 2022/05/05
// @author Julen
// @match https://share.dmhy.org/topics/list?*
// @icon https://www.google.com/s2/favicons?sz=64&domain=dmhy.org
// @grant none
// ==/UserScript==
@julenwang
julenwang / deleteLeetcodeNodes.js
Last active December 10, 2021 08:26
删除 leetcode 题解页的额外元素,用于网页截图
// ==UserScript==
// @name deleteLeetcodeNodes.js
// @namespace manual
// @match https://leetcode-cn.com/*
// @version 0.3
// @author Julen
// @description 2021/12/10 下午3:30:44
// @grant GM_registerMenuCommand
// ==/UserScript==