InstaSynchP Bump Command

Command to bump a video from a user or url

  1. // ==UserScript==
  2. // @name InstaSynchP Bump Command
  3. // @namespace InstaSynchP
  4. // @description Command to bump a video from a user or url
  5.  
  6. // @version 1.0.3
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-Bump-Command
  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://greasyfork.org/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js?version=37716
  17. // ==/UserScript==
  18.  
  19. function Bump(version) {
  20. "use strict";
  21. this.version = version;
  22. this.name = "InstaSynchP Bump Command";
  23. this.commands = {
  24. "'bump": {
  25. 'hasArguments': true,
  26. 'type': 'mod',
  27. 'reference': this,
  28. 'description': 'Bumps a video from a user or the url. Position can be specified',
  29. 'callback': this.execute
  30. }
  31. };
  32. this.bumpInfo = undefined;
  33. this.bumpTo = undefined;
  34. }
  35.  
  36. Bump.prototype.executeOnce = function () {
  37. var th = this;
  38. //bind event for bumping an url
  39. events.on(th, 'AddVideo', function (vidinfo) {
  40. //bump the video after it got added
  41. if (videoInfoEquals(vidinfo.info, th.bumpInfo)) {
  42. sendcmd('move', {
  43. info: vidinfo.info,
  44. position: th.bumpTo
  45. });
  46. th.bumpInfo = undefined;
  47. th.bumpTo = undefined;
  48. }
  49. });
  50.  
  51. };
  52.  
  53. Bump.prototype.execute = function (opts) {
  54. "use strict";
  55. var th = this,
  56. user = opts.usernames[0],
  57. i,
  58. activeIndex = activeVideoIndex(),
  59. bumpIndex = -1,
  60. playlist = window.room.playlist.videos;
  61. th.bumpTo = opts.numbers.length > 0 ? opts.numbers[0] : activeVideoIndex() + 1;
  62. th.bumpInfo = opts.videos[0];
  63.  
  64. //return if nothing to bump got found
  65. if (!user && !th.bumpInfo) {
  66. addSystemMessage('Nothing found to bump: \'bump [user] [url] [position]');
  67. return;
  68. }
  69.  
  70. //search the video to be bumped
  71. for (i = playlist.length - 1; i >= 0; i -= 1) {
  72. if (videoInfoEquals(playlist[i].info, th.bumpInfo) ||
  73. (user && playlist[i].addedby.toLowerCase() === user.toLowerCase())) {
  74. bumpIndex = i;
  75. break;
  76. }
  77. }
  78. //video not found
  79. if (bumpIndex === -1) {
  80. //no link provided
  81. if (!th.bumpInfo) {
  82. addSystemMessage("The user didn't add any videos");
  83. } else {
  84. //add the video and bump it in the addVideo event
  85. sendcmd('add', {
  86. URL: urlParser.create({
  87. videoInfo: th.bumpInfo
  88. })
  89. });
  90. }
  91. } else {
  92. sendcmd('move', {
  93. info: playlist[bumpIndex].info,
  94. position: th.bumpTo
  95. });
  96. th.bumpTo = undefined;
  97. th.bumpInfo = undefined;
  98. }
  99. };
  100.  
  101. window.plugins = window.plugins || {};
  102. window.plugins.bump = new Bump('1.0.3');