Skip to content

Instantly share code, notes, and snippets.

@aero31aero
Last active November 19, 2018 18:50
Show Gist options
  • Save aero31aero/0d7e5c06996895c1cff997e9c9003fa4 to your computer and use it in GitHub Desktop.
Save aero31aero/0d7e5c06996895c1cff997e9c9003fa4 to your computer and use it in GitHub Desktop.
BITS PS Station Swap Helper
// Usage:
// Paste the following in the console once on each reload.
// After that, type `x(first_index, second_index)` and press ENTER.
// Example: To swap 13th station with 75th station, you'd type:
// x(13,75)
// Example: To put 50th station at 2nd position, you'd type:
// y(50,2)
// Remember to save afterwards. :)
let cheat = function() {
let get_station_index_by_station_id = (target_index) => {
return $('[spn=' + target_index + ']').parent().find('div.ui-state-default.sortable-number').text();
}
let get_station_li_by_index = (target_index) => {
let all_counters = $('div.ui-state-default.sortable-number');
for (let i=0; i<all_counters.length; i++) {
let counter = $(all_counters[i]);
if (counter.text() == target_index) {
return counter.parent();
}
}
}
let update_station_counters = () => {
let all_counters = $('div.ui-state-default.sortable-number');
for (let i=0; i<all_counters.length; i++) {
let counter = $(all_counters[i]);
counter.text(i+1);
}
}
let filter_match = (id_num, filter) => {
elem = $(get_station_li_by_index(id_num));
if (filter) {
if(elem.html().toLowerCase().indexOf(filter) == -1) {
return false;
}
}
return true;
}
let swap = (first, second) => {
if (!first || !second || first > 393 || first < 1 || second > 393 || second < 1) {
return false;
}
first = $(get_station_li_by_index(first));
second = $(get_station_li_by_index(second));
first.after(second.clone());
second.after(first).remove();
update_station_counters();
}
let set_color = (id_num, color) => {
color = color || '';
elem = $(get_station_li_by_index(id_num));
elem.css('background-color', color);
}
let put_at = (id_num, destination_num) => {
destination_num = destination_num || 1;
if (!id_num || id_num > 393 || id_num < 1) {
return false;
}
id = $(get_station_li_by_index(id_num));
destination = $(get_station_li_by_index(destination_num));
destination.before(id.clone());
id.remove();
update_station_counters();
set_color(destination_num, 'lightgreen');
return destination_num > id_num;
}
let mark_range = (from, to, color, filter) => {
let i = 0;
for (i = from; i <= to; i++) {
if (filter_match(i, filter)) {
set_color(i, color);
}
}
}
let move_range = (from, to, destination, filter) => {
let i = 0;
let counter = 0;
for (i = from; i <= to; i++) {
if (filter_match(i, filter)) {
let down = put_at(i, destination);
if (down) {
i--;
counter++;
}
if(counter > 100) {
return;
}
}
}
}
let mark_accom = (from, to, bool, filter) => {
let i = 0;
for (i = from; i <= to; i++) {
if (filter_match(i, filter)) {
let elem = get_station_li_by_index(i);
let cbox = elem.find(':checkbox');
if (bool) {
cbox.attr('checked','checked');
} else {
cbox.removeAttr('checked');
}
}
}
}
let put_at_by_id = (station_id, destination_num) => {
let index_num = get_station_index_by_station_id(station_id);
put_at(index_num, destination_num);
}
return {
swap,
get_station_li_by_index,
put_at,
update_station_counters,
set_color,
mark_range,
filter_match,
move_range,
mark_accom,
get_station_index_by_station_id,
put_at_by_id,
};
}();
x = cheat.swap;
y = cheat.put_at;
z = cheat.mark_range;
xx = cheat.mark_accom;
yy = cheat.move_range;
zz = cheat.put_at_by_id;
// LEGALESE...
// Copyright 2018 Rohitt Vashishtha
// Published under the MIT License.
// EXAMPLE USES
// x(3,4) // swap
// y(100,1) // Move {x} to {y}
// z(1,169,'lightblue') // Mark Color Ranges
// z(1,30,'lightgreen', 'mumbai') // Mark all mumbai stations in top 30 as green.
// xx(1,169,true,'mumbai') // Mark Accom by Filter
// yy(1,200,201,'chennai') // Move {from},{to} to position {pos} by {filter}
// yy(1,392,393,'chemical') // Move all chemical down
// yy(40,392,39, 'finance') // move all finance stations up.
// yy(6,40,1) // Move without filter.
// zz(3062, 2) // Move by station id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment