lee8oi / Auto Reject

// ==UserScript==
// @name         Auto Reject
// @namespace    https://plus.google.com/u/0/+LeeForestHimself
// @version      1.1
// @license      MPL-2.0
// @description  Auto reject all the posts in 'Likely Spam' section of a Community on Google+.
// @author       Lee Forest
// @match        https://plus.google.com/communities/*/modmodmod
// @match        https://plus.google.com/u/0/communities/*/modmodmod
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    function loadMore() {
        getXpathElem('//*[@id="i1"]/div[2]/div[2]/div/div').click(); // "Load More" Xpath
    }
    function getXpathElem(path) {
        return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    }
    function gridReject() {
        var paths = [];
        for (var x = 0; x < 4; x++) {
            for (var y = 0; y < 4; y++) {
                var elem = getXpathElem('//*[@id="i1"]/div[2]/div[1]/div['+x+']/c-wiz['+y+']/div[3]/div[1]/div[3]');
                if (elem !== null && elem !== undefined) {
                    elem.click();
                    //elem.parentNode.removeChild(elem); // remove reject button
                }
            }
        }
        var wizCount = document.getElementsByTagName('c-wiz').length;
        if (wizCount > 10) { setTimeout(gridReject, 3000) }
        if (wizCount < 20) { loadMore() }
    }
    setTimeout(gridReject, 2000);
    loadMore();
})();