TL Recent posts

Adds a recent post indicator at the end of the post time.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         TL Recent posts
// @include      *teamliquid.net/*
// @author       nakam
// @description  Adds a recent post indicator at the end of the post time.
// @version 0.0.1.20140530203430
// @namespace https://greasyfork.org/users/2349
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
    script.addEventListener('load', function() {
    var script = document.createElement("script");
    script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
    document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}

function main() {
    // Note, jQ replaces $ to avoid conflicts.
    var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
    var myRe = /(January|February|March|April|May|June|July|August|September|October|November|December).{4,7}20[0-9]{2}.[0-9]{2}:[0-9]{2}/g;
  
    $(".forummsginfo,.forummsginfoa").each(function( index ) {
        var newPostHeader = convertPostTitle($(this).html());
        $(this).html(newPostHeader);
    });
    
    $(".quote").each(function( index ) {
        var post = convertQuote($(this).html());
        $(this).html(post);
    });
  
    function dateStringToObject(content) {
        
        var workStr = String(content.match(myRe));
        if(workStr === 'null'){
            return 'null';
        }

        var postHour = workStr.substring(workStr.length - 5, workStr.length - 3);
        var postMinute = workStr.substring(workStr.length - 2, workStr.length);
        var postYear = parseInt(workStr.match(/[0-9]{4}/), 0);
        var postMonthName = workStr.match(/[A-z]*/);
        var postMonth = monthToNumber(postMonthName);
        var postDay = workStr.match(/[0-9]{2}/);

        var postDate = new Date(postYear, postMonth, postDay, postHour, postMinute);
        return postDate; 
    }
    
    function makeRecentTextString(postDate) {
        var curDate = new Date();
        
        var diffMinutes = Math.abs((curDate - postDate)/1000/60);
        var recentText;
        var recentTextString;
        var color = "#d20000";
        
        if (diffMinutes < 60) {
            recentText = Math.round(diffMinutes) + " min";
            recentTextString = "<span style='color:" + color + "'> ("+recentText+")</span>"
        }
        else if (diffMinutes < 60*24) {
            recentText = Math.round(Math.abs(diffMinutes / 60)) + " hours";
            recentTextString = "<span style='color:" + color + "'> ("+recentText+")</span>"
        }
        else if (diffMinutes < 60*24*10) {
            recentText = Math.round(Math.abs(diffMinutes / 60 / 24)) + " days";
            recentTextString = "<span style='color: black'> ("+recentText+")</span>"
        }
        else {
            recentTextString = "";
        }
        return recentTextString;
    }
    function adjustQuoteTime(postDate) {
        postDate = Date.parse(postDate)-3600000*7;
        var newDate = new Date();
        newDate.setTime(postDate);
        return newDate;
    }
    function convertQuote(content) {
    
        var postDate = dateStringToObject(content);
        if(postDate === 'null'){
            return content;
        }
        
        postDate = adjustQuoteTime(postDate);

        var recentTextString = makeRecentTextString(postDate);
        var newPostMinutes = (postDate.getMinutes()<10?'0':'') + postDate.getMinutes();
        var newDateString = monthNames[postDate.getMonth()] + " " + postDate.getDate() + " " + postDate.getFullYear() + " " + postDate.getHours() + ":" + newPostMinutes + " " + recentTextString;
        
        return content.replace(myRe, newDateString);        
    }
  
    function convertPostTitle(content) {
        var postDate = dateStringToObject(content);
        if(postDate === 'null') {
            return content;
        }
        var recentTextString = makeRecentTextString(postDate);
        
        newPostMinutes = postDate.getMinutes();
        
        if (postDate.getMinutes() < 10) {
            newPostMinutes = "0"+newPostMinutes;
        }

        var newDateString = monthNames[postDate.getMonth()] + " " + postDate.getDate() + " " + postDate.getFullYear() + " " + postDate.getHours() + ":" + newPostMinutes + " " + recentTextString;
        
        return content.replace(myRe, newDateString);
    }
    function monthToNumber(monthName) {
        "use strict";
        if (monthName == "January") {
            return 0;
        }
        if (monthName == "February") {
            return 1;
        }
        if (monthName == "March") {
            return 2;
        }
        if (monthName == "April") {
            return 3;
        }
        if (monthName == "May") {
            return 4;
        }
        if (monthName == "June") {
            return 5;
        }
        if (monthName == "July") {
            return 6;
        }
        if (monthName == "August") {
            return 7;
        }
        if (monthName == "September") {
            return 8;
        }
        if (monthName == "October") {
            return 9;
        }
        if (monthName == "November") {
            return 10;
        }
        if (monthName == "December") {
            return 11;
        }
    }
}


// load jQuery and execute the main function
addJQuery(main);