Greasy Fork is available in English.

Discussions » Creation Requests

Snappy Queue Software show only number

§
Posted: 23 Oktober 2023

Hello i have a local website i'd like to show only one small thing in it.

This is my code for it

// ==UserScript==
// @name New Userscript1
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://192.168.150.30:6060/qms/CounterTab.html
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant none
// ==/UserScript==



(function() {
'use strict';

// Function to remove all elements within the body
function removeEverythingExceptOne(elementId) {
const body = document.body;
const elements = Array.from(body.children);

for (const element of elements) {
if (element.id !== elementId) {
body.removeChild(element);
}
}
}

// Specify the ID of the element you want to keep
var elementToKeepId = 'id_s_Div';

// Remove everything except for the specified element
removeEverythingExceptOne(elementToKeepId);
})();



but its not working. The page html is attached. Can someone help me write the code

§
Posted: 23 Oktober 2023

There is no html or any explanation what you need and what is even Snappy Queue Software? But anyways, here is some function removeEverythingExceptOne, seems to be working and doing something. The screenshot is the topic page with everything removed except a reply form

function removeEverythingExceptOne(elementId) {
  const elementToKeep = document.getElementById(elementId);
  if (elementToKeep) {
    const parent = elementToKeep.parentNode;
    while (parent.firstChild) {
      if (parent.firstChild !== elementToKeep) {
        parent.removeChild(parent.firstChild);
      } else {
        break;
      }
    }
    while (parent.lastChild) {
      if (parent.lastChild !== elementToKeep) {
        parent.removeChild(parent.lastChild);
      } else {
        break;
      }
    }
  }
}

removeEverythingExceptOne('post-reply');

Post reply

Sign in to post a reply.