Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var log = console.log.bind(console); // just a shortcut to console.log
- var options = {
- group: 915505, // if the user isn't in this group, he'll be ignored
- waitTime: 5000 // number of milliseconds to wait between messages
- };
- // called when we want to send to all users
- function run() {
- var promise = Promise.resolve();
- var elms = document.querySelectorAll(
- "#ctl00_cphRoblox_rbxGroupRoleSetMembersPane_GroupMembersUpdatePanel .GroupMember .Name"
- );
- for (var i = 0, j = elms.length; i < j; ++i) {
- var id = elms[i].href.match(/\d+/)[0],
- name = elms[i].textContent;
- // IIFE so id and name don't change
- (function(id, name) {
- // add to the queue
- promise = promise.then(function() {
- return new Promise(function(resolve) {
- setTimeout(resolve.bind(null, {
- id: id,
- name: name
- }, waitTime));
- });
- })
- .then(checkUser)
- .then(sendMsg)
- .then(function(user) {
- log("Sent message to", user.name, "(", user.id, ")");
- })
- .catch(function(err) {
- // log any errors to console
- console.error("Error sending to", name, "(", id, "):", err);
- // if we got blocked for flood reasons, wait another 5 seconds
- if (err.shortMessage && err.shortMessage.find("flood")) {
- return new Promise(function(resolve) {
- setTimeout(resolve, 5000); // whoo, magic numbers
- });
- }
- });
- })(id, name);
- }
- __doPostBack('ctl00$cphRoblox$rbxGroupRoleSetMembersPane$dlUsers_Footer$ctl02$ctl00', '');
- }
- // check if a user is in a group. User format: {id: <String>, name: <String>}
- function checkUser(user) {
- if (!options.group) {
- return user; // pass the user on to the next function
- }
- // if we *do* have a group to filter by, do so
- return
- $.get('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid=' + userId + '&groupid=' + group)
- .done(function(response) {
- if (response.indexOf("true") === -1) {
- return user; // pass the user on to the next function
- } else {
- throw "User is already in the group."
- }
- });
- }
- // send a message to the user. User format: {id: <String>, name: <String>}
- function sendMsg(user) {
- return $.post('http://www.roblox.com/messages/send', {
- subject: "Subject",
- body: "Body",
- recipientid: user.id,
- cacheBuster: Date.now()
- })
- .done(function(response) {
- if (response.success == true) {
- return;
- } else {
- throw response;
- }
- })
- }
- // I have no idea what this is doing here
- function __doPostBack(eventTarget, eventArgument) {
- if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
- theForm.__EVENTTARGET.value = eventTarget;
- theForm.__EVENTARGUMENT.value = eventArgument;
- theForm.submit();
- }
- }
- // wait for the DOM to load - you could also place the <script> tag
- // as the last child of the <body>. I personally prefer that approach
- document.addEventListener("DOMContentLoaded", function() {
- // call run when the DOM loads, and also when #__EVENTTARGET changes its value
- document.getElementById('__EVENTTARGET').addEventListener("change", function() {
- if (this.value === "") {
- run();
- }
- });
- run();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement