Skip to content

Commit

Permalink
Restore "Find discreet work" link afterwards, w/o needing page reload.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Schurman committed Oct 15, 2018
1 parent 0a9d2b0 commit f7891a1
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions discreet_helper.user.js
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Tau Discreet Helper
// @namespace http://tampermonkey.net/
// @version 0.1
// @version 0.2
// @description Add links to areas while on discreet work
// @author Marco Fontani <MFONTANI@cpan.org>
// @match https://alpha.taustation.space/*
Expand All @@ -13,7 +13,9 @@
// the mission update text to see whether anything looks like
// an area at the current station, i.e. "Gym" or "Bank", etc.
// and if so link to that area's "people" tab
// This speeds up discreet missions ever so slightly.
// After finishing the mission, restore the "new mission"
// links without the user needing to reload the page.
// These speed up discreet missions ever so slightly.

(function() {
'use strict';
Expand Down Expand Up @@ -47,11 +49,41 @@
}
$(nd).html(text);
});
}

// After a Discreet Work mission's final click, show the "Find discreet work"
// sidebar link without requiring a page reload.
//
// Step 1: Future-proofing: Save the "new mission links" html currently used by the site.
function save_new_mission_links() {
if (window.location.pathname.startsWith('/area/discreet-work')) {
$('.jobs-list a[href="/area/discreet-work/accept"]').click(function() {
localStorage.setItem('discreet_helper-new_mission_links',
$('.employment-title:contains("Current Mission")').parent().html());
});
}
}

// Step 2: Restore the previously-saved links (instead of using a hardcoded string).
function restore_new_mission_links() {
if (window.location.pathname.startsWith('/character/details/') &&
localStorage['discreet_helper-new_mission_links']) {
$('.mission-step-link[data-step-slug="finish"]').click(function() {
// After clicking the above mission step, the "active mission" is no longer active,
// but remains in the sidebar. Replace it with the "find new missions" links.
$('.employment-title:contains("Current Mission")').parent()
.html(localStorage['discreet_helper-new_mission_links']);
localStorage.removeItem('discreet_helper-new_mission_links');
});
}
}

// TODO refresh directions only when a _new_
// ".narrative-direction" enters the DOM,
// rather than every second
window.setInterval(refresh_directions, 1000);
refresh_directions();

save_new_mission_links();
restore_new_mission_links();
})();

0 comments on commit f7891a1

Please sign in to comment.