Bonk.io - Disable P2P

Disables peer-to-peer connections on bonk.io and supercarstadium.com to hide your IP address

  1. // ==UserScript==
  2. // @name Bonk.io - Disable P2P
  3. // @description Disables peer-to-peer connections on bonk.io and supercarstadium.com to hide your IP address
  4. // @version 0.6
  5. // @author kklkkj
  6. // @license MIT
  7. // @namespace https://github.com/kklkkj/
  8. // @match http*://*.bonk.io/*
  9. // @match http*://*.supercarstadium.com/*
  10. // @run-at document-body
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. // Delete some WebRTC things in case replacing PeerJS fails
  15. // If replacing PeerJS fails, Bonk will just show "Still waiting for P2P..."
  16. const webrtcThings = [
  17. "RTCCertificate",
  18. "RTCDataChannel",
  19. "RTCIceCandidate",
  20. "RTCIceTransport",
  21. "RTCPeerConnection",
  22. "RTCRtpReceiver",
  23. "RTCSessionDescription",
  24. "mozRTCIceCandidate",
  25. "mozRTCPeerConnection",
  26. "mozRTCSessionDescription",
  27. "webkitRTCPeerConnection",
  28. ];
  29.  
  30. for (const t of webrtcThings) delete window[t];
  31.  
  32. // RequireJS loads PeerJS by appending a script to <head>, thanks to Excigma for
  33. // some of this code
  34. const _appendChild = document.head.appendChild;
  35.  
  36. document.head.appendChild = function () {
  37. if (arguments?.[0]?.src?.includes("peer.min.js")) {
  38. // Replace peer.min.js with a fake version that doesn't do anything
  39. arguments[0].textContent = `
  40.  
  41. parcelRequire = function (e, r, t, n) {
  42. var i,
  43. o = 'function' == typeof parcelRequire && parcelRequire,
  44. u = 'function' == typeof require && require;
  45. function f(t, n) {
  46. if (!r[t]) {
  47. if (!e[t]) {
  48. var i = 'function' == typeof parcelRequire && parcelRequire;
  49. if (!n && i) return i(t, !0);
  50. if (o) return o(t, !0);
  51. if (u && 'string' == typeof t) return u(t);
  52. var c = new Error('Cannot find module \\'' + t + '\\'');
  53. throw c.code = 'MODULE_NOT_FOUND',
  54. c
  55. }
  56. p.resolve = function (r) {
  57. return e[t][1][r] || r
  58. },
  59. p.cache = {
  60. };
  61. var l = r[t] = new f.Module(t);
  62. e[t][0].call(l.exports, p, l, l.exports, this)
  63. }
  64. return r[t].exports;
  65. function p(e) {
  66. return f(p.resolve(e))
  67. }
  68. }
  69. f.isParcelRequire = !0,
  70. f.Module = function (e) {
  71. this.id = e,
  72. this.bundle = f,
  73. this.exports = {
  74. }
  75. },
  76. f.modules = e,
  77. f.cache = r,
  78. f.parent = o,
  79. f.register = function (r, t) {
  80. e[r] = [
  81. function (e, r) {
  82. r.exports = t
  83. },
  84. {
  85. }
  86. ]
  87. };
  88. for (var c = 0; c < t.length; c++) try {
  89. f(t[c])
  90. } catch (e) {
  91. i || (i = e)
  92. }
  93. if (t.length) {
  94. var l = f(t[t.length - 1]);
  95. 'object' == typeof exports && 'undefined' != typeof module ? module.exports = l : 'function' == typeof define && define.amd ? define(function () {
  96. return l
  97. }) : n && (this[n] = l)
  98. }
  99. if (parcelRequire = f, i) throw i;
  100. return f
  101. }({
  102. // Deleted other properties and modified the one below
  103. 'iTK6': [
  104. function (require, module, exports) {
  105. 'use strict';
  106. Object.defineProperty(exports, '__esModule', {
  107. value: !0
  108. });
  109.  
  110. exports.peerjs = {
  111. // Fake PeerJS API
  112. Peer: function () {
  113. this.destroy = function(){};
  114. this.on = function(eventName, callback) {
  115. if (eventName == "open") setTimeout(()=>{ callback("LOOL1"+Math.random().toString(36).substring(2,13)) }, 0);
  116. }
  117. this.connect = function(peerID) {
  118. return {
  119. on: function() {},
  120. open: false
  121. };
  122. }
  123. }
  124. // util: e.util
  125. },
  126. exports.default = exports.Peer
  127. window.peerjs = exports.peerjs,
  128. window.Peer = exports.Peer;
  129. },
  130. {}
  131. ]
  132. }, {
  133. }, [
  134. 'iTK6'
  135. ], null)
  136.  
  137. `;
  138. arguments[0].removeAttribute("src");
  139. const res = _appendChild.apply(document.head, arguments);
  140. arguments[0].dispatchEvent(new Event("load"));
  141.  
  142. console.log("replaced peer.min.js");
  143. return res;
  144. } else return _appendChild.apply(document.head, arguments);
  145. };
  146.  
  147. console.log("Disable P2P script run");