Greasy Fork 还支持 简体中文。

Mint.com Customize Default Categories

Hide specified default built-in mint.com categories

目前為 2015-03-16 提交的版本,檢視 最新版本

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