MartynMage / Show_New_User_On_Post

// ==UserScript==
// @name        Show_New_User_On_Post
// @namespace   Thingy
// @include     http://imgur.com/gallery/*
// @include     https://imgur.com/gallery/*
// @version     0.2.0
// @grant       none
// ==/UserScript==


// TODO: Think about useable version numbers...
// TODO: Add support for username.imgur.com  style urls
// TODO: Is there a way to request http://community.imgur.com/users/'+username+'.json  without CORS problems ?
//       We could use greasemonkey ajax call, but that wouldn't work with bookmarklets and every other browser (i guess)
// TODO: Show errors and handle no credits remaining ?

$( window ).ready(function() {
    var CLIENT_ID = "cd0695f1226536b";
    var IC_LOGO = "https://imgur-discourse.global.ssl.fastly.net/uploads/default/11780/18545d7f659da306.png";
    var lastUrlChecked = '';
    setInterval(function(){ CheckStats(); }, 500);
    function CheckStats(){
       if(window.location.href == lastUrlChecked)
       {
        return;
       }
        lastUrlChecked = window.location.href;
        console.log('stats checker running');
        var username = $('.post-account').text(); // TODO: look for a more stable way (is there an imgur js var maybe ?)
        var location = "http://imgur.com/user/";

       $('.post-title-meta').append($('<span id="newAcctIndicator" style="display:none"> · <a href="http://'+username+'.imgur.com">New Account</a></span>'));
        $('.post-title-meta').append($('<span id="onlySubIndicator" style="display:none"> · <a href="'+location+''+username+'/submitted">1 Submission</a></span>'));
        $('.post-title-meta').append($('<span id="zeroCommentsIndicator" style="display:none"> · <a href="'+location+''+username+'">0 Comments</a></span>'));
        $('.post-title-meta').append($('<span id="zeroFavsIndicator" style="display:none"> · <a href="'+location+''+username+'/favorites">0 Favs</a></span>'));
        // get coments / submission stats
        $.ajax({
            url: 'https://api.imgur.com/3/account/'+username+'/gallery_profile',
            method: 'GET',
            headers: {
                Authorization: 'Client-ID ' + CLIENT_ID,
                Accept: 'application/json'
            },
            success: function(result, status, request) {
                if(result.data.total_gallery_submissions==1){
                  $('#onlySubIndicator').show();
                }else{
                    $('#onlySubIndicator').hide();
                }
                if(result.data.total_gallery_comments===0){
                  $('#zeroCommentsIndicator').show();
                }else{
                    $('#zeroCommentsIndicator').hide();
                }
                if(result.data.total_gallery_favorites===0){
                   $('#zeroFavsIndicator').show();
                }else{
                    $('#zeroFavsIndicator').hide();
                }
            },
            error: function(a, b, c){
                console.log('Failed to load', a, b, c);
            }
        });

        // get the exact (*) join date. TODO: I bet i messed up the time(zones) here.
        $.ajax({
            url: 'https://api.imgur.com/3/account/'+username,
            method: 'GET',
            headers: {
                Authorization: 'Client-ID ' + CLIENT_ID,
                Accept: 'application/json'
            },
            success: function(result, status, request) {
                if(((new Date()).getTime()/1000)-result.data.created < 432000) // 5 days
                {
                    $('#newAcctIndicator').show();
                }else{
                    $('#newAcctIndicator').hide();
                }
            },
            error: function(a, b, c){
                console.log('Failed to load', a, b, c);
            }
        });


    }
});