InstaSynchP Timestamp

Adds timestamps to the chat

  1. // ==UserScript==
  2. // @name InstaSynchP Timestamp
  3. // @namespace InstaSynchP
  4. // @description Adds timestamps to the chat
  5.  
  6. // @version 1.0.3
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-Timestamp
  9. // @license MIT
  10.  
  11. // @include *://instasync.com/r/*
  12. // @include *://*.instasync.com/r/*
  13. // @grant none
  14. // @run-at document-start
  15.  
  16. // @require https://gf.qytechs.cn/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js?version=37716
  17. // @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js
  18. // ==/UserScript==
  19.  
  20. function Timestamp(version) {
  21. "use strict";
  22. this.version = version;
  23. this.name = 'InstaSynchP Timestamp';
  24. this.settings = [{
  25. label: 'Show timestamps in chat',
  26. id: 'chat-timestamp',
  27. type: 'checkbox',
  28. 'default': true,
  29. section: ['Timestamp']
  30. }, {
  31. label: 'Format of the timestamp <a href="http://momentjs.com/docs/#/displaying/" target="_blank">More info</a>',
  32. title: 'Seconds can be added with :ss for example use the doc in the link for more info',
  33. id: 'chat-timestamp-format',
  34. type: 'text',
  35. 'default': '\\[hh:mm\\] ',
  36. size: 10,
  37. section: ['Timestamp']
  38. }];
  39. }
  40.  
  41. Timestamp.prototype.executeOnce = function () {
  42. "use strict";
  43. var th = this;
  44.  
  45. //add/remove timestamps when changing the setting
  46. events.on(th, 'SettingChange[chat-timestamp],SettingChange[chat-timestamp-format]', function () {
  47. $('.timestamp').each(function () {
  48. var unix, timestamp;
  49. unix = $(this).attr('unix');
  50. timestamp = moment.unix(unix).format(gmc.get('chat-timestamp-format'));
  51. $(this).css('display', gmc.get('chat-timestamp') ? 'initial' : 'none').text(timestamp);
  52. });
  53. scrollDown();
  54. });
  55.  
  56. events.on(th, 'AddMessage', function (user, message) {
  57. //filtered greynames don't get added at all
  58. if (!isUdef(user.loggedin) &&
  59. !user.loggedin &&
  60. room.filterGreyname ||
  61. window.room.isMuted(user.ip)) {
  62. return;
  63. }
  64.  
  65. try {
  66. var unix, timestamp, span;
  67. //create the timestamp
  68. unix = moment().unix();
  69. timestamp = moment.unix(unix).format(gmc.get('chat-timestamp-format'));
  70. //create the span
  71. span = $('<span>', {
  72. 'unix': unix,
  73. 'class': 'timestamp'
  74. }).text(timestamp).css('margin', '0px 6px 0px -6px')
  75. .css('display', gmc.get('chat-timestamp') ? 'initial' : 'none');
  76. //add it
  77. $('#chat_messages >:last-child >:first-child').before(span);
  78. //scroll chat down since the longer line can cause a line break
  79. if (window.room.autoscroll) {
  80. scrollDown();
  81. }
  82. } catch (err) {
  83. //ignore?
  84. //when moment() fails because of a loading issue
  85. //it causes a endless spam of errors in chat
  86. }
  87. });
  88. };
  89.  
  90. window.plugins = window.plugins || {};
  91. window.plugins.timestamp = new Timestamp('1.0.3');

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址