Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name fh
- // @namespace http://tampermonkey.net/
- // @version 2023-12-29
- // @description try to take over the world!
- // @author fullhomo
- // @match https://www.shutdown.chat/rooms/downtown/*
- // @grant GM_openInTab
- // @grant GM_addStyle
- // ==/UserScript==
- GM_addStyle('#blockedContainer { height:100px; width: 900px; margin: 0 auto;}');
- GM_addStyle('#blockedMessages { height:90px; width: 900px; margin: 0 auto;}');
- (function() {
- 'use strict';
- if (/child/.test(location.search)) {
- window.stop();
- const xhr = new XMLHttpRequest();
- xhr.open('GET', window.location.href);
- xhr.onload = () => {
- var html = xhr.responseText
- .replace(/<script\b[\s\S]*?<\/script>/g, s => {
- // check if script tag should be replaced/deleted
- if (s.includes('rmp')) {
- let regex = /(_rmp\([^,]*,[^,]*,[^,]*,)(?:'[^']*'|[^,]*)(,)/;
- let str = s.replace(regex, "$1'0'$2");
- regex = /(_fcr\([^,]*,[^,]*,[^,]*,)(?:'[^']*'|"[^"]*"|[^,]*)(,)/;
- str = str.replace(regex, "$1'0'$2");
- return str;
- } else {
- return s;
- }
- });
- document.open();
- document.write(html);
- function onDocumentLoaded() {
- const chatbox = document.querySelector('.chatbox');
- if (!chatbox) {
- console.error('Chatbox not found');
- return;
- }
- let processedMessages = new Set();
- const getMessageInfo = (node) => {
- const username = node.querySelector('.nm')?.textContent.trim();
- const message = node.querySelector('.msg')?.textContent.trim();
- return {
- username,
- message
- };
- };
- function handleAllMessages({
- username,
- message
- }) {
- console.log(username + " " + message);
- window.opener.postMessage(username + ":" + message, "*");
- if (processedMessages.has(message)) {
- return;
- }
- processedMessages.add(message);
- }
- const observer = new MutationObserver((mutations) => {
- mutations.forEach(({
- addedNodes
- }) => {
- addedNodes.forEach((node) => {
- if (node.tagName === 'P') {
- const {
- username,
- message
- } = getMessageInfo(node);
- if (username && message) {
- handleAllMessages({
- username,
- message
- });
- }
- }
- });
- });
- });
- observer.observe(chatbox, {
- childList: true,
- subtree: true
- });
- document.querySelector(".fccb input").click();
- }
- document.addEventListener('DOMContentLoaded', onDocumentLoaded);
- document.close();
- };
- xhr.send();
- } else if (/blockcheck/.test(location.search)) {
- let allMessages = [];
- var processedMessages = [];
- // Function to find and append missing messages
- function appendMissingMessages() {
- // Find messages that are in allMessages but not in processedMessages
- let missingMessages = allMessages.filter(message => !processedMessages.includes(message));
- let messageBox = document.getElementById('blockedMessages');
- let missingMessagesText = "\n";
- missingMessages.forEach(message => {
- missingMessagesText += message + '\n';
- });
- messageBox.value = missingMessagesText;
- messageBox.scrollTop = messageBox.scrollHeight;
- }
- window.addEventListener('message', function(event) {
- allMessages.push(event.data);
- console.log("Message received from the child: " + event.data); // Message received from child
- });
- window.open("https://www.shutdown.chat/rooms/downtown/?child", "mozillaTab");
- //GM_openInTab("https://www.shutdown.chat/rooms/downtown/?child",{setParent : true});
- var divElement = document.createElement('div');
- divElement.id = "blockedContainer";
- var blockedButton = document.createElement("button");
- blockedButton.id = "blockedButton";
- blockedButton.innerHTML = "showBlockedMessages";
- divElement.appendChild(blockedButton);
- blockedButton.addEventListener('click', showBlockedMessages);
- let footer = document.getElementById("room_footer");
- document.querySelector("#content").insertBefore(divElement, footer);
- function showBlockedMessages() {
- var textbox = document.createElement('textarea');
- textbox.id = 'blockedMessages'; //
- document.querySelector("#blockedContainer").appendChild(textbox);
- document.querySelector("#blockedButton").style.display = "none";
- setInterval(appendMissingMessages, 1000);
- const chatbox = document.querySelector('.chatbox');
- if (!chatbox) {
- console.error('Chatbox not found');
- return;
- }
- const getMessageInfo = (node) => {
- const username = node.querySelector('.nm')?.textContent.trim();
- const message = node.querySelector('.msg')?.textContent.trim();
- return {
- username,
- message
- };
- };
- function handleAllMessages({
- username,
- message
- }) {
- processedMessages.push(username + ":" + message);
- }
- const observer = new MutationObserver((mutations) => {
- mutations.forEach(({
- addedNodes
- }) => {
- addedNodes.forEach((node) => {
- if (node.tagName === 'P') {
- const {
- username,
- message
- } = getMessageInfo(node);
- if (username && message) {
- handleAllMessages({
- username,
- message
- });
- }
- }
- });
- });
- });
- observer.observe(chatbox, {
- childList: true,
- subtree: true
- });
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement