Mint.com "Everything Else" budgets links fix-up

Make categories under "Everything Else" in Budgets page open correct URL when middle-clicked.

  1. // ==UserScript==
  2. // @name Mint.com "Everything Else" budgets links fix-up
  3. // @namespace com.roastedporksteambuns.mint
  4. // @version 0.1
  5. // @description Make categories under "Everything Else" in Budgets page open correct URL when middle-clicked.
  6. // @author RoastedPorkSteamBuns
  7. // @match https://mint.intuit.com/planning.event
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. "use strict";
  13.  
  14. function fixHyperlink(hyperlink) {
  15. hyperlink.href = hyperlink.href.replace("category=:", "category:");
  16. }
  17.  
  18. function attachEEListMutationObserver(target) {
  19. var observerConfig = {
  20. attributes: true,
  21. attributeFilter: ["href"],
  22. subtree: true
  23. };
  24. var observer = new MutationObserver(function(mutations) {
  25. var hyperlinks = [];
  26. mutations.forEach(function(mutation) {
  27. hyperlinks.push(mutation.target);
  28. });
  29. if (hyperlinks.length > 0) {
  30. // Temporarily disconnect the observer to avoid recursive notification.
  31. observer.disconnect();
  32. hyperlinks.forEach(function(hyperlink) {
  33. fixHyperlink(hyperlink);
  34. });
  35. observer.observe(target, observerConfig);
  36. }
  37. });
  38. observer.observe(target, observerConfig);
  39. }
  40.  
  41. (function waitForEEList() {
  42. // Wait for Everything Else list to appear.
  43. var target = document.querySelector('#spendingEE-list-body');
  44. if (target === null) {
  45. setTimeout(waitForEEList, 1000);
  46. return;
  47. }
  48. // Fix-up any already added children.
  49. jQuery(target).find('a').each(function(_, hyperlink) {
  50. fixHyperlink(hyperlink);
  51. });
  52. // Observe for and fix-up any children added in future.
  53. attachEEListMutationObserver(target);
  54. })();
  55. })();