Skip to content

fix bug with map chat being sent to global on page load#761

Open
AcrylonitrileButadieneStyrene wants to merge 1 commit intoynoproject:masterfrom
AcrylonitrileButadieneStyrene:patch-3
Open

fix bug with map chat being sent to global on page load#761
AcrylonitrileButadieneStyrene wants to merge 1 commit intoynoproject:masterfrom
AcrylonitrileButadieneStyrene:patch-3

Conversation

@AcrylonitrileButadieneStyrene

the config loader reads the globalMessage key (controlling the globe in all chat) after it reads the chat index, which causes it to overwrite the message destination with whether or not all chat was set to go to global or map instead of which tab was actually selected.

this pr fixes that by preventing the all chat globe from driving state when not visible. it is still updated to look correct, and switching to the all tab still switches to the right channel.

an alternative fix would be reordering the other of things being done in the config loader, but to me that seems to be more finicky.

tested with this userscript, and it works:

// ==UserScript==
// @name        New script ynoproject.net
// @match       https://ynoproject.net/*
// @grant       unsafeWindow
// ==/UserScript==

let once = false;
console.log("running");
const orig = unsafeWindow.document.getElementById;
unsafeWindow.document.getElementById = function (name) {
  const val = orig.apply(this, arguments);
  if (name == "chatTabs") {
    if (once) return val;
    once = true;
    let a = orig.call(this, 'globalMessageButton');
    func = a.onclick;
    a.onclick = function () {
  this.classList.toggle('toggled');
  const chatInput = document.getElementById('chatInput');
  const toggled = this.classList.contains('toggled');

  // Only let globe change message destination if all chat is actually
  // selected, otherwise this only updates the visuals of the button,
  // since this function is over-used by the config loader for that.
  const active = document.getElementById("chatTabAll").classList.contains("active");
  if (active) {
    if (toggled)
      chatInput.dataset.global = true;
    else
      delete chatInput.dataset.global;
  }

  chatInput.disabled = toggled && document.getElementById('chatInputContainer').classList.contains('globalCooldown');
  config.globalMessage = toggled;
  updateConfig(config);
};
  }
  return val;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants