Bonk.io - Disable P2P

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

目前为 2021-12-31 提交的版本。查看 最新版本

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