Greasy Fork

Greasy Fork is available in English.

Bonk Kicked Alert

A userscript to add a message in chat if a player was kicked

当前为 2022-04-11 提交的版本,查看 最新版本

// ==UserScript==
// @name         Bonk Kicked Alert
// @version      1.0.0
// @author       Blu
// @description  A userscript to add a message in chat if a player was kicked
// @match        https://bonk.io/gameframe-release.html
// @run-at       document-start
// @grant        none
// @namespace http://greasyfork.icu/users/826975
// ==/UserScript==

// for use as a userscript ensure you have Excigma's code injector userscript
// http://greasyfork.icu/en/scripts/433861-code-injector-bonk-io

const injectorName = `BonkKicked`;
const errorMsg = `Whoops! ${injectorName} was unable to load.
This may be due to an update to Bonk.io. If so, please report this error!
This could also be because you have an extension that is incompatible with \
${injectorName}`;

function injector(src){
  let newSrc = src;
  
  // on receive packet 24, handle player kicked when ingame or in lobby
  newSrc = newSrc.replace(`O6H[8]=v8yy;`, `O6H[8]=v8yy;
    let playerArr = u6H[44];
    let player = playerArr[h97];
    
    let lobby = u6H[29];
    let ingame = u6H[30];
    if (lobby) {
      lobby.showStatusMessage("* " + player.userName + " was KICKED!", "#cc3333", false);
    }
    if (ingame) {
      ingame.chatStatus("* " + player.userName + " was KICKED!");
    }`);
  
  if(src === newSrc) throw "Injection failed!";
  console.log(injectorName+" injector run");
  return newSrc;
}

// Compatibility with Excigma's code injector userscript
if(!window.bonkCodeInjectors) window.bonkCodeInjectors = [];
window.bonkCodeInjectors.push(bonkCode => {
	try {
		return injector(bonkCode);
	} catch (error) {
		alert(errorMsg);
		throw error;
	}
});

console.log(injectorName+" injector loaded");