Sort Bounties By Reward

Sort bounties by reward

  1. // ==UserScript==
  2. // @name Sort Bounties By Reward
  3. // @description Sort bounties by reward
  4. // @include http://g.e-hentai.org/bounty.php?u=*
  5. // @include http://g.e-hentai.org/bounty.php?*&u=*
  6. // @version 0.0.1.20150701182040
  7. // @namespace https://greasyfork.org/users/2233
  8. // ==/UserScript==
  9.  
  10. /*** Settings ***/
  11.  
  12. var hath_to_credits = 6000
  13. var sort_from_small_to_big = true
  14.  
  15. /*** End of Settings ***/
  16.  
  17. var wnd = window
  18. var doc = wnd.document
  19. var loc = location
  20. var href = loc.href
  21.  
  22. var $ = function(e, css) { if(!css) { css=e; e=doc }; return e.querySelector(css) }
  23. var $$ = function(e, css) { if(!css) { css=e; e=doc }; return e.querySelectorAll(css) }
  24.  
  25. var t = $$('.itg')
  26. for(var i=0, len_i=t.length; i<len_i; i++) {
  27. var b = $$('[class^="gtr"]')
  28. var b_arr = Array.prototype.slice.call(b, 0)
  29. b_arr.sort(function(a, b) {
  30. var a_reward = a.querySelectorAll('.itd')[4].textContent
  31. var m_credits = a_reward.match(/([0-9, ]+)Credits/i)
  32. var m_hath = a_reward.match(/([0-9, ]+)Hath/i)
  33. a_reward = 0
  34. if(m_credits) {
  35. m_credits = parseInt(m_credits[1].replace(/[, ]/g, ''))
  36. a_reward += m_credits
  37. }
  38. if(m_hath) {
  39. m_hath = parseInt(m_hath[1].replace(/[, ]/g, ''))
  40. a_reward += (m_hath * hath_to_credits)
  41. }
  42.  
  43. var b_reward = b.querySelectorAll('.itd')[4].textContent
  44. var m_credits = b_reward.match(/([0-9, ]+)Credits/i)
  45. var m_hath = b_reward.match(/([0-9, ]+)Hath/i)
  46. b_reward = 0
  47. if(m_credits) {
  48. m_credits = parseInt(m_credits[1].replace(/[, ]/g, ''))
  49. b_reward += m_credits
  50. }
  51. if(m_hath) {
  52. m_hath = parseInt(m_hath[1].replace(/[, ]/g, ''))
  53. b_reward += (m_hath * hath_to_credits)
  54. }
  55.  
  56. if(sort_from_small_to_big) {
  57. if(a_reward < b_reward) { return -1 }
  58. if(a_reward > b_reward) { return 1 }
  59. return 0
  60. }
  61. else {
  62. if(a_reward > b_reward) { return -1 }
  63. if(a_reward < b_reward) { return 1 }
  64. return 0
  65. }
  66. })
  67.  
  68. var b_cln = []
  69. for(var j=0, len_j=b_arr.length; j<len_j; j++) {
  70. //console.log(b_arr[j].querySelectorAll('.itd')[4].textContent)
  71. b_cln.push(b_arr[j].cloneNode(true))
  72. }
  73. for(var j=0, len_j=b.length; j<len_j; j++) {
  74. b[j].parentNode.replaceChild(b_cln[j], b[j])
  75. }
  76. }