ejsoon

Forum Replies Created

Viewing 5 posts - 96 through 100 (of 126 total)
  • Author
    Posts
  • in reply to: 往經典編輯器上加按鈕 #12798
    ejsoon
    Keymaster
    in reply to: unpkg.com及jsdelivr無法訪問 #12797
    ejsoon
    Keymaster
    in reply to: unpkg.com及jsdelivr無法訪問 #12795
    ejsoon
    Keymaster
    'use strict';
    
    const testPath = "npm2url/dist/index.cjs";
    const defaultProviders = {
      jsdelivr: (path) => `https://cdn.jsdelivr.net/npm/${path}`,
      unpkg: (path) => `https://unpkg.com/${path}`
    };
    async function checkUrl(url, signal) {
      const res = await fetch(url, {
        signal
      });
      if (!res.ok) {
        throw res;
      }
      await res.text();
    }
    class UrlBuilder {
      constructor() {
        this.providers = { ...defaultProviders };
        this.provider = "jsdelivr";
      }
      /**
       * Get the fastest provider name.
       * If none of the providers returns a valid response within `timeout`, an error will be thrown.
       */
      async getFastestProvider(timeout = 5e3, path = testPath) {
        const controller = new AbortController();
        let timer = 0;
        try {
          return await new Promise((resolve, reject) => {
            Promise.all(
              Object.entries(this.providers).map(async ([name, factory]) => {
                try {
                  await checkUrl(factory(path), controller.signal);
                  resolve(name);
                } catch {
                }
              })
            ).then(() => reject(new Error("All providers failed")));
            timer = setTimeout(reject, timeout, new Error("Timed out"));
          });
        } finally {
          controller.abort();
          clearTimeout(timer);
        }
      }
      /**
       * Set the current provider to the fastest provider found by `getFastestProvider`.
       */
      async findFastestProvider(timeout, path) {
        this.provider = await this.getFastestProvider(timeout, path);
        return this.provider;
      }
      setProvider(name, factory) {
        if (factory) {
          this.providers[name] = factory;
        } else {
          delete this.providers[name];
        }
      }
      getFullUrl(path, provider = this.provider) {
        if (path.includes("://")) {
          return path;
        }
        const factory = this.providers[provider];
        if (!factory) {
          throw new Error(`Provider ${provider} not found`);
        }
        return factory(path);
      }
    }
    const urlBuilder = new UrlBuilder();
    
    exports.UrlBuilder = UrlBuilder;
    exports.urlBuilder = urlBuilder;
    in reply to: nishiki字體表情 #12547
    ejsoon
    Keymaster

    8212 2014 — xw
    8213 2015 ― xww
    8216 2018 ‘ xyy
    8217 2019 ’ xzz
    8220 201c “ xy
    8221 201d ” xz
    8226 2022 • xk
    8229 2025 ‥ xll
    8230 2026 … xl
    8231 2027 ‧ xkk
    12288 3000   xs
    12289 3001 、 xb
    12290 3002 。 xx
    12295 3007 〇 xn
    12296 3008 〈 xtt
    12297 3009 〉 xuu
    12298 300a 《 xt
    12299 300b 》 xu
    12300 300c 「 xc
    12301 300d 」 xd
    12302 300e 『 xcc
    12303 300f 』 xdd
    12304 3010 【 xq
    12305 3011 】 xr
    12308 3014 〔 xo
    12309 3015 〕 xp
    12316 301c 〜 xm
    65073 fe31 ︱ xv
    65281 ff01 ! xj
    65288 ff08 ( xe
    65289 ff09 ) xf
    65292 ff0c , x
    65294 ff0e . xa
    65306 ff1a : xh
    65307 ff1b ; xg
    65311 ff1f ? xi
    65371 ff5b { xoo
    65372 ff5c | xvv
    65373 ff5d } xpp
    65374 ff5e ~ xmm

    in reply to: 嘗試燈箱插件(圖片點擊放大) #12476
    ejsoon
    Keymaster

    Lightbox with PhotoSwipe

Viewing 5 posts - 96 through 100 (of 126 total)