Skip to content

Instantly share code, notes, and snippets.

@seler
Last active March 24, 2017 14:01
Show Gist options
  • Save seler/d37f23a511960b0ce03b6591f80d7d35 to your computer and use it in GitHub Desktop.
Save seler/d37f23a511960b0ce03b6591f80d7d35 to your computer and use it in GitHub Desktop.
Follow all members of StarCitizen organization
// ==UserScript==
// @name Follow all members of StarCitizen organization
// @namespace seler
// @version 0.1
// @description Follow all members of StarCitizen organization
// @author You
// @match https://robertsspaceindustries.com/orgs/*/members
// @grant none
// @updateURL https://gist.githubusercontent.com/seler/d37f23a511960b0ce03b6591f80d7d35/raw/rsifolloworg.user.js
// @installURL https://gist.githubusercontent.com/seler/d37f23a511960b0ce03b6591f80d7d35/raw/rsifolloworg.user.js
// ==/UserScript==
(function() {
'use strict';
var totalMembers,
addTimeout = 250,
processedMembers = 0,
membersLoadingInterval,
initialScrollY,
initialScrollX,
followAllButton = '.js-follow-all',
members = '.js-member-item span.nick';
$( document ).ajaxComplete(function(a, b, c) {
if(c.url == '/api/contacts/add'){
processedMembers += 1;
$(followAllButton).text('Following in progress ('+processedMembers+'/'+totalMembers+')');
if(processedMembers == totalMembers){
$(followAllButton).text('Following done');
}
}
});
function followAll() {
console.log(totalMembers, $(members).length);
if($(members).length < totalMembers){
window.scrollTo(initialScrollX, $('#rsi-website-footer').offset().top);
} else {
clearInterval(membersLoadingInterval);
window.scrollTo(initialScrollX, initialScrollY);
var timeout = 0;
var _nickname;
$(members).each(function(){
timeout += addTimeout;
_nickname = $(this).text();
setTimeout(function(){
RSI.eventDispatcher.trigger('contact:add', {nickname: _nickname});
}, timeout);
});
}
}
$('<li><a href="#" class="' + followAllButton.replace('.', '') + ' trans-02s">Follow all <span class="trans-02s"></span></a></li>').appendTo('ul.subnav');
$(followAllButton).click(function(e){
$(followAllButton).text('Following in progress');
initialScrollY = window.scrollY;
initialScrollX = window.scrollX;
totalMembers = parseInt($('.js-totalrows').text());
membersLoadingInterval = window.setInterval(followAll, 100);
e.preventDefault();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment