Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Flexable Chat
- // @namespace http://czogi.usermd.net
- // @version 0.2
- // @description Dodatek do gry umożliwiający modyfikowanie chatu w grze.
- // @author Czogi
- // @match https://alkatria.pl/game
- // @grant none
- // ==/UserScript==
- /*
- !!!UWAGA!!!
- Słowo "wspomagacz" zawarte w regulaminie(07.01.2021)(dd:mm:rrrr) gry "Alkatria" w punkcie 8 w podpunkcie c według mnie nie definiuje poniższego dodatku.
- Opieram się na artykule https://pl.wikipedia.org/wiki/Cheat oraz https://www.miejski.pl/tag-wspomagacze zawierających podane słowo kluczowe.
- Zakładając że przyjmujemy taką definicję słowa "wspomagacz" poniższy dodatek nie łamie żadnego z punktów regulaminu na dzień(07.01.2021)(dd:mm:rrrr)
- Każdy jednak może inaczej interpretować regulamin gry, więc uczulam każdego kto zdecyduje się na użytkowanie z tego dodatku na ewentualną możliwość złamania regulaminu gry.
- Pełny regulamin dostępny na stronie: https://alkatria.pl/rules.
- W razie błędów proszę o zgłoszenie w wiadomości prywatnej Сzogi#8027(588099587605135377) bądź na moim serwerze Discord, jeżeli jescze będę zajmować się projektem postaram się naprawić zgłoszone błędy.
- Instalacja:
- ### W związku z tym że nie wszyscy mogą wiedzieć w jaki sposób zainstalować userscript poniżej zamieszczam bardzo kródką instrukcję w jaki sposób to zrobić. ###
- #1: Zainstaluj dodatek na twoją przeglądarkę obsługujący skrypty userscript(Przykładowe dodatki na różne przeglądarki):
- -Firefox - Greasemonkey.
- -Chrome, Opera - Tampermonkey.
- #2: Dodaj skrypt z linku w ustawieniach Greasemonkey/Tampermonkey lub przekopiuj całość do edytora posiadanego przez ciebie dodatku i zapisz skrypt.
- #3: Odświerz stronę gry i voilà.
- Działanie:
- Skrypt zamienia kolory tła kolejnych wiadomości na chacie zgodnie z kolejnością i wartościami rgb podanymi w tablicy w linii 104.
- Kolor godziny przy "nieprzeczytanych" wiadomościach zamienia się na czerwony, wiadomość a także wszystkie poprzednie "nieprzeczytane" staje się "przeczytana" po najechaniu na nią myszką
- Skrypt dodatkowo umożliwia zmianę rozmiaru chatu.
- Długie wiadomości wychodzące poza okno chatu są zwijane do nowej linii.
- Wygląd dodatku w grze: http://czogi.usermd.net/alkatria/obrazy/flexable_chat.png
- Changelog:
- -0.1 Pierwsza wersja (07.01.2021).
- -0.2 Zmieniono sposób dodawania listenerów (07.01.2021).
- Nie mam nic przeciwko co do modyfikacji i redystrybucji dodatku/kodu.
- !!!UWAGA!!!
- */
- (() => {
- class ChatSettings {
- constructor() {
- this.name = "chatSettings";
- if (!localStorage[this.name]) {
- localStorage.setItem(this.name, "{}");
- }
- this.settings = JSON.parse(localStorage[this.name]);
- }
- get(key, defaultVal) {
- if (typeof this.settings[key] !== "undefined") {
- return this.settings[key];
- }
- return defaultVal;
- }
- set(key, val) {
- this.settings[key] = val;
- localStorage.setItem(this.name, JSON.stringify(this.settings));
- }
- }
- class ChatValues {
- constructor(chatFrameHeight, chatContentHeight, newChatContentHeight, tab) {
- this.frameHeight = this.pxToIntValye(
- getComputedStyle(chatFrameHeight).height
- );
- this.bgGroundHeight = this.pxToIntValye(
- getComputedStyle(chatContentHeight).height
- );
- this.newBgGroundHeight = this.pxToIntValye(
- getComputedStyle(newChatContentHeight).height
- );
- this.tabsHeight = this.pxToIntValye(getComputedStyle(tab).height);
- }
- pxToIntValye(string) {
- return parseInt(string.replace("px", ""));
- }
- }
- class RGB {
- constructor(r, g, b) {
- this.red = r;
- this.green = g;
- this.blue = b;
- }
- }
- const settings = new ChatSettings();
- const newBorder = document.createElement("div");
- const chatBottom = document.querySelector(".chat-frame-bottom");
- const chatContent = document.querySelector(".chat-content");
- const newBgGround = chatContent.cloneNode(false);
- newBgGround.classList = "";
- const chatFrame = document.querySelector(".chat-frame");
- const chatTab = document.querySelector(".chat-messages");
- const chatTop = document.querySelector(".w530px");
- const colors = [
- new RGB(191, 184, 78),
- new RGB(59, 143, 217),
- new RGB(242, 56, 56)
- ];
- let mousePressed = false,
- startMousePosition = 0,
- chatElementsPositions,
- currColor = 0;
- for (const tab of Array.from(document.querySelectorAll(".chat-messages"))) {
- tab.style.overflowWrap = "break-word";
- }
- newBorder.style.cssText = `border-color: rgb(49, 54, 50);
- border-style: solid;
- border-width: 1px;
- border-collapse: inherit;
- border-spacing: 6px;
- margin: -1px -4px 0px -1px;
- height: ${getComputedStyle(chatContent).height}`;
- chatBottom.style.cursor = "n-resize";
- newBgGround.style.background = getComputedStyle(chatContent).background;
- chatContent.style.background = "none";
- newBgGround.style.backgroundSize = "1000px 1000px";
- newBgGround.style.zIndex = "-1";
- newBgGround.style.backgroundPosition = "-50px -50px";
- newBgGround.style.backgroundRepeat = "no-repeat";
- newBgGround.style.position = "absolute";
- newBgGround.style.width = "523px";
- newBgGround.style.top = "0px";
- newBgGround.style.height = getComputedStyle(chatContent).height;
- chatTop.style.background = getComputedStyle(chatBottom).background;
- chatTop.style.left = "3px";
- chatTop.style.transform = "rotate(180deg)";
- chatTop.style.backgroundPosition = "center";
- chatContent.appendChild(newBorder);
- chatContent.appendChild(newBgGround);
- for (const tab of Array.from(document.querySelectorAll(".chat-messages"))) {
- tab.style.backgroundSize = "cover";
- }
- (() => {
- const properYData = settings.get("height", 0);
- if (!properYData) {
- return false;
- }
- chatElementsPositions = new ChatValues(
- chatFrame,
- chatContent,
- newBgGround,
- chatTab
- );
- const contentHeight = properYData + chatElementsPositions.bgGroundHeight;
- const frameHeight = properYData + chatElementsPositions.frameHeight;
- const newContentHeight =
- properYData + chatElementsPositions.newBgGroundHeight;
- const tabsHeight = properYData + chatElementsPositions.tabsHeight;
- chatContent.style.height = `${contentHeight}px`;
- chatFrame.style.height = `${frameHeight}px`;
- newBgGround.style.height = `${newContentHeight}px`;
- newBorder.style.height = `${contentHeight}px`;
- for (const tab of Array.from(document.querySelectorAll(".chat-messages"))) {
- tab.style.height = `${tabsHeight}px`;
- }
- })();
- chatBottom.addEventListener("mousedown", (mouseData) => {
- mousePressed = true;
- chatElementsPositions = new ChatValues(
- chatFrame,
- chatContent,
- newBgGround,
- chatTab
- );
- startMousePosition = mouseData.y;
- });
- document.addEventListener("mouseup", () => {
- if (!mousePressed) {
- return false;
- }
- mousePressed = false;
- startMousePosition = 0;
- });
- document.addEventListener("mousemove", (mouseData) => {
- if (!mousePressed) {
- return false;
- }
- const properYData = (startMousePosition - mouseData.y) * -1;
- settings.set("height", properYData);
- const contentHeight = properYData + chatElementsPositions.bgGroundHeight;
- const frameHeight = properYData + chatElementsPositions.frameHeight;
- const newContentHeight =
- properYData + chatElementsPositions.newBgGroundHeight;
- const tabsHeight = properYData + chatElementsPositions.tabsHeight;
- chatContent.style.height = `${contentHeight}px`;
- chatFrame.style.height = `${frameHeight}px`;
- newBgGround.style.height = `${newContentHeight}px`;
- newBorder.style.height = `${contentHeight}px`;
- for (const tab of Array.from(document.querySelectorAll(".chat-messages"))) {
- tab.style.height = `${tabsHeight}px`;
- }
- });
- window.game.chatMessage = (data) => {
- data.message = data.message.replace(
- /(http:\/\/[^\s]+)/gi,
- '<a href="$1" target="_blank">$1</a>'
- );
- data.message = data.message.replace(
- /(https:\/\/[^\s]+)/gi,
- '<a href="$1" target="_blank">$1</a>'
- );
- var text = "";
- const dateArray = data.date.split(".");
- const timeStampOfMsg = Date.parse(
- `${data.time} ${dateArray[1]}.${dateArray[0]}.${dateArray[2]}`
- );
- let msgIsNew = false;
- if (settings.get(`${data.channel}|lastRead`, 0) < timeStampOfMsg) {
- msgIsNew = !msgIsNew;
- }
- if (data.player != undefined) {
- text =
- `<span style="${msgIsNew ? "color: red" : ""}">${data.time}</span>` +
- ' <span class="player-chat" data-name="' +
- data.name +
- '">' +
- data.player +
- "</span>: " +
- data.message;
- } else if (data.time == undefined) {
- text = data.message;
- } else {
- text =
- `<span style="${msgIsNew ? "color: red" : ""}">${data.time}</span>` +
- ": " +
- data.message;
- }
- const bgOfMsg = `background: rgb(${Object.values(
- colors[currColor++ % colors.length]
- ).toString()},0.55)`;
- if (data.color != undefined) {
- $(".chat-messages-" + data.channel).append(
- `<span title=${data.date} style="color: ${data.color} ${bgOfMsg}" onmouseenter="leaveMsg(this)">${text}</span><br>`
- );
- } else {
- $(".chat-messages-" + data.channel).append(
- ` <span title=${data.date} style="${bgOfMsg}" onmouseenter="leaveMsg(this)">${text}</span><br>`
- );
- }
- if (this.channel != data.channel) {
- $(".channel-" + data.channel).addClass("new-message");
- }
- document.getElementById(
- "chat-messages-" + data.channel
- ).scrollTop = document.getElementById(
- "chat-messages-" + data.channel
- ).scrollHeight;
- };
- window.leaveMsg = (msg) => {
- const timeChild = msg.children[0];
- if (timeChild.style.color !== "red") {
- return false;
- }
- const dateArray = msg.title.split(".");
- const timeStampOfMsg = Date.parse(
- `${timeChild.innerText} ${dateArray[1]}.${dateArray[0]}.${dateArray[2]}`
- );
- settings.set(`${game.channel}|lastRead`, timeStampOfMsg);
- Array.from(
- document.querySelector("#chat-messages-" + game.channel).children
- ).forEach((element) => {
- if (element.tagName === "BR") {
- return false;
- }
- const timeChild = element.children[0];
- if (timeChild.style.color !== "red") {
- return false;
- }
- const dateArray = element.title.split(".");
- const timeStampOfElement = Date.parse(
- `${timeChild.innerText} ${dateArray[1]}.${dateArray[0]}.${dateArray[2]}`
- );
- if (timeStampOfElement > timeStampOfMsg) {
- return;
- }
- timeChild.style.color = "white";
- });
- };
- })();
Add Comment
Please, Sign In to add comment