// ==UserScript== // @name InstaSynchP Wallcounter // @namespace InstaSynchP // @description Summarizes the lengths of each users video walls // @version 1.0.1 // @author Zod- // @source https://github.com/Zod-/InstaSynchP-Wallcounter // @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 // @downloadURL none // ==/UserScript== function Wall(username) { "use strict"; this.duration = 0; this.videoCount = 0; this.username = username; } Wall.prototype.add = function (video) { "use strict"; this.videoCount++; this.duration += video.duration; }; Wall.prototype.remove = function (video) { "use strict"; this.videoCount--; this.duration -= video.duration; }; Wall.prototype.format = function (format) { "use strict"; var th = this; return format.format( th.username, window.utils.secondsToTime(th.duration), th.videoCount ); }; function Wallcounter() { "use strict"; this.version = '1.0.1'; this.name = 'InstaSynchP Wallcounter'; this.counter = {}; this.ownCounter = undefined; this.commands = { "'wallcounter": { 'hasArguments': true, 'reference': this, 'description': 'Summarizes the lengths of each users video walls or specific users', 'callback': this.execute } }; this.styles = [{ 'name': 'wallcounter', 'url': 'https://cdn.rawgit.com/Zod-/InstaSynchP-Wallcounter/9bc2c3c08d1560ce1253d8bb858ebe29ff645ec8/dist/wallcounter.css', 'autoload': true }]; } Wallcounter.prototype.resetVariables = function () { "use strict"; this.ownCounter = undefined; this.counter = {}; }; Wallcounter.prototype.updateOwnDisplay = function () { "use strict"; var th = this; $('#playlist_wallcounter').text( th.ownCounter.format('Wallcounter[{1} - {2}]') ); }; Wallcounter.prototype.key = function (key) { "use strict"; return key.toLowerCase(); }; Wallcounter.prototype.increase = function (username, video) { "use strict"; this.counter[this.key(username)].add(video); }; Wallcounter.prototype.decrease = function (username, video) { "use strict"; this.counter[this.key(username)].remove(video); }; Wallcounter.prototype.create = function (username) { "use strict"; this.counter[this.key(username)] = new Wall(username); }; Wallcounter.prototype.createIfNotExists = function (username) { "use strict"; var th = this; if (th.counter.hasOwnProperty(th.key(username))) { return; } th.create(username); }; Wallcounter.prototype.bindUpdates = function () { "use strict"; var th = this; function onAddVideo(video) { th.increase(video.addedby, video); th.updateOwnDisplay(); } function onAddUser(user) { th.createIfNotExists(user.username); } //LoadPlaylist happens before LoadUserlist so the walls would not have been //created yet when recieving the AddVideo events events.on(th, 'LoadPlaylist', function (videos) { videos.forEach(function (video) { onAddUser({ username: video.addedby }); onAddVideo(video); }); events.on(th, "AddVideo", onAddVideo, true); }); events.on(th, "AddUser", onAddUser); events.on(th, "RemoveVideo", function (ignore, video) { th.decrease(video.addedby, video); th.updateOwnDisplay(); }, true); }; Wallcounter.prototype.executeOnce = function () { "use strict"; var th = this; th.bindUpdates(); events.on(th, 'Joined', function () { th.ownCounter = new Wall(thisUser().username); th.counter[th.key(th.ownCounter.username)] = th.ownCounter; }); }; Wallcounter.prototype.preConnect = function () { "use strict"; //own wallcounter display below the playlist $('.playlist-stats').append( $('