PF2M / Miiverse+

// ==UserScript==
// @name         Miiverse+
// @namespace    http://pokemonfan2000man.x10.bz/
// @version      Prerelease
// @description  Miiverse enhancement script.
// @author       PF2M
// @match        https://miiverse.nintendo.net/*
// @grant        none
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';

    //Edit the script's settings here.
    var BlockAllAds = "on";
    var ShowAllSpoilers = "off";
    var ExtendCommentLimit = "on";
    var DisableBackwardsNotifs = "on";

    //Everything below here is important code. Don't mess with it unless you know what you're doing.

    //Set functions
    function htmlReplace(a,b,element){
        if(!element)element=document.body;
        var nodes=element.childNodes;
        for(var n=0;n<nodes.length;n++) {
            if(nodes[n].nodeType==Node.TEXT_NODE) {
                nodes[n].textContent=nodes[n].textContent.replace(new RegExp(a,'gi'),b); }
            else{htmlReplace(a,b,nodes[n]);}}}
    var token = document.getElementsByTagName("body")[0].getAttribute("data-token");

    //Add post form to activity feed
    if(window.location.href.indexOf("/activity") > -1) {
        $('.headline').after('<script>function updateInput(titl,comm){ document.getElementById("titleid").value = titl;document.getElementById("communityid").value = comm; }</script><form id="post-form" method="post" action="/posts" class="" data-post-subtype="default" name="test-post-default-form"><center><select onchange="updateInput(this.value,this.options[this.selectedIndex].title)"><option disabled>Non-Redesigned Communities (Visible):</option><option value="14866558072985245728" title="14866558073038702637">New Super Luigi U Community</option><option value="14866558073007174237" title="14866558073007174239">The Legend of Zelda Series Community</option><option value="14866558073622318921" title="14866558073622322339">Game Tips Community</option><option disabled></option><option disabled>Redesigned Communities (Activity Feed):</option><option value="14866558073037299863" title="14866558073037299866">Super Smash Bros. for 3DS/Wii U Community</option><option value="6437256808786423085" title="6437256808786423092">YouTube Community</option><option value="14866558073081608988" title="14866558073081608996">Wii Fit U Community</option><option value="6437256808834406317" title="6437256808834406327">Minecraft: Wii U Edition Community</option><option value="6437256809081804590" title="6437256809081804604">Streetpass Mii Plaza Community</option></select></center><input type="hidden" name="token" value="'+token+'"><input type="hidden" name="olv_title_id" id="titleid" value="14866558072985245728"><input type="hidden" name="olv_community_id" id="communityid" value="14866558073038702637"><div class="post-count-container"><div class="textarea-feedback" style="float:left;"><font color="#646464" style="font-size: 13px; padding: 0 3px 0 7px;">400</font> Characters Remaining</div></div><br><div class="tutorial-window open-topic-post-existing-warning js-cannnot-topic-post test-cannnot-topic-post none"><div class="content">Unable to create a new discussion because the last discussion you posted is still open for comments. Do you want to review that open discussion?<div class="window-bottom-buttons"><a href="" class="button test-existing-open-topic-post-link js-existing-open-topic-post-link" data-ytta-id="-">Yes</a></div></div></div><div class="feeling-selector js-feeling-selector test-feeling-selector"><label class="symbol feeling-button feeling-button-normal checked"><input type="radio" name="feeling_id" value="0" checked="" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_normal_face.png?latest" dcvalue="0"><span class="symbol-label">normal</span></label><label class="symbol feeling-button feeling-button-happy"><input type="radio" name="feeling_id" value="1" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_happy_face.png?latest" dcvalue="1"><span class="symbol-label">happy</span></label><label class="symbol feeling-button feeling-button-like"><input type="radio" name="feeling_id" value="2" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_like_face.png?latest" dcvalue="2"><span class="symbol-label">like</span></label><label class="symbol feeling-button feeling-button-surprised"><input type="radio" name="feeling_id" value="3" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_surprised_face.png?latest" dcvalue="3"><span class="symbol-label">surprised</span></label><label class="symbol feeling-button feeling-button-frustrated"><input type="radio" name="feeling_id" value="4" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_frustrated_face.png?latest" dcvalue="4"><span class="symbol-label">frustrated</span></label><label class="symbol feeling-button feeling-button-puzzled"><input type="radio" name="feeling_id" value="5" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_puzzled_face.png?latest" dcvalue="5"><span class="symbol-label">puzzled</span></label></div><div class="textarea-container"><div class="js-album-preview-wrapper none"><div class="community-container"><img src="https://d3esbfg30x759i.cloudfront.net/oip/zlCfzRGmg40tPMF3n4" class="community-icon">Activity Feed</div><div class="album-image-preview"><img class="preview-image js-album-image-preview" src=""><input type="hidden" name="album_image_id" value=""></div></div><textarea name="body" class="textarea-text textarea " maxlength="400" placeholder="Share your thoughts in a post to this community. *Please note that exchanging Nintendo Network IDs and friend codes is prohibited by the Miiverse Code of Conduct." data-open-topic-post-existing-placeholder="Unable to post a new discussion because you already have another discussion open for comments." data-open-folded-form="" data-required=""></textarea></div><div class="post-form-footer-options"><div class="post-form-footer-option-inner post-form-spoiler js-post-form-spoiler test-post-form-spoiler"><label class="spoiler-button symbol"><input type="checkbox" id="is_spoiler" name="is_spoiler" value="1" dcvalue="1">Spoilers</label></div></div><div class="form-buttons"><input type="submit" class="black-button post-button disabled" value="Send" data-track-category="post" data-track-action="sendPost" data-track-label="default" data-community-id="" data-title-id="" data-post-content-type="text" data-post-with-screenshot="nodata" dcvalue="Send" disabled></div></form>'); }

    //Add character count for text boxes
    $('.textarea-feedback').html('<font color="#646464" style="font-size: 13px; padding: 0 3px 0 7px;">'+400+'</font> Characters Remaining');
    $('.textarea').keyup(function() {
        var text_length = $('.textarea').val().length;
        var text_remaining = 400 - text_length;
        $('.textarea-feedback').html('<font color="#646464" style="font-size: 13px; padding: 0 3px 0 7px;">'+text_remaining+'</font> Characters Remaining');
    });
    $('.remaining-today-post-count').after('<div class="textarea-feedback" style="float:left;"><font color="#646464" style="font-size: 13px; padding: 0 3px 0 7px;">400</font> Characters Remaining</div>');

    //Unlock comment limits
    if(window.location.href.indexOf("/posts") > -1) {
        var reply = $('.reply-count').text(); var replycount = parseInt(reply, 10);
        if(replycount!=105) {
            var postid = document.querySelector('[data-track-label="default"]').getAttribute("data-url-id");
            var titleid = document.querySelector('[data-track-label="default"]').getAttribute("data-title-id");
            var communityid = document.querySelector('[data-track-label="default"]').getAttribute("data-community-id");
            $('.cannot-reply').replaceWith('<form id="reply-form" method="post" action="/posts/'+postid+'/replies"><input type="hidden" name="token" value="'+token+'"><div class="feeling-selector"><label class="symbol feeling-button feeling-button-normal checked"><input type="radio" name="feeling_id" value="0" checked="" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_normal_face.png?latest" dcvalue="0"><span class="symbol-label">normal</span></label><label class="symbol feeling-button feeling-button-happy"><input type="radio" name="feeling_id" value="1" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_happy_face.png?latest" dcvalue="1"><span class="symbol-label">happy</span></label><label class="symbol feeling-button feeling-button-like"><input type="radio" name="feeling_id" value="2" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_like_face.png?latest" dcvalue="2"><span class="symbol-label">like</span></label><label class="symbol feeling-button feeling-button-surprised"><input type="radio" name="feeling_id" value="3" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_surprised_face.png?latest" dcvalue="3"><span class="symbol-label">surprised</span></label><label class="symbol feeling-button feeling-button-frustrated"><input type="radio" name="feeling_id" value="4" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_frustrated_face.png?latest" dcvalue="4"><span class="symbol-label">frustrated</span></label><label class="symbol feeling-button feeling-button-puzzled"><input type="radio" name="feeling_id" value="5" data-mii-face-url="https://mii-secure.cdn.nintendo.net/35ihn9scmmztv_puzzled_face.png?latest" dcvalue="5"><span class="symbol-label">puzzled</span></label></div><div class="textarea-container"><div class="js-album-preview-wrapper none"><div class="community-container"><img src="https://d3esbfg30x759i.cloudfront.net/cip/zlCfzRAwCC0sfbJLk6" class="community-icon">New SUPER MARIO BROS. U</div><div class="album-image-preview"><img class="preview-image js-album-image-preview" src=""><input type="hidden" name="album_image_id" value=""></div></div><textarea name="body" class="textarea-text textarea" maxlength="400" placeholder="Add a comment here. *Please note that exchanging Nintendo Network IDs and friend codes is prohibited by the Miiverse Code of Conduct." data-required=""></textarea></div><div class="post-form-footer-options"><div class="post-form-footer-option-inner post-form-spoiler"><label class="spoiler-button symbol"><input type="checkbox" id="is_spoiler" name="is_spoiler" value="1" dcvalue="1">Spoilers</label></div></div><div class="form-buttons"><input type="submit" class="black-button reply-button" value="Send" data-track-category="reply" data-track-action="sendReply" data-title-id="'+titleid+'" data-community-id="'+communityid+'" data-url-id="'+postid+'" data-track-label="reply" data-post-content-type="text" data-post-with-screenshot="nodata" dcvalue="Send"></div></form>'); } }

    //Show all spoilers
    if(ShowAllSpoilers=="on") {
        $('.hidden-content-button').click(); }

    //Block all ads
    if(BlockAllAds=="on") {
        $(".adx").remove(); }

    //Disable backwards notifications
    if(DisableBackwardsNotifs=="on")
    htmlReplace('‮','');
})();