Amazon Category Expander

The Category Expander expands all categories on the daily offers page of Amazon

  1. // ==UserScript==
  2. // @name Amazon Category Expander
  3. // @namespace https://lewisch.io/
  4. // @version 1.0
  5. // @description The Category Expander expands all categories on the daily offers page of Amazon
  6. // @author Thomas Lewisch
  7. // @match *.amazon.de/gp/angebote*
  8. // @require https://code.jquery.com/jquery-2.2.0.min.js
  9. // @grant none
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12. 'use strict';
  13.  
  14. var CategoryExpander = function(options) {
  15. this.options = options || {};
  16.  
  17. this.defaults = {
  18. selectors: { // the selectors used to find the categories
  19. expander: '.a-expander-header span', // the selector for the category expander
  20. categoryContainer: '#widgetFilters', // the selector for the category container
  21. },
  22. };
  23.  
  24. this.settings = jQuery.extend({}, this.defaults, options);
  25. };
  26.  
  27. /**
  28. * starts the category selector
  29. *
  30. * @return {void}
  31. */
  32. CategoryExpander.prototype.run = function () {
  33. var self = this,
  34. exists = window.setInterval(function() {
  35. if (self.filters().length) {
  36. self.expandCategories();
  37. window.clearInterval(exists);
  38. }
  39. }, 100);
  40. };
  41.  
  42. /**
  43. * gets the container element that holds the filters
  44. *
  45. * @return {jQuery element|array}
  46. */
  47. CategoryExpander.prototype.filters = function () {
  48. return jQuery(document).find(this.settings.selectors.categoryContainer);
  49. };
  50.  
  51. /**
  52. * expands the categories to display all categories
  53. *
  54. * @return {void}
  55. */
  56. CategoryExpander.prototype.expandCategories = function () {
  57. this.filters().find(this.settings.selectors.expander).trigger('click');
  58. };
  59.  
  60. /**
  61. * initializes a new category expander
  62. *
  63. * @param {object} options
  64. * @return {CategoryExpander}
  65. */
  66. CategoryExpander.init = function(options) {
  67. var expander = new CategoryExpander(options);
  68.  
  69. expander.run();
  70.  
  71. return expander;
  72. };
  73.  
  74. jQuery(document).ready(function($) {
  75. CategoryExpander.init();
  76. });