Greasy Fork 支持简体中文。

Board Game Arena Games Tab Create Table button

adds a create table button to each game in the game list so you don't have to use the crappy play now section

  1. // ==UserScript==
  2. // @name Board Game Arena Games Tab Create Table button
  3. // @namespace https://boardgamearena.com
  4. // @version 0.3
  5. // @description adds a create table button to each game in the game list so you don't have to use the crappy play now section
  6. // @author ArmBandito
  7. // @match https://boardgamearena.com/*
  8. // @match https://*.boardgamearena.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. // Select the node that will be observed for mutations
  15. const targetNode = document.getElementById("main-content");
  16. if(targetNode != null){
  17. // Options for the observer (which mutations to observe)
  18. const config = {childList: true,};
  19. //const config = { attributes: false, childList: true, subtree: false };
  20.  
  21. // Create an observer instance linked to the callback function
  22. const observer = new MutationObserver(pageChange);
  23.  
  24. // Start observing the target node for configured mutations
  25. observer.observe(targetNode, config);
  26.  
  27. //this is for the game info page when we directly load a single game page
  28. const gametargetNode = document.getElementById("play_game_buttons");
  29. GameInfoPlay(gametargetNode);
  30. }
  31. })();
  32.  
  33. //on page change do our work
  34. function pageChange () {
  35.  
  36. //loop throught game rows and increase the height to accomadate for new button
  37. var gameslistrows = document.querySelectorAll('.gamelist_itemrow');
  38. for(var gamerow of gameslistrows.values()) {
  39. gamerow.style.height = "275px";
  40. }
  41.  
  42. //loop through list of games, and create a "create table" button for each
  43. var gameslist = document.querySelectorAll('.gamelist_item');
  44. for(var game of gameslist.values()) {
  45. game.style.height = "240px";
  46. var btn = document.createElement("button");
  47. btn.innerHTML = "Create Table";
  48. btn.classList.add("bgabutton");
  49. btn.classList.add("bgabutton_blue");
  50. btn.style.textAlign = "center";
  51. btn.style.marginLeft = "5%";
  52. btn.style.marginRight = "5%";
  53. btn.style.marginTop = "10px";
  54. btn.style.marginBottom = "10px";
  55. btn.style.width = "90%";
  56. btn.addEventListener("click", createGameTable);
  57.  
  58. game.appendChild(btn);
  59. }
  60.  
  61.  
  62. //this is for the game info page when we click on a single game when the page is already loaded
  63. const info_play_game = document.getElementById("play_game_buttons");
  64. GameInfoPlay(info_play_game);
  65.  
  66. }
  67.  
  68. function GameInfoPlay(element){
  69. if(element != null){
  70. var btn = document.createElement("button");
  71. btn.innerHTML = "Create Table";
  72. btn.classList.add("bgabutton");
  73. btn.classList.add("bgabutton_big");
  74. btn.classList.add("bgabutton_blue");
  75.  
  76. btn.addEventListener("click", createGameTable);
  77.  
  78. element.appendChild(btn);
  79. }
  80. }
  81.  
  82. //when the creat table button for a game is pressed fire off a request for a new table
  83. function createGameTable(){
  84. //grab game id
  85. var game_id = this.parentNode.id.split("_");
  86. //two different sources of game id whether or not there is currently a filter
  87. if(game_id.length == 4){
  88. game_id = game_id[3];
  89. }else{
  90. game_id = game_id[4];
  91. }
  92.  
  93. if(game_id == null){
  94. // if game id wasn't found in parent then we're on the single game page
  95. const single_game_id = document.getElementById("game_id");
  96. game_id = single_game_id.innerText;
  97. }
  98.  
  99. //send async request for a new table
  100. var xmlHttp = new XMLHttpRequest();
  101. xmlHttp.onreadystatechange = function() {
  102. if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
  103. createTableResponse(JSON.parse(xmlHttp.responseText));
  104. }
  105. }
  106. xmlHttp.open("GET", window.location.origin + "/table/table/createnew.html?game=" + game_id, true);
  107. xmlHttp.send(null);
  108. }
  109.  
  110. function createTableResponse(resonse){
  111. console.log(resonse);
  112. if(resonse.status == 1){
  113. window.location = window.location.origin + "/table?table=" + resonse.data.table;
  114. }
  115. else{
  116. alert("Failed to create table: " + resonse.error);
  117. }
  118. }