TagPro Region Select

Select your preferred region from the profile page or while "waiting for eligibility"

  1. // ==UserScript==
  2. // @name TagPro Region Select
  3. // @description Select your preferred region from the profile page or while "waiting for eligibility"
  4. // @author Ko
  5. // @version 1.2
  6. // @match *://*.koalabeast.com/*
  7. // @match *://*.jukejuice.com/*
  8. // @match *://*.newcompte.fr/*
  9. // @supportURL https://www.reddit.com/message/compose/?to=Wilcooo
  10. // @website https://redd.it/aunqi0
  11. // @license MIT
  12. // @require https://greasyfork.org/scripts/371240-TPUL.js
  13. // @namespace https://greasyfork.org/users/152992
  14. // ==/UserScript==
  15.  
  16. /* global tagpro, tagproConfig, $, tpul */
  17.  
  18. (function(){
  19.  
  20. // Immediately show the selection and enable the input
  21. // while finding a game (even when "waiting for eligibility")
  22.  
  23. if (tpul.playerLocation == 'find') {
  24.  
  25. $("#settings .js-cookie").prop("disabled", false)
  26. $("#settings .js-send-settings").show()
  27. $("#settings").show()
  28.  
  29. tagpro.rawJoinerSocket.on('settings', function(){
  30. // as soon as we get the updated settings from the server,
  31. // forcibly save server-chosen settings to the cookies.
  32. // (to fix a problem in case you select nothing, and the server auto-selects a region and mode for you)
  33.  
  34. // Get the current selection
  35.  
  36. var regions = $("#regions .js-cookie:checked").map( function(i,region){ $(region).data("region") }).get()
  37. var gameModes = $("#gameModes .js-cookie:checked").map( function(i,mode){ $(mode).data("mode") }).get()
  38.  
  39. // Save to the cookies
  40.  
  41. $("#settings .js-cookie").each(function() {
  42. var name = $(this).prop("name"),
  43. checked = $(this).prop("checked")
  44. $.cookie(name, checked, { expires: 36500, path: "/", domain: tagproConfig.cookieHost })
  45. })
  46. })
  47.  
  48. // Show some feedback
  49.  
  50. $("#settings .btn.js-send-settings").before('<div id=regions-status style="display: none;">Regions saved!').click(function(){
  51. $("#regions-status").slideDown()
  52. setTimeout( function(){ $("#regions-status").slideUp() }, 3e3)
  53. })
  54.  
  55. }
  56.  
  57.  
  58. // Show the region selection on the profile/settings page as well
  59.  
  60. if (tpul.playerLocation == 'profile' || tpul.playerLocation == 'settings') {
  61.  
  62. // A new header for "Region Select"
  63.  
  64. $("#settings, .card:first").before('<div id=region-select class="profile-settings block"><h3 class=header-title>Region Select</h3><form class=form-horizontal><div class=form-group></div><hr><div id=save-group class=form-group>')
  65.  
  66. // Fetch the currently available regions and gamemodes (from /games/find)
  67.  
  68. $("#region-select .form-group:first").load("/games/find #regions, #gameModes", function(){
  69. $("#regions").before('<label class="col-sm-4 control-label">Regions</label>').css('margin-bottom','15px')
  70. $("#gameModes").before('<label class="col-sm-4 control-label">Game modes</label>')
  71. $("#regions, #gameModes").addClass('col-sm-8')
  72.  
  73. // Select the currently enabled regions/modes (from the cookies)
  74.  
  75. $("#region-select .js-cookie").each(function() {
  76. var name = $(this).prop("name")
  77. $(this).prop("checked", $.cookie( name ) == "true")
  78. }).prop("disabled", false)
  79. })
  80.  
  81. // The save button
  82.  
  83. $("#save-group").append('<div class="col-sm-12 text-right"><div id=regions-status style="display: none;">Regions saved!</div><button id="saveRegions" class="btn" type="button">Save Regions')
  84. $("#regions-status").css('margin-bottom', '20px')
  85.  
  86. $("#save-group button").click(function(){
  87.  
  88. // Get the current selection
  89.  
  90. var regions = $("#regions .js-cookie:checked").map( function(i,region){ $(region).data("region") }).get()
  91. var gameModes = $("#gameModes .js-cookie:checked").map( function(i,mode){ $(mode).data("mode") }).get()
  92.  
  93. // Save to the cookies
  94.  
  95. $("#region-select .js-cookie").each(function() {
  96. var name = $(this).prop("name"),
  97. checked = $(this).prop("checked")
  98. $.cookie(name, checked, { expires: 36500, path: "/", domain: tagproConfig.cookieHost })
  99. })
  100.  
  101. // Show some feedback
  102.  
  103. $("#regions-status").slideDown()
  104. setTimeout( function(){ $("#regions-status").slideUp() }, 3e3)
  105. })
  106.  
  107. // Slightly change the style when not logged in
  108.  
  109. if (tpul.playerLocation == 'settings') {
  110. $("#region-select").addClass('card')
  111. $("#region-select h3").replaceWith('<h1>Region Select')
  112. $("#region-select .text-right").removeClass('text-right').addClass('text-center')
  113. }
  114. }
  115.  
  116. })()