InstaSynchP Timestamp

Adds timestamps to the chat

10.05.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        InstaSynchP Timestamp
// @namespace   InstaSynchP
// @description Adds timestamps to the chat

// @version     1.0.3
// @author      Zod-
// @source      https://github.com/Zod-/InstaSynchP-Timestamp
// @license     MIT

// @include     *://instasync.com/r/*
// @include     *://*.instasync.com/r/*
// @grant       none
// @run-at      document-start

// @require     https://greatest.deepsurf.us/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js?version=37716
// @require     https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js
// ==/UserScript==

function Timestamp(version) {
  "use strict";
  this.version = version;
  this.name = 'InstaSynchP Timestamp';
  this.settings = [{
    label: 'Show timestamps in chat',
    id: 'chat-timestamp',
    type: 'checkbox',
    'default': true,
    section: ['Timestamp']
  }, {
    label: 'Format of the timestamp <a href="http://momentjs.com/docs/#/displaying/" target="_blank">More info</a>',
    title: 'Seconds can be added with :ss for example use the doc in the link for more info',
    id: 'chat-timestamp-format',
    type: 'text',
    'default': '\\[hh:mm\\] ',
    size: 10,
    section: ['Timestamp']
  }];
}

Timestamp.prototype.executeOnce = function () {
  "use strict";
  var th = this;

  //add/remove timestamps when changing the setting
  events.on(th, 'SettingChange[chat-timestamp],SettingChange[chat-timestamp-format]', function () {
    $('.timestamp').each(function () {
      var unix, timestamp;
      unix = $(this).attr('unix');
      timestamp = moment.unix(unix).format(gmc.get('chat-timestamp-format'));
      $(this).css('display', gmc.get('chat-timestamp') ? 'initial' : 'none').text(timestamp);
    });
    scrollDown();
  });

  events.on(th, 'AddMessage', function (user, message) {
    //filtered greynames don't get added at all
    if (!isUdef(user.loggedin) &&
        !user.loggedin &&
        room.filterGreyname ||
        window.room.isMuted(user.ip)) {
      return;
    }

    try {
      var unix, timestamp, span;
      //create the timestamp
      unix = moment().unix();
      timestamp = moment.unix(unix).format(gmc.get('chat-timestamp-format'));
      //create the span
      span = $('<span>', {
          'unix': unix,
          'class': 'timestamp'
        }).text(timestamp).css('margin', '0px 6px 0px -6px')
        .css('display', gmc.get('chat-timestamp') ? 'initial' : 'none');
      //add it
      $('#chat_messages >:last-child >:first-child').before(span);
      //scroll chat down since the longer line can cause a line break
      if (window.room.autoscroll) {
        scrollDown();
      }
    } catch (err) {
      //ignore?
      //when moment() fails because of a loading issue
      //it causes a endless spam of errors in chat
    }
  });
};

window.plugins = window.plugins || {};
window.plugins.timestamp = new Timestamp('1.0.3');