InstaSynchP UserSpy

Log user actions into the chat (login/off, video add)

当前为 2015-05-10 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        InstaSynchP UserSpy
// @namespace   InstaSynchP
// @description Log user actions into the chat (login/off, video add)

// @version     1.1.0
// @author      Zod-
// @source      https://github.com/Zod-/InstaSynchP-UserSpy
// @license     MIT

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

// @require     https://greasyfork.org/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js?version=37716
// ==/UserScript==
function UserSpy(version) {
  'use strict';
  this.version = version;
  this.name = 'InstaSynchP UserSpy';
  this.settings = [{
    label: 'Show user logs in or off',
    id: 'login-off-log',
    type: 'checkbox',
    'default': true,
    section: ['UserSpy']
  }, {
    label: 'Show when a greyname logs in or off',
    id: 'login-off-greynames-log',
    type: 'checkbox',
    'default': true,
    section: ['UserSpy']
  }, {
    label: 'Show when a greyname renames himself',
    id: 'rename-log',
    type: 'checkbox',
    'default': true,
    section: ['UserSpy']
  }, {
    label: 'Show when someone adds a video',
    title: 'Includes the title',
    id: 'add-video-log',
    type: 'checkbox',
    'default': true,
    section: ['UserSpy']
  }];
}

UserSpy.prototype.getAddVideoMessage = function (video) {
  'use strict';
  //user added <a href="url">title</a>
  return ''.concat(
    video.addedby,
    ' added ',
    '<a target="_blank" href="',
    urlParser.create({
      videoInfo: video.info,
      format: 'long'
    }),
    '">',
    video.title.substr(0, 240),
    '</a>'
  );
};

UserSpy.prototype.getRenameMessage = function (user) {
  'use strict';
  //ip renamed to username
  return ''.concat(
    user.ip,
    ' renamed to ',
    user.username
  );
};

UserSpy.prototype.getLogOnMessage = function (user) {
  'use strict';
  //user(ip) logged on
  return ''.concat(
    user.username,
    '(',
    user.ip,
    ') logged on'
  );
};

UserSpy.prototype.getLogOffMessage = function (user) {
  'use strict';
  //user(ip) logged off
  return ''.concat(
    user.username,
    '(',
    user.ip,
    ') logged off'
  );
};

UserSpy.prototype.executeOnce = function () {
  'use strict';
  var _this = this;
  events.on(_this, 'RenameUser', function (ignore1, ignore2, user) {
    if (gmc.get('rename-log')) {
      addSystemMessage(_this.getRenameMessage(user));
    }
  });
};

UserSpy.prototype.postConnect = function () {
  'use strict';
  var _this = this;
  //add events after we connected so it doesn't spam the chat for every user/video
  events.on(_this, 'AddUser', _this.userLoggedOn);
  events.on(_this, 'RemoveUser', _this.userLoggedOff);
  events.on(_this, 'AddVideo', _this.videoAdded);
};

UserSpy.prototype.videoAdded = function (video) {
  'use strict';
  var _this = this;
  if (gmc.get('add-video-log')) {
    addSystemMessage(_this.getAddVideoMessage(video));
  }
};

UserSpy.prototype.resetVariables = function () {
  'use strict';
  var _this = this;
  //remove events when disconnecting/changing room and readd at postConnect
  events.unbind('AddUser', _this.userLoggedOn);
  events.unbind('RemoveUser', _this.userLoggedOff);
  events.unbind('AddVideo', _this.videoAdded);
};

UserSpy.prototype.isUserLogged = function (user) {
  'use strict';
  return gmc.get('login-off-log') &&
    (user.loggedin || gmc.get('login-off-greynames-log'));
};

UserSpy.prototype.userLoggedOn = function (user) {
  'use strict';
  var _this = this;
  if (_this.isUserLogged(user)) {
    addSystemMessage(_this.getLogOnMessage(user));
  }
};

UserSpy.prototype.userLoggedOff = function (ignore, user) {
  'use strict';
  var _this = this;
  if (_this.isUserLogged(user)) {
    addSystemMessage(_this.getLogOffMessage(user));
  }
};

window.plugins = window.plugins || {};
window.plugins.userSpy = new UserSpy('1.1.0');