DC - MobileFixes

Fix player interactions with draggable boxes

当前为 2019-12-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name DC - MobileFixes
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.13
  5. // @description Fix player interactions with draggable boxes
  6. // @author Ajira
  7. // @match https://www.dreadcast.net/Main
  8. // @match https://www.dreadcast.eu/Main
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. /* TODO ==============================================
  16. - Should loop on class identified objects like AITL
  17. =================================================== */
  18.  
  19. // Stop event propagation
  20. function disableEvent(event) {
  21. event.stopPropagation();
  22. }
  23.  
  24. // Trigger fix only if a dialogbox is popup
  25. document.getElementById("zone_lightBox").addEventListener('DOMNodeInserted', function() {
  26. // Check if the dialogbox contains a digicode input
  27. var digiInput = document.getElementById("lb_textinput_digicode");
  28. if (digiInput === null) { return; }
  29. // Search the parent form of the digicode
  30. var digiForm = digiInput.parentNode.parentNode;
  31. if (digiForm === null) { return; }
  32. // Search the dialogbox which contains the form
  33. var digiBox = digiForm.parentNode.parentNode;
  34. if (digiBox === null) { return; }
  35. // Disable draggable event which are in conflict with input click on mobile
  36. digiBox.removeEventListener("touchstart", disableEvent);
  37. digiBox.addEventListener("touchstart", disableEvent, true);
  38. }, false);
  39.  
  40. /* === FROM HERE ==========================
  41. Other experiments
  42. - Allow scrolling on long AITL offers
  43. - Allow to enter price in exchanges form
  44. - Allow to use decks
  45. ======================================== */
  46.  
  47. // Trigger fix only if a databox is popup
  48. document.getElementById("zone_dataBox").addEventListener('DOMNodeInserted', function() {
  49. // Check if the databox contains an aitl offer page
  50. var aitlPages = document.getElementsByClassName("aitl_page");
  51. if (aitlPages.length == 0) { return; }
  52. // Search for the AITL box
  53. var aitlBox = aitlPages[0].parentNode.parentNode.parentNode.parentNode;
  54. if (aitlBox === null) { return; }
  55. // Disable draggable event which are in conflict with scroll
  56. aitlBox.removeEventListener("touchstart", disableEvent);
  57. aitlBox.addEventListener("touchstart", disableEvent, true);
  58. }, false);
  59.  
  60. // Trigger fix only if a dialogbox is popup
  61. document.getElementById("zone_dataBox").addEventListener('DOMNodeInserted', function() {
  62. // Check if the dialogbox contains a exchange input
  63. var priceInput = document.getElementById("champ_credits");
  64. if (priceInput === null) { return; }
  65. // Search the parent form of the exchange
  66. var priceForm = priceInput.parentNode.parentNode;
  67. if (priceForm === null) { return; }
  68. // Search the dialogbox which contains the form
  69. var priceBox = priceForm.parentNode;
  70. if (priceBox === null) { return; }
  71. // Disable draggable event which are in conflict with input click on mobile
  72. priceBox.removeEventListener("touchstart", disableEvent);
  73. priceBox.addEventListener("touchstart", disableEvent, true);
  74. }, false);
  75.  
  76. // Trigger fix only if a dialogbox is popup
  77. document.getElementById("zone_dataBox").addEventListener('DOMNodeInserted', function() {
  78. // Check if the databox contains a deck
  79. var deckFroms = document.getElementsByClassName("deck_main");
  80. if (deckFroms.length == 0) { return; }
  81. // Search for the deck screen
  82. var deckScreen = deckFroms[0].parentNode.parentNode.parentNode;
  83. if (deckScreen === null) { return; }
  84. // Disable draggable event which are in conflict with scroll
  85. deckScreen.removeEventListener("touchstart", disableEvent);
  86. deckScreen.addEventListener("touchstart", disableEvent, true);
  87. }, false);
  88. })();