StackExchange sites - convert dates to local timezone

Converts dates to your local timezone

15.12.2015 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        StackExchange sites - convert dates to local timezone
// @namespace   darkred
// @description Converts dates to your local timezone
// @match       *://*.stackoverflow.com/*
// @match       *://*.stackexchange.com/*
// @match       *://*.superuser.com/*
// @match       *://*.stackapps.com/*
// @match       *://*.askubuntu.com/*
// @match       *://*.mathoverflow.net/*
// @match       *://*.serverfault.com/*
// @version     1
// @grant       none
// @require     https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment-with-locales.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.4.1/moment-timezone-with-data.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.6/jstz.min.js
// ==/UserScript==



var dates = document.getElementsByClassName('relativetime');


// tooltip with added timezone: "2015-12-14 14:11:13 +0000"
function toTimeZone(time, zone) {
    var format1 = ('YYYY-MM-DD HH:mm:ss Z');
    var format2 = ('YYYY-MM-DD HH:mm:ss');
    return moment(time, format1).tz(zone).format(format2);
}


function getLocalTimezone(){
    var tz = jstz.determine();    // Determines the time zone of the browser client
    return tz.name();             // Returns the name of the time zone eg "Europe/Berlin"
}


var localTimezone = getLocalTimezone();


function convertTitleDates() {
    var temp;


    for (var i = 0; i < dates.length; i++) {

        // "2015-12-14 14:11:13Z"   (the default tooltip)
        temp = dates[i].title;
        temp = temp.substring(0, temp.length - 1);
        temp += ' +0000';

        var format0 = ('YYYY-MM-DD HH:mm:ss Z');

        if (moment(temp, format0, true).isValid()) {

            dates[i].title = toTimeZone(temp, localTimezone);


            // 2015-12-08 10:38:53
            // Dec 8 at 10:38

            var regex2 = /(.*at\ ).*/;
            if (dates[i].innerHTML.match(regex2)) {

                var title = dates[i].title;
                var month = title.substring(8, 10);   // the '8'
                var time = title.substring(11, 16);   // the '10:38'

                if (month.substring(0, 1) === '0') {  // if the 1st digit in month is '0' then dont' use it in the replacing of datetext
                    month = month.substring(1, 2);
                }

                var datetext = dates[i].innerHTML;
                var dateTextArray = datetext.split(' ');
                dateTextArray[1] = month;
                dateTextArray[3] = time;

                dates[i].innerHTML = dateTextArray.join(' ');

            }


        }
    }

}



convertTitleDates();



new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
        console.log(mutation.type);
        console.log('CHANGE');
        convertTitleDates();
    });
}).observe(
    document.querySelector('#mainbar'), {           // monitor #mainbar for changes
        // attributes: true,
        childList: true,
        // characterData: true,
    }
);



new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
        console.log(mutation.type);
        console.log('CHANGE');
        convertTitleDates();
    });
}).observe(
    document.querySelector('#questions'), {         // monitor #questions for changes
        // attributes: true,
        childList: true,
        // characterData: true,
    }
);