Greasy Fork

来自缓存

Fix HB layout

"Fix" HB's new layout

目前为 2021-05-30 提交的版本。查看 最新版本

// ==UserScript==
// @name     Fix HB layout
// @author   quanzi
// @version  0.1
// @description    "Fix" HB's new layout
// @grant    none
// @match    https://www.humblebundle.com/*
// @require http://code.jquery.com/jquery-latest.js
// @namespace https://greasyfork.org/users/76976
// ==/UserScript==

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function fix() {
  var tiers = Array.from($(".js-tier-filter"));
  var tier_item_count = new Array();
  var tier_headers = new Array();
  var parent = $(".desktop-tier-collection-view")[0];
  for (tier of tiers) {
    tier.click();
    await sleep(0.3 * 1000);
	  tier_item_count.push(parent.childElementCount - 1);
    var header = $(".tier-header")[0].textContent;
    header = header.slice(0, header.indexOf("for"));
    header += "to unlock!";
    tier_headers.push(header);
  }
  tier_item_count.reverse();
  tier_headers.reverse();
  console.log(tier_item_count);
  console.log(tier_headers);
  tiers[0].click();
  
  for (var i in tier_item_count) {
    $('<h3 class="tier-header heading-medium js-tier-header tier-item-view" googl="true" style="width:100%;margin:0 .4em;order:' + 
        tier_item_count[i].toString() + '">' + tier_headers[i] + '</h3>').insertBefore(parent.childNodes[0]);
  }
	$(".tier-header")[0].textContent = "\xa0";
  $(".tier-filters")[0].style.display = "none";
  for (var i = parent.childNodes.length - 1, count = 0, t_index = 0; i >= 0 ; i--){
    console.log("test");
    parent.childNodes[i].style.order = tier_item_count[t_index].toString();
    count++;
    if (count >= tier_item_count[t_index]) {
      t_index++;
    }
  }
}

$(document).ready(function() {
  fix();
});