Mint.com Customize Default Categories

Hide specified default built-in mint.com categories

目前为 2015-03-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Mint.com Customize Default Categories
  3. // @namespace com.schrauger.mint.js
  4. // @author Stephen Schrauger
  5. // @description Hide specified default built-in mint.com categories
  6. // @homepage https://github.com/schrauger/mint.com-customize-default-categories
  7. // @include https://*.mint.com/*
  8. // @version 1.2.0
  9. // @reqnhuire https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
  10. // @grant none
  11. // ==/UserScript==
  12. /*jslint browser: true*/
  13. /*global jQuery*/
  14. function after_jquery() {
  15. var bit_flags_per_char = 6; // using 01XXXXXX ASCII codes, which allows for 6 flags per character
  16. var unique_id_length = 4; // the bit array starts with '#!1 ' or '#!2 ' or '#!3 '
  17. var categories_per_string = 8; // with 20 characters per string, and 2 characters per category, we can fit 8 (plus the 4-char unique id)
  18. var characters_per_category = 2; // with 6 flags, this allows for 11 sub categories and 1 major category
  19. var number_of_bit_arrays = 3; // use 3 arrays to store all preferences.
  20. var category_id = 20; // save the custom fields in the 'uncategorized' major category, which has the id of 20
  21. var class_hidden = 'sgs-hide-from-mint'; // just a unique class; if an element has it, it will be hidden.
  22. var class_edit_mode = 'mint_edit_mode';
  23.  
  24. var hs_action_hide = 'hide';
  25. var hs_action_show = 'show';
  26. var hs_action_edit = 'edit';
  27.  
  28. // Need to define all categories and subcategories, along with their ID. Create this list dynamically.
  29. function get_default_category_list() {
  30. var categories = [];
  31.  
  32. // loop through each category and create an array of arrays with their info
  33. jQuery('#popup-cc-L1').find('> li').each(function () {
  34. var category_major = [];
  35. category_major.id = jQuery(this).attr('id').replace(/\D/g, ''); // number-only portion (they all start with 'pop-categories-'{number}
  36. //console.log(caconsole.logtegory_major.id);
  37. category_major.name = jQuery(this).children('a').text();
  38. category_major.categories_minor = [];
  39. category_major.is_hidden = jQuery(this).hasClass(class_hidden);
  40. /* get the minor/sub categories. only the :first ul, because the second one is
  41. user-defined custom categories, which they can change with native mint.com controls
  42. */
  43. jQuery(this).find('div.popup-cc-L2 ul:first > li').each(function () {
  44. var category_minor = [];
  45. category_minor.id = jQuery(this).attr('id').replace(/\D/g, '');
  46. category_minor.name = jQuery(this).text();
  47. category_minor.is_hidden = jQuery(this).hasClass(class_hidden);
  48. category_major.categories_minor.push(category_minor);
  49. });
  50. categories.push(category_major);
  51. });
  52.  
  53. return categories;
  54. }
  55.  
  56. // Somehow save any categories the user wants hidden.
  57. // This will be done by creating a custom subcategory in the 'uncategorized' category, where the name of this
  58. // subcategory will define which other categories to hide.
  59. // This way, if the UserScript is installed on multiple computers, the user sees their preferences synced.
  60. // Alternatively, a cookie could be used, but preferences would be specific to that device.
  61.  
  62. /**
  63. * @str_bit_array String A printable-ascii encoded bit array (values that can be saved in a custom category)
  64. * @array_of_eight_categories Array 8 categories with their subcategories and
  65. * ID, name, subcategories and is_hidden members
  66. * for both the category and subcategories
  67. */
  68. function decode_bit_array(str_bit_array_array, array_of_all_categories) {
  69.  
  70. // second, translate any extra characters into their forbidden character
  71. // (double quote is forbidden; use a non-bit-array character to encode)
  72.  
  73. // third, loop through each category and each of its subcategories
  74.  
  75. // use bitwise operators to see if the subcategory minor id (always 1-9) is marked as hidden
  76.  
  77.  
  78. str_bit_array_array.sort();
  79.  
  80. array_of_all_categories.sort(function (a, b) {
  81. return (a.id - b.id); // sort by id, lowest first
  82. });
  83.  
  84.  
  85. var field_count = 0; // 0, 1, or 2; for the 3 unique fields holding the 23 category hidden attributes
  86. var bit_string_category_count = 0; // only 8 categories per string. once this goes past 7, reset and use next string.
  87. var str_bit_array = str_bit_array_array[field_count]; // 3 custom fields with attributes
  88. // remove the first 4 characters (the unique ID plus a space)
  89. str_bit_array = str_bit_array.substring(unique_id_length); // 0-based, meaning start at character 5 (inclusive)
  90.  
  91. // loop through each major category and its minor categories and mark them as hidden or not
  92. for (var category_major_count = 0, category_major_length = array_of_all_categories.length; category_major_count < category_major_length; category_major_count++) {
  93. var category_major = array_of_all_categories[category_major_count];
  94.  
  95. array_of_all_categories[category_major_count].categories_minor.sort(function (a, b) {
  96. return (a.id - b.id); // sort by id, lowest first
  97. });
  98.  
  99.  
  100. var bit_characters = str_bit_array.substr(bit_string_category_count * characters_per_category, characters_per_category); // grab the 2 characters for this category
  101.  
  102. for (var category_minor_count = 0, category_minor_length = category_major.categories_minor.length; category_minor_count < category_minor_length; category_minor_count++) {
  103.  
  104. var minor_id = category_major.categories_minor[category_minor_count].id.slice(-2); // the last two digits are the minor category; the first two are always the same as the parent major category
  105. // if flag is '1', it is hidden
  106. array_of_all_categories[category_major_count].categories_minor[category_minor_count].is_hidden = is_category_hidden(bit_characters, minor_id);
  107. //console.debug(array_of_all_categories[category_major_count].categories_minor[category_minor_count].name + ' is hidden: '
  108. // + array_of_all_categories[category_major_count].categories_minor[category_minor_count].is_hidden);
  109. }
  110. var last_flag = characters_per_category * bit_flags_per_char; // last flag is used for major category, instead of subcategory #12 (2 * 6);
  111. array_of_all_categories[category_major_count].is_hidden = is_category_hidden(bit_characters, last_flag);
  112. //console.debug(array_of_all_categories[category_major_count].name + ' is hidden: '
  113. // + array_of_all_categories[category_major_count].is_hidden);
  114. bit_string_category_count += 1;
  115. if (bit_string_category_count > (categories_per_string - 1)) {
  116. // each of our custom bit arrays can only hold 8 categories' info. reset the counter and move on to the next bit array
  117. bit_string_category_count = 0;
  118. field_count += 1;
  119.  
  120. str_bit_array = str_bit_array_array[field_count]; // 3 custom fields with attributes
  121. // remove the first 4 characters (the unique ID plus a space)
  122. str_bit_array = str_bit_array.substring(unique_id_length); // 0-based, meaning start at character 5 (inclusive)
  123. }
  124. }
  125. return array_of_all_categories;
  126. }
  127.  
  128. /**
  129. * Returns true if the bit location is set to true.
  130. */
  131. function is_category_hidden(ascii_characters, minor_id) {
  132. var bit_shift_count = ((minor_id - 1) % bit_flags_per_char); // category 1 is stored in last bit flag; cat 2 in the second to last. cat 7 stored in last flag
  133. var bit_to_use = (Math.floor((minor_id - 1) / bit_flags_per_char)); // 1-6 (0-5) in first bit. 7-12 (6-11) stored in second. etc. 7/6 floored is 1.
  134. var bit_character = (ascii_characters.charCodeAt(bit_to_use)); // get binary representation
  135. var is_hidden = ((bit_character >>> bit_shift_count) & 000001); // shift the bits over and mask with '1'. if both are 1, it will return 1 (true) for hidden
  136. //console.log('is_hidden: ' + is_hidden);
  137. return is_hidden;
  138. }
  139.  
  140. function encode_category_hidden(ascii_characters, minor_id, is_hidden) {
  141. var bit_shift_count = ((minor_id - 1) % bit_flags_per_char); // category 1 is stored in last bit flag; cat 2 in the second to last. cat 7 stored in last flag
  142. var bit_to_use = (Math.floor((minor_id - 1) / bit_flags_per_char)); // 1-6 (0-5) in first bit. 7-12 (6-11) stored in second. etc. 7/6 floored is 1.
  143. var mask = ((is_hidden << bit_shift_count)); // move the mask to the proper location
  144.  
  145. var new_char = String.fromCharCode(ascii_characters[bit_to_use].charCodeAt(0) | mask);
  146. ascii_characters = ascii_characters.replaceAt(bit_to_use, new_char); // replace with new character
  147. //console.debug(ascii_characters);
  148. return ascii_characters;
  149. }
  150.  
  151. /**
  152. * Replaces the substituted characters with the 'illegal' characters.
  153. * This way, the script can use bitwise operations in a logical manner.
  154. */
  155. function translate_to_script(string_with_substituted_characters) {
  156. var str_return = string_with_substituted_characters.replace('?', String.fromCharCode(127)); // the delete char (127) is substituted with a question mark when saved at mint
  157. return str_return;
  158. }
  159.  
  160. /**
  161. * Replaces any illegal characters with substituted characters that mint.com allows in text fields.
  162. */
  163. function translate_to_mint(string_with_illegal_characters) {
  164. var str_return = string_with_illegal_characters.replace(String.fromCharCode(127), '?');
  165. return str_return;
  166. }
  167.  
  168. /**
  169. * Extracts the bit arrays from the saved custom category input box and puts all 3 into a string array.
  170. * Also hides the three fields, since the user probably shouldn't mess with them directly (and they look weird).
  171. * @returns {Array}
  172. */
  173. function extract_mint_array() {
  174. var str_bit_array_array = [];
  175. jQuery('#menu-category-' + category_id + ' ul li:contains("#!")').each(function () {
  176. str_bit_array_array.push(jQuery(this).text());
  177. //console.log('processing val is ' + jQuery(this).text());
  178. });
  179. return str_bit_array_array;
  180. }
  181.  
  182. function encode_bit_array(array_of_all_categories) {
  183. // loop through each category, create an ASCII character, and replace illegal characters
  184.  
  185. array_of_all_categories.sort(function (a, b) {
  186. return (a.id - b.id); // sort by id, lowest first
  187. });
  188.  
  189. var field_count = 0; // 0, 1, or 2; for the 3 unique fields holding the 23 category hidden attributes
  190. var bit_string_category_count = 0; // only 8 categories per string. once this goes past 7, reset and use next string.
  191. var str_bit_array_array = [];
  192.  
  193. // loop through each major category and its minor categories and mark them as hidden or not
  194. str_bit_array_array[field_count] = new Array(characters_per_category * categories_per_string + 1).join('@');
  195. for (var category_major_count = 0, category_major_length = array_of_all_categories.length; category_major_count < category_major_length; category_major_count++) {
  196.  
  197. var category_major = array_of_all_categories[category_major_count];
  198.  
  199. array_of_all_categories[category_major_count].categories_minor.sort(function (a, b) {
  200. return (a.id - b.id); // sort by id, lowest first
  201. });
  202.  
  203.  
  204. var bit_characters = new Array(characters_per_category + 1).join('@'); // the @ character is 01000000, so all flags (last 6) start 'off'.
  205. for (var category_minor_count = 0, category_minor_length = category_major.categories_minor.length; category_minor_count < category_minor_length; category_minor_count++) {
  206.  
  207. var minor_id = category_major.categories_minor[category_minor_count].id.slice(-2); // the last two digits are the minor category; the first two are always the same as the parent major category
  208. // if flag is '1', it is hidden
  209.  
  210. bit_characters = encode_category_hidden(bit_characters, minor_id, array_of_all_categories[category_major_count].categories_minor[category_minor_count].is_hidden);
  211. str_bit_array_array[field_count] = str_bit_array_array[field_count].replaceAt(bit_string_category_count * characters_per_category, bit_characters);
  212. }
  213. var last_flag = characters_per_category * bit_flags_per_char; // last flag is used for major category, instead of subcategory #12 (2 * 6);
  214. bit_characters = encode_category_hidden(bit_characters, last_flag, array_of_all_categories[category_major_count].is_hidden);
  215.  
  216. str_bit_array_array[field_count] = str_bit_array_array[field_count].replaceAt(bit_string_category_count * characters_per_category, bit_characters);
  217.  
  218. bit_string_category_count += 1;
  219. if (bit_string_category_count > (categories_per_string - 1)) {
  220. // each of our custom bit arrays can only hold 8 categories' info. reset the counter and move on to the next bit array
  221. bit_string_category_count = 0;
  222. field_count += 1;
  223. str_bit_array_array[field_count] = new Array(characters_per_category * categories_per_string + 1).join('@');
  224. }
  225. }
  226. // now that all 3 bit arrays are creates, tack on the unique id to the string
  227. for (var i = 0; i < number_of_bit_arrays; i++) {
  228. str_bit_array_array[i] = '#!' + (i + 1) + ' ' + str_bit_array_array[i];
  229. str_bit_array_array[i] = translate_to_mint(str_bit_array_array[i]);
  230. //console.log(str_bit_array_array[i]);
  231. }
  232. return str_bit_array_array;
  233. }
  234.  
  235.  
  236. /**
  237. * Will update or insert as needed.
  238. * @param bit_string
  239. */
  240. function upsert_field(bit_string) {
  241. var unique_id = bit_string.substr(0, unique_id_length);
  242. var input_id = jQuery('ul.popup-cc-L2-custom > li > input[value^="' + unique_id + '"]').prev().val();
  243. if (input_id) {
  244. update_field(bit_string);
  245. } else {
  246. insert_field(bit_string);
  247. }
  248. }
  249.  
  250. function insert_field(bit_string) {
  251. var hidden_token = JSON.parse(jQuery('#javascript-user').val()).token;
  252. var data = {
  253. pcatId: category_id,
  254. catId: 0,
  255. category: bit_string,
  256. task: 'C',
  257. token: hidden_token
  258. };
  259. jQuery.ajax(
  260. {
  261. type: "POST",
  262. url: '/updateCategory.xevent',
  263. data: data
  264. }
  265. );
  266. }
  267.  
  268. function update_field(bit_string) {
  269.  
  270. var hidden_token = JSON.parse(jQuery('#javascript-user').val()).token;
  271. var unique_id = bit_string.substr(0, unique_id_length);
  272.  
  273. var input = jQuery('ul.popup-cc-L2-custom > li > input[value^="' + unique_id + '"]');
  274. //console.log('setting input string from ' + input.val() + ' to ' + bit_string);
  275. input.val(bit_string); // set the value on the user's page manually (not needed for ajax, but needed for later processing)
  276. jQuery('#menu-category-' + category_id + ' ul li:contains("' + unique_id + '")').text(bit_string);
  277. /* input.prop('value',bit_string);
  278. input.attr('value',bit_string);*/
  279. var input_id = input.prev().val();
  280. var data = {
  281. pcatId: category_id,
  282. catId: input_id,
  283. category: bit_string,
  284. task: 'U',
  285. token: hidden_token
  286. };
  287. jQuery.ajax(
  288. {
  289. type: "POST",
  290. url: '/updateCategory.xevent',
  291. data: data
  292. }
  293. );
  294. }
  295.  
  296. function delete_field(bit_string) {
  297. var hidden_token = JSON.parse(jQuery('#javascript-user').val()).token;
  298. var unique_id = bit_string.substr(0, unique_id_length);
  299. var input_id = jQuery('ul.popup-cc-L2-custom > li > input[value^="' + unique_id + '"]').prev().val();
  300. var data = {
  301. catId: input_id,
  302. task: 'D',
  303. token: hidden_token
  304. };
  305. jQuery.ajax(
  306. {
  307. type: "POST",
  308. url: '/updateCategory.xevent',
  309. data: data
  310. }
  311. );
  312. }
  313.  
  314. /**
  315. * Loop through all the category objects. If any are hidden,
  316. * add the proper CSS to hide the field.
  317. * @TODO Create toggle to show hidden fields so they can be unhidden
  318. * @param default_categories
  319. */
  320. function process_hidden_categories(default_categories) {
  321. for (var major_count = 0; major_count < default_categories.length; major_count++) {
  322. for (var minor_count = 0; minor_count < default_categories[major_count].categories_minor.length; minor_count++) {
  323. if (default_categories[major_count].categories_minor[minor_count].is_hidden) {
  324. jQuery('#menu-category-' + default_categories[major_count].categories_minor[minor_count].id).addClass(class_hidden);
  325. //console.log('hide minor ' + default_categories[major_count].categories_minor[minor_count].id);
  326. jQuery('#pop-categories-' + default_categories[major_count].categories_minor[minor_count].id).addClass(class_hidden);
  327. }
  328. }
  329. if (default_categories[major_count].is_hidden) {
  330. jQuery('#menu-category-' + default_categories[major_count].id).addClass(class_hidden);
  331. jQuery('#pop-categories-' + default_categories[major_count].id).addClass(class_hidden);
  332.  
  333. }
  334. }
  335. hide_show_category(hs_action_hide);
  336. }
  337.  
  338. /**
  339. *
  340. * @param action
  341. */
  342. function hide_show_category(action) {
  343. var category = jQuery('.' + class_hidden);
  344. if (action == hs_action_hide) {
  345. // hide the categories completely
  346. category.hide();
  347. category.css('text-decoration', 'line-through');
  348. }
  349. if (action == hs_action_show) {
  350. // remove any visible attributes
  351. category.show();
  352. category.css('text-decoration', '');
  353. }
  354. if (action == hs_action_edit) {
  355. category.show();
  356. category.css('text-decoration', 'line-through');
  357. }
  358. }
  359.  
  360. function add_toggle() {
  361. if (!(jQuery('#sgs-toggle').length)) {
  362. var toggle_style = "position: absolute; right: 30px; top: 35px; cursor: pointer";
  363. var toggle_text = "Edit Hidden Categories";
  364. jQuery('#pop-categories-main').prepend('<div id="sgs-toggle" class="" style="' + toggle_style + '">' + toggle_text + '</div>');
  365. jQuery('#sgs-toggle').click(function () {
  366. edit_categories();
  367. });
  368. jQuery('#pop-categories-submit').click(function(){
  369. jQuery('#sgs-toggle').addClass('editing'); // force the current mode to be editing so the edit_categories call saves
  370. edit_categories(); // if user clicks the "I'm done" button, we should also save the categories.
  371. })
  372. }
  373. }
  374.  
  375. function edit_categories() {
  376. var toggle = jQuery('#sgs-toggle');
  377. toggle.toggleClass('editing');
  378. if (toggle.hasClass('editing')) {
  379. toggle.text('Save Hidden Categories');
  380. mint_edit(true); // make all categories clickable; when clicked, add class and strike out
  381. } else {
  382. mint_edit(false); // remove clickable event and strike css; go back to hiding
  383. mint_save();
  384. toggle.text('Edit Hidden Categories');
  385.  
  386. }
  387.  
  388. }
  389.  
  390. function mint_edit(edit_mode) {
  391. if (edit_mode) {
  392. // get the major and minor categories in the popup editor
  393. var minor_categories = jQuery('div.popup-cc-L2 > ul:first-of-type > li'); // second ul is custom categories, so just get first
  394. var major_categories = jQuery('#popup-cc-L1').find('.isL1');
  395.  
  396.  
  397. // display all previously hidden fields (except our three custom fields holding bit arrays)
  398.  
  399.  
  400. // add checkboxes to the categories
  401. minor_categories.each(function () {
  402. add_checkbox(this);
  403. });
  404. major_categories.each(function () {
  405. add_checkbox(this);
  406. })
  407. jQuery('input.hide_show_checkbox').css({
  408. 'position': 'absolute',
  409. 'right': '-18px'
  410. });
  411.  
  412. // add label for minor checkboxes
  413. jQuery('div.popup-cc-L2 > h3:first-of-type').append('<span class="' + class_edit_mode + ' minor_hide_show_label">Hide</span>');
  414. jQuery('span.minor_hide_show_label').css({
  415. 'position': 'absolute',
  416. 'right': '64px',
  417. 'top': '3px',
  418. 'font-size': '13px',
  419. 'font-weight': 'bold'
  420. });
  421.  
  422.  
  423. // add label for major categories
  424. jQuery('#pop-categories-form fieldset').prepend('<span class="' + class_edit_mode + ' major_hide_show_label">Hide</span>');
  425. jQuery('span.major_hide_show_label').css({
  426. 'position': 'absolute',
  427. 'left': '267px',
  428. 'font-size': '13px',
  429. 'font-weight': 'bold'
  430. });
  431. // add checkbox event. when checked add the 'hidden' class (which is scanned on save)
  432. jQuery('input.hide_show_checkbox').click(function () {
  433. parent_id = jQuery(this).parent().attr('id').replace(/\D/g, '');
  434. if (jQuery(this).is(':checked')) {
  435. jQuery('#menu-category-' + parent_id).addClass(class_hidden);
  436. jQuery('#pop-categories-' + parent_id).addClass(class_hidden);
  437. jQuery(this).parent().css('text-decoration', 'line-through');
  438. } else {
  439. jQuery('#menu-category-' + parent_id).removeClass(class_hidden);
  440. jQuery('#pop-categories-' + parent_id).removeClass(class_hidden);
  441. ;
  442. jQuery(this).parent().css('text-decoration', '');
  443.  
  444. }
  445. });
  446. hide_show_category(hs_action_edit);
  447. } else {
  448. // no longer editing (saving), so remove our labels and checkboxes, and re-hide the desired categories
  449. jQuery('.' + class_edit_mode).remove();
  450. hide_show_category(hs_action_hide);
  451. }
  452. }
  453.  
  454. function add_checkbox(element) {
  455. var checked = '';
  456. if (jQuery(element).hasClass(class_hidden)) {
  457. // hidden categories are checked
  458. checked = 'checked="checked"';
  459. }
  460. jQuery(element).append('<input type="checkbox" class="' + class_edit_mode + ' hide_show_checkbox"' + checked + ' />');
  461. }
  462.  
  463. /**
  464. * hooks to the save or cancel button so that hidden categories will be re-hidden after ajax refresh
  465. */
  466. function add_save_hook() {
  467. if ((jQuery('#pop-categories-submit').length && (!(jQuery('#pop-categories-submit').hasClass('sgs-hook-added'))))) {
  468.  
  469. jQuery('#pop-categories-submit').addClass('sgs-hook-added');
  470. jQuery('#pop-categories-submit, #pop-categories-close').click(function () {
  471. mint_refresh();
  472. });
  473.  
  474. }
  475. }
  476.  
  477. function add_dropdown_hook() {
  478. //console.log('start dropdown');
  479. //if ((jQuery('#txnEdit-category_input').length) && (!(jQuery('#txtEdit-category_input').hasClass('sgs-hook-added')))) {
  480. jQuery('#txnEdit-category_input').addClass('sgs-hook-added');
  481. jQuery('#txnEdit-category_input, #txnEdit-category_picker').off('click', mint_refresh);
  482. jQuery('#txnEdit-category_input, #txnEdit-category_picker').on('click', mint_refresh);
  483. //}
  484. }
  485.  
  486. /**
  487. * Hides our bit array custom categories permanently so the user won't accidentally mess with them.
  488. */
  489. function hide_bit_array() {
  490. jQuery('input[value^="#!"]').parent().hide();
  491. jQuery('li[id^="menu-category-"] a:contains("#!")').parent().hide();
  492.  
  493. }
  494.  
  495. /**
  496. * Allows immutable strings to have character(s) replaced
  497. * @param index
  498. * @param character
  499. * @returns {string}
  500. */
  501. String.prototype.replaceAt = function (index, character) {
  502. return this.substr(0, index) + character + this.substr(index + character.length);
  503. };
  504.  
  505. /**
  506. * Lets you bind an event and have it run first.
  507. * @param name
  508. * @param fn
  509. */
  510. jQuery.fn.bindFirst = function (name, fn) {
  511. // bind as you normally would
  512. // don't want to miss out on any jQuery magic
  513. this.on(name, fn);
  514.  
  515. // Thanks to a comment by @Martin, adding support for
  516. // namespaced events too.
  517. this.each(function () {
  518. var handlers = jQuery._data(this, 'events')[name.split('.')[0]];
  519. // take out the handler we just inserted from the end
  520. var handler = handlers.pop();
  521. // move it at the beginning
  522. handlers.splice(0, 0, handler);
  523. });
  524. };
  525.  
  526. function mint_refresh() {
  527. add_toggle();
  528. add_save_hook();
  529. // when the popup is opened or closed, re-hide the categories
  530. var str_bit_array_array = extract_mint_array();
  531. var default_categories = get_default_category_list();
  532. default_categories = decode_bit_array(str_bit_array_array, default_categories);
  533. process_hidden_categories(default_categories); // hides the appropriate fields
  534. hide_bit_array(); // comment this out in order to see the bit string data
  535. }
  536.  
  537. /**
  538. * Saves the preferences
  539. */
  540. function mint_save() {
  541. //console.debug('saving');
  542. var default_categories = get_default_category_list();
  543. var bit_array_array = encode_bit_array(default_categories);
  544. for (var i = 0; i < bit_array_array.length; i++) {
  545. upsert_field(bit_array_array[i]);
  546. }
  547. }
  548. ////// Start jQuery Addon
  549. /*
  550. * arrive.js
  551. * v2.1.0
  552. * https://github.com/uzairfarooq/arrive
  553. * MIT licensed
  554. *
  555. * Copyright (c) 2014-2015 Uzair Farooq
  556. */
  557. var _arrive_unique_id_=0;
  558. (function(n,u,p){function h(a){return a._shouldBeIgnored===p?-1!=(" "+a.className+" ").indexOf(" ignore-arrive ")?a._shouldBeIgnored=!0:null==a.parentNode?a._shouldBeIgnored=!1:a._shouldBeIgnored=h(a.parentNode):a._shouldBeIgnored}function q(a,c,e){for(var d=0,b;b=a[d];d++)h(b)||(f.matchesSelector(b,c.selector)&&(b._id===p&&(b._id=_arrive_unique_id_++),-1==c.firedElems.indexOf(b._id)&&(c.firedElems.push(b._id),e.push({callback:c.callback,elem:b}))),0<b.childNodes.length&&q(b.childNodes,c,e))}function v(a){for(var c=
  559. 0,e;e=a[c];c++)e.callback.call(e.elem)}function x(a,c){a.forEach(function(a){if(!h(a.target)){var d=a.addedNodes,b=a.target,r=[];null!==d&&0<d.length?q(d,c,r):"attributes"===a.type&&f.matchesSelector(b,c.selector)&&(b._id===p&&(b._id=_arrive_unique_id_++),-1==c.firedElems.indexOf(b._id)&&(c.firedElems.push(b._id),r.push({callback:c.callback,elem:b})));v(r)}})}function y(a,c){a.forEach(function(a){if(!h(a.target)){a=a.removedNodes;var d=[];null!==a&&0<a.length&&q(a,c,d);v(d)}})}function z(a){var c=
  560. {attributes:!1,childList:!0,subtree:!0};a.fireOnAttributesModification&&(c.attributes=!0);return c}function A(a){return{childList:!0,subtree:!0}}function g(a){a.arrive=k.bindEvent;f.addMethod(a,"unbindArrive",k.unbindEvent);f.addMethod(a,"unbindArrive",k.unbindEventWithSelectorOrCallback);f.addMethod(a,"unbindArrive",k.unbindEventWithSelectorAndCallback);a.leave=l.bindEvent;f.addMethod(a,"unbindLeave",l.unbindEvent);f.addMethod(a,"unbindLeave",l.unbindEventWithSelectorOrCallback);f.addMethod(a,"unbindLeave",
  561. l.unbindEventWithSelectorAndCallback)}if(n.MutationObserver&&"undefined"!==typeof HTMLElement){var f=function(){var a=HTMLElement.prototype.matches||HTMLElement.prototype.webkitMatchesSelector||HTMLElement.prototype.mozMatchesSelector||HTMLElement.prototype.msMatchesSelector;return{matchesSelector:function(c,e){return c instanceof HTMLElement&&a.call(c,e)},addMethod:function(a,e,d){var b=a[e];a[e]=function(){if(d.length==arguments.length)return d.apply(this,arguments);if("function"==typeof b)return b.apply(this,
  562. arguments)}}}}(),B=function(){var a=function(){this._eventsBucket=[];this._beforeRemoving=this._beforeAdding=null};a.prototype.addEvent=function(a,e,d,b){a={target:a,selector:e,options:d,callback:b,firedElems:[]};this._beforeAdding&&this._beforeAdding(a);this._eventsBucket.push(a);return a};a.prototype.removeEvent=function(a){for(var e=this._eventsBucket.length-1,d;d=this._eventsBucket[e];e--)a(d)&&(this._beforeRemoving&&this._beforeRemoving(d),this._eventsBucket.splice(e,1))};a.prototype.beforeAdding=
  563. function(a){this._beforeAdding=a};a.prototype.beforeRemoving=function(a){this._beforeRemoving=a};return a}(),w=function(a,c,e){function d(a){"number"!==typeof a.length&&(a=[a]);return a}var b=new B;b.beforeAdding(function(b){var c=b.target,d;if(c===n.document||c===n)c=document.getElementsByTagName("html")[0];d=new MutationObserver(function(a){e.call(this,a,b)});var m=a(b.options);d.observe(c,m);b.observer=d});b.beforeRemoving(function(a){a.observer.disconnect()});this.bindEvent=function(a,e,t){"undefined"===
  564. typeof t&&(t=e,e=c);for(var m=d(this),f=0;f<m.length;f++)b.addEvent(m[f],a,e,t)};this.unbindEvent=function(){var a=d(this);b.removeEvent(function(b){for(var c=0;c<a.length;c++)if(b.target===a[c])return!0;return!1})};this.unbindEventWithSelectorOrCallback=function(a){var c=d(this);b.removeEvent("function"===typeof a?function(b){for(var d=0;d<c.length;d++)if(b.target===c[d]&&b.callback===a)return!0;return!1}:function(b){for(var d=0;d<c.length;d++)if(b.target===c[d]&&b.selector===a)return!0;return!1})};
  565. this.unbindEventWithSelectorAndCallback=function(a,c){var e=d(this);b.removeEvent(function(b){for(var d=0;d<e.length;d++)if(b.target===e[d]&&b.selector===a&&b.callback===c)return!0;return!1})};return this},k=new w(z,{fireOnAttributesModification:!1},x),l=new w(A,{},y);u&&g(u.fn);g(HTMLElement.prototype);g(NodeList.prototype);g(HTMLCollection.prototype);g(HTMLDocument.prototype);g(Window.prototype)}})(this,"undefined"===typeof jQuery?null:jQuery);
  566.  
  567. ////// End jQuery Addon
  568. jQuery(document).arrive("#txnEdit-category_input", add_dropdown_hook);
  569.  
  570. }
  571.  
  572.  
  573. /**
  574. * Mint.com loads jquery after page is loaded, and it conflicts with other verions. We can't
  575. * use a sandbox for our script, either, since we must use their version of jquery in order
  576. * to hook into their ajax completion events.
  577. * Therefore, we must manually check for jquery every so often (50 ms) until it finally exists.
  578. * Then, we can call our jquery-requiring function and modify the page.
  579. * @param method
  580. */
  581. function defer(method) {
  582. if (window.jQuery) {
  583. method();
  584. } else {
  585. setTimeout(function () {
  586. defer(method)
  587. }, 50);
  588. }
  589. }
  590. window.onload = function () {
  591. defer(after_jquery);
  592. };