Advertisement
Guest User

Untitled

a guest
Jan 1st, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. /* To use this script, modify the names below to suit your needs (Or remove both the names). Make sure the last name in the list does not have a comma.
  2. Commas should only go between each name.
  3. Once you've finished modifying the names, copy this entire script. If using Google Chrome,
  4. open up the Developer console with F12 (while on the RSI Website), paste the script, press ENTER key to execute the script.
  5. You will see it say "DONE!" when it finishes"
  6. By default this script will automatically follow all members visible in RR.
  7.  
  8. YOUTUBE Demo: https://youtu.be/cFpX0IxNDvM
  9. */
  10.  
  11.  
  12. var RROMemberScript =
  13. {
  14. baseAddressLive: "https://robertsspaceindustries.com/",
  15. baseAddressPtu: "https://ptu.cloudimperiumgames.com/",
  16. maximumContactsPrefilCount: 200, // The maximum number of contacts this script will add
  17.  
  18. // The members of organisation. The redacted or hidden members are included.
  19. OtherContacts: [
  20.  
  21. 'illanar',
  22. 'ranalli'
  23.  
  24.  
  25. ],
  26.  
  27. // The members that will be removed from contactlist. IE: Old members of organisation.
  28. /**
  29. OldMembers: [
  30.  
  31. ],
  32. **/
  33.  
  34. // nothing needs to be filled in here
  35. addedMembers: [],
  36.  
  37. // Get the server base address. Supports PTU and live.
  38. getBaseAddress: function () {
  39. if ($("#ptubar").length)
  40. return this.baseAddressPtu;
  41.  
  42. return this.baseAddressLive;
  43. },
  44. // getCookie from http://stackoverflow.com/a/11767598 by Paul Sweatte
  45. // Extracts a cookie from document.cookie
  46. getCookie: function (cookiename) {
  47. // Get name followed by anything except a semicolon
  48. var cookiestring = RegExp("" + cookiename + "[^;]+").exec(document.cookie);
  49. // Return everything after the equal sign
  50. return unescape(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, "") : "");
  51. },
  52.  
  53. // additional headers, here we only use the RSI token from the cookie.
  54. __hs: function () {
  55. return { "X-Rsi-Token": this.getCookie('Rsi-Token') };
  56. },
  57.  
  58. /**
  59. * Follow one Star Citizen.
  60. * name is the nickname/handle of the player.
  61. * follow=true -> follow, follow=false -> unfollow
  62. */
  63. changeFollow: function (name, follow) {
  64. var that = this;
  65.  
  66. if (!follow || (that.addedMembers.length < that.maximumContactsPrefilCount && that.addedMembers.indexOf(name.toLowerCase()) < 0)) {
  67. $.ajax({
  68. async: false,
  69. type: "post",
  70. url: that.getBaseAddress() + "api/contacts/" + (follow ? "add" : "erase"),
  71. success: function (d) {
  72. if (d.msg != 'Validation failed' && d.msg != 'ErrCannotAddItself' && d.msg != 'ErrNoAccountForNickname') {
  73. // tell the user if it worked
  74. console.log((follow ? "Following " : "Unfollowing ") + name + " -> " + d.msg);
  75.  
  76. if (follow)
  77. that.addedMembers.push(name.toLowerCase());
  78. }
  79. },
  80. data: JSON.stringify({
  81. nickname: name
  82. }),
  83. headers: that.__hs()
  84. });
  85. }
  86. },
  87.  
  88. /**
  89. * Erase ALL members in your contacts list.
  90. */
  91. eraseAll: function () {
  92. var that = this;
  93.  
  94. $.ajax({ // request a page of members
  95. async: false,
  96. type: "post",
  97. url: that.getBaseAddress() + "api/contacts/list",
  98. success: function (d) {
  99. //console.debug(d);
  100. if (d.data.resultset.length) { // still more members available
  101. $.each(d.data.resultset, function (i, field) {
  102. that.changeFollow(field.nickname, false);
  103. });
  104. // load next charge/page of members
  105. that.eraseAll();
  106. }
  107. },
  108. data: JSON.stringify({
  109. page: 1,
  110. query: ""
  111. }),
  112. headers: that.__hs()
  113. });
  114. },
  115.  
  116. /**
  117. * Follow all members of an organization
  118. * sid is the SID, Spectrum ID/handle of the organization.
  119. * follow=true -> follow, follow=false -> unfollow
  120. * page defaults to 1, dont use it.
  121. */
  122. changeOrgFollow: function (sid, follow, page) {
  123. var that = this;
  124.  
  125. page = page || 1;
  126. $.ajax({ // request a page of members
  127. async: false,
  128. type: "post",
  129. url: that.getBaseAddress() + "api/orgs/getOrgMembers",
  130. success: function (d) {
  131. //console.debug(d); // debug received data
  132. if (d.data && d.data.html) { // still more members available
  133. // parse to DOM object
  134. dt = $('<div></div');
  135. dt.html(d.data.html);
  136. // (un-)follow all members
  137. $('.nick', dt).each(function (i, field) {
  138. that.changeFollow(field.innerHTML, follow);
  139. });
  140.  
  141. // load next charge/page of members
  142. that.changeOrgFollow(sid, follow, page + 1);
  143. }
  144. },
  145. data: JSON.stringify({
  146. symbol: sid.toUpperCase(),
  147. page: page
  148. }),
  149. headers: that.__hs()
  150. });
  151. },
  152.  
  153. /**
  154. * Append extra members
  155. */
  156. appendMembers: function (members) {
  157. var that = this;
  158.  
  159. $.each(members, function (i, name) {
  160. that.changeFollow(name, true);
  161. });
  162. },
  163.  
  164. /**
  165. * Remove old members
  166. */
  167. removeMembers: function (oldmembers) {
  168. var that = this;
  169.  
  170. $.each(oldmembers, function (i, name) {
  171. that.changeFollow(name, false);
  172. });
  173. },
  174.  
  175. /**
  176. * Execute the script.
  177. **/
  178. execute: function () {
  179. //this.eraseAll();
  180. this.appendMembers(this.OtherContacts);
  181. // this.removeMembers(this.oldMembers));
  182.  
  183.  
  184. this.changeOrgFollow('RRO', true);
  185.  
  186.  
  187.  
  188.  
  189.  
  190. console.log('DONE! Added ' + this.addedMembers.length + " members.")
  191.  
  192. this.addedMembers.length = [];
  193. }
  194. };
  195. RROMemberScript.execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement