Mint Sticky Budget Summary

Keep the budget summary box on-screen in the right column.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name       Mint Sticky Budget Summary
// @namespace  http://mint.com/
// @version    1.0.1
// @description  Keep the budget summary box on-screen in the right column.
// @match      https://wwws.mint.com/planning.event
// @require    https://code.jquery.com/jquery-2.1.1.min.js
// @copyright  2012+, You
// ==/UserScript==

(function ($) {
  StickySummary = {
    // Declare elements
    sidebar: [],
    summary: [],
    buffer: 30,
    boxtop: 0,

    // Init
    init: function() {
      var self = this;

      $(window).scroll(function() {
        // Ensure the elements are set.
        // They appear to be loaded via ajax from Mint.
        if (self.sidebar.length == 0) {
          self.sidebar = $('#main td.details-budgets');
          self.summary = $("#right_col", self.sidebar);

          if (self.sidebar.length > 0) {
            // Set the top buffer
            var $pos = self.summary.offset();
            self.boxtop = $pos.top;
          }
        }

        // Compare the position with the top of the screen and lock the summary
        // if it scrolls past the top.
        if (self.sidebar.length > 0) {
          var $pos = $(document).scrollTop();

          if ($pos >= (self.boxtop - self.buffer)) {
            self.summary.css({
              'position': 'fixed',
              'top': self.buffer,
              'margin-top': 0
            });
          }
          else {
            self.summary.css({
              'position': 'static',
              'top': '',
              'margin-top': ''
            });
          }
        }
      });
    }
  };

  // Run the script
  $(document).ready(function() {
    StickySummary.init();
  });
})(jQuery);