=A!

    @@ -3,22 +3,22 @@ * @description Hatena Antenna force bulk checker * @include http://a.hatena.ne.jp/HATENA_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 - * @private waiting review */ // TODO -// - try-catch -// - server safe interval, avoid (D)DoS +// - error handling +// - request timeout +// - general page handling +// - http://a.hatena.ne.jp/HATENA_ID/ // login required (() => { 'use strict'; - document.body.querySelectorAll([ - 'a[href^="./editpage?cid="]', - ]).forEach(async content => { + const refresh = async (content) => { const headers = new Headers(); headers.set('Content-Type', 'text/html;charset=euc-jp'); @@ -40,10 +40,36 @@ const checker = new URL('http://a.hatena.ne.jp/check'); checker.searchParams.set('url', url); - // working? + // GET API await fetch(checker.href, { credentials: 'same-origin', }); - }); + }; + + const sleep = (wait = 1 * 1000) => { + return new window.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 + // 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 + 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'); + })(); })();
  • /*
     * @title =A!
     * @description Hatena Antenna force bulk checker
     * @include http://a.hatena.ne.jp/HATENA_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 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));
            //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
        // 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
            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