Sudohaiku

    
      
  • // ==UserScript==
    // @name        Sudohaiku
    // @namespace   apburk@lightni.ng
    // @description Filter spam using data from Haiku Anti-Spam. Very first (beta/testing/unreleased) version, soon to be improved.
    // @include     http://h.hatena.ne.jp/*
    // @version     1
    // @run-at      document-idle
    // ==/UserScript==
    
    
    
    //document.addEventListener("DOMContentLoaded", addNewHaikuListener);
    function addNewHaikuListener() {
    
        var userScores;
    
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                userScores = JSON.parse(this.responseText);
    
            }
        };
        xmlhttp.open("GET", "https://haikuantispam.lightni.ng/api/recent_scores.json", false);
        xmlhttp.send();
    
    
    
        var initialEntryList = document.querySelector("body#index div#container div#main div.stream div.streambody div.entries div.tl-entry-list");
        initialEntryList.childNodes.forEach(function(entry) {
            if (entry.querySelector("div.list-body") != null) {
                username = entry.querySelector("div.list-body > div.info > span.username > a").title.substring(3);
    
                if (username in userScores && userScores[username] >= 5) {
                    console.log("Hid spam from " +username);
                    entry.innerHTML = "<i>Spam hidden (id:" + username + " has avg spam score " + userScores[username] + " >= 5)</i>";
                    entry.style.padding = "0px 0px 0px 10px";
                    entry.style["font-size"] = "10px";
    
                }
            }
        });
    
        var haikuList = document.querySelector("body#index div#container div#main div.stream div.streambody div.entries div.tl-entry-list");
        haikuList.addEventListener( 'DOMNodeInserted', function ( event ) {
    
            if( event.target.parentNode == haikuList ) {
                [].forEach.call(event.target.children, function(element) {
                    username = element.querySelector("div.list-body > div.info > span.username > a").title.substring(3);
    
                    if (username in userScores && userScores[username] >= 5) {
                        console.log("Hid spam from " +username);
                        element.innerHTML = "<i>Spam hidden (id:" + username + " has avg spam score " + userScores[username] + " >= 5)</i>";
                        element.style.padding = "0px 0px 0px 10px";
                        element.style["font-size"] = "10px";
                    }
                });
            }
        }, false );
    }
    addNewHaikuListener();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2018/05/10 09:43:08 - 2018-05-10
  2. 2018/05/10 08:29:19 - 2018-05-10
  3. 2018/05/10 08:28:24 - 2018-05-10