Xkcd Forums Time Delta

Finds the time since the previous post or a specified time

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Xkcd Forums Time Delta
// @version      0.1
// @description  Finds the time since the previous post or a specified time
// @author       Faubi
// @grant        none
// @match        http://forums.xkcd.com/*
// @match        http://fora.xkcd.com/*
// @match        http://forums3.xkcd.com/*
// @match        http://echochamber.me/*
// @namespace    FaubiScripts
// ==/UserScript==

function get_date(element) {
    return new Date(/» (.*) [A-Z]{3} /.exec(element.textContent)[1]);
}

function append_dif(element, time1, time2, label) { 
    var w = Math.floor((time1 - time2)/1000);
    var days = Math.floor(w/86400);
    var hours = Math.floor(w/3600)%24;
    var minutes = Math.floor(w/60)%60;
    var seconds = w%60;
    var pList = element.parentNode.getElementsByClassName('delta');
    if (pList.length > 0) {
        element.parentNode.removeChild(pList[0]);
    } else {
        element.parentNode.appendChild(document.createElement('hr'));
    }
    var p = document.createElement('p');       
    p.innerHTML = 'Time since ' + label + ': ' + days + ' days, ' + hours + ' hours, ' + minutes + ' minutes, ' + seconds + ' seconds';
    p.classList.add('delta');
    element.parentNode.appendChild(p);
}

authors = document.getElementsByClassName('author');
for (var i=0;i<authors.length;i++) {
    (function(){
        var author = authors[i];
        if (i>=1) {
            var prevauthor = authors[i-1];
            var button = document.createElement('input');
            button.type = 'button';
            button.style['line-height']='1.2em';
            button.style['margin-left'] = '5px';
            button.style['margin-right'] = '0px';
            button.classList.add('button2');
            button.value = 'ΔPrevious';
            button.addEventListener('click', function(){
                append_dif(author, get_date(author), get_date(prevauthor), 'previous post');            
            });
            author.appendChild(button);
        }
        var button2 = document.createElement('input');
        button2.type = 'button';
        button2.style['line-height']='1.2em';
        button2.style['margin-left'] = '5px';
        button2.classList.add('button2');
        button2.value = 'ΔInput';
        button2.addEventListener('click', function(){
            append_dif(author, get_date(author), new Date(prompt('Enter the date to compare to')), 'inputted time');
        });
        author.appendChild(button2);
        
    })();
}