-
1.
// ==UserScript==
-
2.
// @name Everfree Outpost Chat Extensions
-
3.
// @description Adds extra chat functionalities to Everfree Outpost.
-
4.
// @author "Thorn Rose", "Green", "Script Anon", "haypone"
-
5.
// @version 0.5.2
-
6.
// @namespace everfree-outpost
-
7.
// @match *://play.everfree-outpost.com/*
-
8.
// @grant GM_addStyle
-
9.
// @connect play.everfree-outpost.com
-
10.
// @run-at document-start
- 11.
-
12.
// ==/UserScript==
-
13.
-
14.
var my_name="haypone"; //Your name on EO so it won't notify your own messages, it can be changed.
-
15.
//var audio = new Audio("https://notificationsounds.com/storage/sounds/file-sounds-1127-beyond-doubt.mp3"); //The sound it will play, it can be changed
-
16.
//-----------------------------
-
17.
-
18.
var GREEN="#306030";
-
19.
var PURPLE="#8844CC";
-
20.
var BLUE="#303090";
-
21.
var LIGHTBLUE="#306090";
-
22.
var RED="#903030";
-
23.
var DARKCYAN="#2D5B60";
-
24.
var userMap = { //Change these to actual names and other colors
-
25.
"True Lime": GREEN,
-
26.
"Derpy": "#71797E",
-
27.
"C": "#0047AB",
-
28.
"Stubenhocker": "#f36044",
-
29.
"Z": "#903060",
-
30.
"E": PURPLE,
-
31.
"F": PURPLE,
-
32.
"G": "#686772",
-
33.
"H": "#96663B",
-
34.
"I": "#606090",
-
35.
"J": "#609030",
-
36.
"K": DARKCYAN,
-
37.
"L": RED,
-
38.
"M": "#FFE085",
-
39.
"N": "#FDBFFF",
-
40.
"O": RED,
-
41.
"P": BLUE,
-
42.
"Q": LIGHTBLUE
-
43.
};
-
44.
-
45.
let lastLine = '';
-
46.
-
47.
var unreadMessages = 0;
-
48.
var original_title = document.title; //Do not change
-
49.
var blink_interval;
-
50.
var is_blinking=false; //Do not change
-
51.
addEventListener("mousemove", stop_blinking);
-
52.
-
53.
const config = { attributes: false, childList: true, subtree: false };
-
54.
// Callback function to execute when mutations are observed
-
55.
const callback = (mutationList, observer) => {
-
56.
for (const mutation of mutationList) {
-
57.
if (mutation.type === "childList") {
-
58.
newChatLine();
-
59.
}
-
60.
}};
-
61.
// Create an observer instance linked to the callback function
-
62.
const observer = new MutationObserver(callback);
-
63.
-
64.
let chat;
-
65.
//UI is created after the site is loaded, so we need to wait for it to exist
-
66.
function init() {
-
67.
let chats = document.getElementsByClassName("chat");
-
68.
if(chats.length >= 2) {
-
69.
chat = chats[1];
-
70.
unreadMessages = 0;
-
71.
const chatMessages = document.getElementsByClassName("chat-line");
-
72.
for(let i = 1; i < chatMessages.length; i++) {
-
73.
unreadMessages++;
-
74.
modifyChatLine(chatMessages[i]);
-
75.
}
-
76.
observer.observe(chat, config);
-
77.
clearInterval(initTimer);
-
78.
}
-
79.
}
-
80.
const initTimer = setInterval(init, 150);
-
81.
-
82.
window.onfocus = function() {
-
83.
unreadMessages = 0;
-
84.
stop_blinking();
-
85.
}
-
86.
-
87.
function stop_blinking(_) {
-
88.
document.title = original_title;
-
89.
clearInterval(blink_interval)
-
90.
is_blinking = false;
-
91.
}
-
92.
-
93.
function blink_title(message) {
-
94.
if (document.title===message) {
-
95.
document.title=original_title;
-
96.
} else {
-
97.
document.title=message;
-
98.
}
-
99.
}
-
100.
-
101.
function formatDate(date) {
-
102.
var hours = date.getHours();
-
103.
var minutes = date.getMinutes();
-
104.
minutes = minutes < 10 ? '0'+minutes : minutes;
-
105.
var strTime = hours + ':' + minutes;
-
106.
return strTime;
-
107.
}
-
108.
-
109.
function urlify(text) {
-
110.
var urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
-
111.
return text.replace(urlRegex, function(url,b,c) {
-
112.
var url2 = (c == 'www.') ? 'http://' +url : url;
-
113.
return '<a href="' +url2+ '" target="_blank">' + url + '</a>';
-
114.
})
-
115.
}
-
116.
-
117.
function modifyChatLine(lastChatMessage) {
-
118.
const wasScrolled = Math.abs(chat.scrollHeight - chat.scrollTop - chat.clientHeight) <= 5; //how many pixels
-
119.
const user = lastChatMessage.children[0];
-
120.
const text = lastChatMessage.children[1];
-
121.
//lastLine = text;
-
122.
-
123.
const userInnerText = user.innerText;
-
124.
if(userInnerText.length == 0) return;
-
125.
const username = userInnerText.substr(1, userInnerText.length - 2);
-
126.
-
127.
if(userInnerText[0] == '[') return;
-
128.
user.innerText = `[${formatDate(new Date)}] ${userInnerText}`;
-
129.
-
130.
text.innerHTML = urlify(text.innerHTML);
-
131.
if (my_name !== username && username !== "*") {
-
132.
unreadMessages += 1;
-
133.
//audio.play();
-
134.
if (!is_blinking && !document.hasFocus()) { //Title blinks only if it is not currently blinking or if the user is not on EO tab
-
135.
blink_interval = setInterval(function(){blink_title(`${unreadMessages} New message!`);},1000)
-
136.
is_blinking=true
-
137.
}
-
138.
}
-
139.
-
140.
/*if (username in userMap) {
-
141.
user.css("color", userMap[username]);
-
142.
user.css("font-weight", "bold");
-
143.
user.css("text-shadow", "0px 0px 6px #fff");
-
144.
}*/
-
145.
-
146.
if(wasScrolled) chat.scrollTop = chat.scrollHeight - chat.clientHeight;
-
147.
}
-
148.
-
149.
function newChatLine () {
-
150.
stop_blinking();
-
151.
const chatMessages = document.getElementsByClassName("chat-line");
-
152.
const lastChatMessage = chatMessages[chatMessages.length-1];
-
153.
modifyChatLine(lastChatMessage);
-
154.
}
by Guest
by Guest
by Guest
by Guest
by Guest