Fix HB layout

"Fix" HB's new layout

  1. // ==UserScript==
  2. // @name Fix HB layout
  3. // @author quanzi
  4. // @version 0.5
  5. // @description "Fix" HB's new layout
  6. // @grant none
  7. // @match https://www.humblebundle.com/games/*
  8. // @match https://www.humblebundle.com/books/*
  9. // @match https://www.humblebundle.com/software/*
  10. // @require http://code.jquery.com/jquery-latest.js
  11. // @namespace https://greasyfork.org/users/76976
  12. // ==/UserScript==
  13.  
  14. var tier_item_count;
  15. var tier_headers;
  16. var parent;
  17. var backup;
  18. var clone;
  19. var divisor;
  20.  
  21. function GM_addStyleX(cssStr) {
  22. var D = document;
  23. var newNode = D.createElement ('style');
  24. newNode.textContent = cssStr;
  25.  
  26. var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
  27. targ.appendChild (newNode);
  28. }
  29.  
  30. function sleep(ms) {
  31. return new Promise(resolve => setTimeout(resolve, ms));
  32. }
  33.  
  34. async function fix() {
  35. var tiers = Array.from($(".js-tier-filter"));
  36. tier_item_count = new Array();
  37. tier_headers = new Array();
  38. parent = $(".desktop-tier-collection-view")[0];
  39. for (tier of tiers) {
  40. tier.click();
  41. await sleep(0.3 * 1000);
  42. tier_item_count.push(parent.childElementCount - 1);
  43. var header = $(".tier-header")[0].textContent;
  44. header = header.slice(0, header.indexOf("for"));
  45. header += "to unlock!";
  46. tier_headers.push(header);
  47. }
  48. tier_item_count.reverse();
  49. tier_headers.reverse();
  50. console.log(tier_item_count);
  51. console.log(tier_headers);
  52. tiers[0].click();
  53. for (var i in tier_item_count) {
  54. $('<h3 class="tier-header heading-medium js-tier-header tier-item-view" googl="true" style="width:100%;margin:0 .4em;order:' +
  55. tier_item_count[i].toString() + '">' + tier_headers[i] + '</h3>').insertBefore(parent.childNodes[0]);
  56. }
  57. $(".tier-header")[0].textContent = "\xa0";
  58. $(".tier-filters")[0].style.display = "none";
  59. for (var i = parent.childNodes.length - 1, count = 0, t_index = 0; i >= 0, t_index < tier_item_count.length; i--){
  60. parent.childNodes[i].style.order = tier_item_count[t_index].toString();
  61. count++;
  62. if (count >= tier_item_count[t_index]) {
  63. t_index++;
  64. }
  65. }
  66. await sleep(0.5 * 1000);
  67. var clone = $(parent).clone(true);
  68. $(".js-basic-info-view").detach().appendTo(".bundle-title");
  69. $(".pwyw-view h2").clone().insertAfter(".quick-facts");
  70. $(".countdown-container").clone().insertAfter(".charity-amount-raised");
  71. $("<div class='button-get-the-bundle'>Get the bundle</div>").appendTo(".bundle-title");
  72. $(".button-get-the-bundle").click(function() { window.scrollTo(0, document.querySelector(".sidebar").offsetTop - $(".navbar").height()); });
  73. var total_item_count = tier_item_count[tier_item_count.length - 1];
  74. if (total_item_count >= 30)
  75. divisor = 8;
  76. else if (total_item_count >= 20)
  77. divisor = 7;
  78. else
  79. divisor = 4;
  80. console.log(divisor);
  81. $('form').on('keyup change paste', 'input, select, textarea',async function(){
  82. console.log('Form changed!');
  83. await sleep(0.5 * 1000);
  84. $(parent).empty();
  85. clone.appendTo($(".js-tier-collection")[0]);
  86. });
  87. var css = `
  88. .bundle-page .main-area { grid-column: 3/ span 8; text-align: center; }
  89. .bundle-page .sidebar { grid-column: 4 / span 6; }
  90. .bundle-title .bundle-logo { margin-left: auto; margin-right: auto; }
  91. .bundle-title .heading-medium { font-size: 20px; text-transform: uppercase; font-weight: bold; }
  92. .bundle-title .countdown-container { margin-top: 1em; font-size: 16px; text-transform: uppercase; }
  93. .bundle-title .time { font-size: 25px; display: block; }
  94. /*.inner-main-wrapper { text-align: center; }*/
  95. .desktop-tier-collection-view { justify-content: center; }
  96. .basic-info-view { line-height: normal; }
  97. .basic-info-view .quick-facts { justify-content: center; }
  98. .basic-info-view .quick-facts .fact { flex-basis: 25%; justify-content: center; font-size: 20px; margin-bottom: 0.5em;
  99. text-transform: uppercase; font-weight: bold;
  100. }
  101. .basic-info-view .charity-amount-raised { max-width: 50%; margin: auto; font-size: 20px; padding: 1em; }
  102. .splits-adjustment-view .split-option:not(:last-child) { display: block; width: 50%; float: left; }
  103. .splits-adjustment-view .split-option:last-child { clear: both; }
  104. .desktop-tier-collection-view .tier-item-view { width: calc((100% - 3.75em) / ` + divisor + `); }
  105. .tier-item-details-view { text-align: left; }
  106. .tier-item-details-view .header-area { text-align: center; }
  107. .tier-item-details-view .heading-medium { max-width: 100%; }
  108. .button-get-the-bundle {
  109. background-color: #9cb946; border-radius: 2px; color: white; cursor: pointer; font-size: 1.25em; font-weight: bold;
  110. padding: 1em; position: relative; text-align: center; text-rendering: optimizeLegibility;
  111. text-shadow: 0 3px 0 rgba(0,0,0,0.2); text-transform: uppercase; transition: 0.35s; width: max-content;
  112. margin: 1em auto 0 auto;
  113. }
  114. .button-get-the-bundle:hover {
  115. background-color: #748934;
  116. text-shadow: 0 3px 0 rgba(0,0,0,0.3);
  117. }
  118. `;
  119.  
  120. GM_addStyleX(css);
  121. }
  122.  
  123.  
  124. $(document).ready(function() {
  125. fix();
  126. });
  127.