H::H spam keywords Fork

    @@ -14,17 +14,14 @@ // http://h.hatena.ne.jp/austinburk/81808835637056449 // http://h.hatena.ne.jp/austinburk/4623530768743273059 - // for "Hot Keyword" at right side e.g. - // http://h.hatena.ne.jp - // or "Related Keywords" by topics e.g. - // http://h.hatena.ne.jp/target?word=mail + // for "Hot Keyword" at right side or "Related Keywords" by topics + // TBC where in page to id:sudofox (async () => { 'use strict'; // Access-Control-Allow-Origin: http://h.hatena.ne.jp const KEYWORD_FILTER = 'https://haikuantispam.lightni.ng/api/recent_keywords.json'; - // returns - // { + // { <KEYWORD> : <SCORE> ... } { // https://html.spec.whatwg.org/#cors-settings-attributes
    @@ -36,10 +33,7 @@ mode: 'cors', // Referrer-Policy fallback referrer: '', - // https://w3c.github.io/webappsec-referrer-policy/#referrer-policies - // https://fetch.spec.whatwg.org/#concept-request-referrer-policy - // https://developer.mozilla.org/en-US/docs/Web/API/Request/referrerPolicy - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy + // [^1] Referrer-Policy referrerPolicy: 'no-referrer', }); const json = await res.json();
    @@ -54,11 +48,47 @@ credentials: 'omit', mode: 'cors', referrer: '', + // [^1] Referrer-Policy referrerPolicy: 'no-referrer', }); const json = await res.json(); - const positives = Object.entries(json).filter(([keyword, score]) => score >= 5); + const SPAM_THRESHOLD = 5; + const positives = Object.entries(json).filter(([, score]) => score >= SPAM_THRESHOLD); console.table(positives); + + const spamkey = new Map(positives); + document.body.querySelectorAll([ + '#related-targets a.keyword[href][title]', + ]).forEach(keylink => { + + // keyword link syntax; + // <a href="http://h.hatena.ne.jp/{ESCAPED_KEYWORD}" class="keyword" title="{KEYWORD}">{KEYWORD}</a> + const keyword = keylink.title; + if (!keyword) return; + + if (spamkey.has(keyword)) { + const container = keylink.parentElement; + //keyword.remove(); + console.table('spamkey', keyword, keylink, container); + container.style.opacity = '0.5'; + } + }); } })(); + + // DEV + // + // [1]: Referrer-Policy + // api + // https://developer.mozilla.org/en-US/docs/Web/API/Request/referrerPolicy + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy + // specs + // https://w3c.github.io/webappsec-referrer-policy/#referrer-policies + // https://fetch.spec.whatwg.org/#concept-request-referrer-policy + // + // test servers + // https://api.github.com + // https://httpstat.us + // https://httpstat.us/404 + // https://httpstat.us/200?sleep=60000
  • /*
     * @title H::H spam keywords
     * @description get Hatena Haiku spam keywords abstract
     * @include *://h.hatena.ne.jp/*
     * @license MIT License https://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // spam filter
    // http://let.hatelabo.jp/noromanba/let/hJmc6brdnsgL
    
    
    // via
    // http://h.hatena.ne.jp/austinburk/81808835637056449
    // http://h.hatena.ne.jp/austinburk/4623530768743273059
    
    // for "Hot Keyword" at right side or "Related Keywords" by topics
    // TBC where in page to id:sudofox
    (async () => {
        'use strict';
    
        // Access-Control-Allow-Origin: http://h.hatena.ne.jp
        const KEYWORD_FILTER = 'https://haikuantispam.lightni.ng/api/recent_keywords.json';
        // { <KEYWORD> : <SCORE> ...  }
    
        {
            // https://html.spec.whatwg.org/#cors-settings-attributes
            const res = await fetch(KEYWORD_FILTER, {
                // https://fetch.spec.whatwg.org/#request-headers
                // https://html.spec.whatwg.org/#initialise-the-document-object
                cache: 'no-cache',
                credentials: 'omit',
                mode: 'cors',
                // Referrer-Policy fallback
                referrer: '',
                // [^1] Referrer-Policy
                referrerPolicy: 'no-referrer',
            });
            const json = await res.json();
            const ordereds = Object.entries(json)
                .sort(([, score], [, zcore]) => score - zcore);
            console.dir(ordereds);
        }
    
        {
            const res = await fetch(KEYWORD_FILTER, {
                cache: 'no-cache',
                credentials: 'omit',
                mode: 'cors',
                referrer: '',
                // [^1] Referrer-Policy
                referrerPolicy: 'no-referrer',
            });
            const json = await res.json();
            const SPAM_THRESHOLD = 5;
            const positives = Object.entries(json).filter(([, score]) => score >= SPAM_THRESHOLD);
            console.table(positives);
    
            const spamkey = new Map(positives);
            document.body.querySelectorAll([
                '#related-targets a.keyword[href][title]',
            ]).forEach(keylink => {
    
                // keyword link syntax;
                // <a href="http://h.hatena.ne.jp/{ESCAPED_KEYWORD}" class="keyword" title="{KEYWORD}">{KEYWORD}</a>
                const keyword = keylink.title;
                if (!keyword) return;
    
                if (spamkey.has(keyword)) {
                    const container = keylink.parentElement;
                    //keyword.remove();
                    console.table('spamkey', keyword, keylink, container);
                    container.style.opacity = '0.5';
                }
            });
        }
    
    })();
    
    // DEV
    //
    // [1]: Referrer-Policy
    // api
    //  https://developer.mozilla.org/en-US/docs/Web/API/Request/referrerPolicy
    //  https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
    // specs
    //  https://w3c.github.io/webappsec-referrer-policy/#referrer-policies
    //  https://fetch.spec.whatwg.org/#concept-request-referrer-policy
    //
    // test servers
    //  https://api.github.com
    //  https://httpstat.us
    //   https://httpstat.us/404
    //   https://httpstat.us/200?sleep=60000
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。