drrr.com QoL Tools

Show drrr.com chat room language on lounge so you don't need to hover on each room just to check the language.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         drrr.com QoL Tools
// @namespace    https://greasyfork.org/users/700963
// @version      v1.0.8
// @description  Show drrr.com chat room language on lounge so you don't need to hover on each room just to check the language.
// @author       eterNEETy
// @match        https://drrr.com/lounge*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=drrr.com
// @grant        none
// ==/UserScript==


var ui_icons = {
  "bot": "",
  "tv": "",
  "tablet": "",
  "mobile": "",
  "desktop": "",
  "console": "",
  "glass": "",
  "watch": ""
}

var flags_lang = {
  "zh-hans-MOE": "CN",
  "zh-hant-MOE": "TW",
  "ka-MOE": "JP",
  "ja-MOE": "JP"
}

function showDevice(r) {
  let el_profile = document.getElementById("profile");
  let el_name = el_profile.querySelector(".name");
  let el_tripcode = "";
  if ("tripcode" in r.profile) {
    el_tripcode = '<span class="tripcode">#' + r.profile.tripcode + '</span>';
  }
  el_name.innerHTML = r.profile.name + el_tripcode + '&nbsp;<span style="font-family: ui-icon;">'+ui_icons[r.profile.device]+'</span>';
}

function processRoom(room) {
  let el_room = document.querySelector('ul.rooms[data-meta*="' + room.id + '"] > li.name');
  if (el_room != null) {
    let el_flag = document.getElementById(room.id + "-flag");
    let lang_code = "US";
    if (room.language in flags_lang) {
      lang_code = flags_lang[room.language];
    } else {
      lang_code = room.language.slice(-2); 
    }
    if (el_flag == null) {
      el_flag = document.createElement("i");
      el_flag.id = room.id + "-flag";
      el_flag.className = "region region-" + lang_code;
      el_room.prepend(el_flag);
    } else {
      el_flag.className = "region region-" + lang_code;
    }
  }
}

function processRooms(r) {
  for (let i=0; i<r.rooms.length; i++) {
    let room = r.rooms[i];
    if ("id" in room) {
      processRoom(room);
    }
  }
}

(function() {
  'use strict';
  let origOpen = XMLHttpRequest.prototype.open;
  XMLHttpRequest.prototype.open = function() {
    this.addEventListener('load', function() {
      let url_obj = new URL(this.responseURL);
      if (url_obj.pathname == "/lounge" && url_obj.search == "?api=json") {
        let response = JSON.parse(this.responseText);
        processRooms(response);
        showDevice(response);
      }
    });
    origOpen.apply(this, arguments);
  };
})();