=A!

    @@ -1,7 +1,7 @@ /* * @title =A! * @description Hatena Antenna force bulk checker - * @include http://a.hatena.ne.jp/HATENA_ID/checklist + * @include http://a.hatena.ne.jp/YOUR_ID/checklist * @contributor noromanba http://let.hatelabo.jp/noromanba/let/hLHUksLx6YMy * @contributor a-kuma3 http://h.hatena.ne.jp/a-kuma3/227133357563872599 (reviewer) * @license MIT License https://opensource.org/licenses/MIT @@ -35,28 +35,28 @@ // manual checker syntax; // http://a.hatena.ne.jp/check?url=<ENCODED_URL>[&robots=1] - // min interval: 5min c.f. + // min GET interval: 5min c.f. // http://a.hatena.ne.jp/check?url= const checker = new URL('http://a.hatena.ne.jp/check'); checker.searchParams.set('url', url); - // GET API await fetch(checker.href, { credentials: 'same-origin', }); }; const sleep = (wait = 1 * 1000) => { - return new window.Promise(res => setTimeout(res, wait)); + const Promise = window.Promise; // ESLint workaround + return new Promise(res => setTimeout(res, wait)); //return Promise.all([callback, res => setTimeout(res, wait)]); }; - // await do not working within Array callback loops, sucks - // i.e. can not use Array#forEach() and Array#map() et al. WTH + // NOTE await do not working within Array/NodeList callback loops, sucks + // i.e. can not use w/ Array#forEach() NodeList#forEach() and Array#map() et al. WTH // https://stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop // https://qiita.com/frameair/items/e7645066075666a13063 (async () => { - // TODO progress feedback; spinner or indicator + // TODO calm progress feedback; spinner or indicator window.alert('start'); for (const link of document.body.querySelectorAll([ 'a[href^="./editpage?cid="]',
  • /*
     * @title =A!
     * @description Hatena Antenna force bulk checker
     * @include http://a.hatena.ne.jp/YOUR_ID/checklist
     * @contributor noromanba   http://let.hatelabo.jp/noromanba/let/hLHUksLx6YMy
     * @contributor a-kuma3     http://h.hatena.ne.jp/a-kuma3/227133357563872599 (reviewer)
     * @license     MIT License https://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // TODO
    //  - error handling
    //  - request timeout
    //  - general page handling
    //   - http://a.hatena.ne.jp/HATENA_ID/
    
    // login required
    (() => {
        'use strict';
    
        const refresh = async (content) => {
            const headers = new Headers();
            headers.set('Content-Type', 'text/html;charset=euc-jp');
    
            const edit = await fetch(content.href, {
                // needs cookie
                credentials: 'same-origin',
                // XXX ignoring charset
                headers,
            });
            const txt = await edit.text();
            // TBD DOMParser()
            const url = (txt.match(/^<td><a href="(https?[^"]+)"\s+target="_blank"/m) || [])[1];
            if (!url) return;
    
            // manual checker syntax;
            //      http://a.hatena.ne.jp/check?url=<ENCODED_URL>[&robots=1]
            // min GET interval: 5min c.f.
            //  http://a.hatena.ne.jp/check?url=
            const checker = new URL('http://a.hatena.ne.jp/check');
            checker.searchParams.set('url', url);
    
            await fetch(checker.href, {
                credentials: 'same-origin',
            });
        };
    
        const sleep = (wait = 1 * 1000) => {
            const Promise = window.Promise; // ESLint workaround
            return new Promise(res => setTimeout(res, wait));
            //return Promise.all([callback, res => setTimeout(res, wait)]);
        };
    
        // NOTE await do not working within Array/NodeList callback loops, sucks
        //      i.e. can not use w/ Array#forEach() NodeList#forEach() and Array#map() et al. WTH
        // https://stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop
        // https://qiita.com/frameair/items/e7645066075666a13063
        (async () => {
            // TODO calm progress feedback; spinner or indicator
            window.alert('start');
            for (const link of document.body.querySelectorAll([
                'a[href^="./editpage?cid="]',
            ])) {
                refresh(link);
                await sleep();
                console.debug([ // eslint-disable-line no-console
                    link.textContent,
                    link.href,
                    '...',
                ].join());
            }
            window.alert('done');
        })();
    })();
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2018/01/21 04:18:00 - 2018-01-21
  2. 2018/01/02 10:48:20 - 2018-01-02
  3. 2018/01/02 10:31:06 - 2018-01-02
  4. 2017/12/31 06:44:10 - 2017-12-31
  5. 2017/12/30 06:18:15 - 2017-12-30
  6. 2017/12/30 05:37:53 - 2017-12-30
  7. 2017/12/27 08:56:10 - 2017-12-27
  8. 2017/12/27 08:07:28 - 2017-12-27
  9. 2017/12/27 07:44:21 - 2017-12-27
  10. 2017/12/27 07:27:35 - 2017-12-27
  11. 2017/12/27 07:25:24 - 2017-12-27