Random Background Color

Changes the background color randomly every few seconds

< Feedback on Random Background Color

Review: Good - script works

NotYouMod
§
Posted: 2023-03-27

Hi again, I just created the script with similar functionality, you can use it if you want:

const NODE = document.body
const FIRST_RANDOM_COLOR = getRandomColor()

setBackground(NODE, FIRST_RANDOM_COLOR)

updateBackground()

function updateBackground() {
    setTimeout(() => {
        const RANDOM_COLOR = getRandomColor()

        setBackground(NODE, RANDOM_COLOR)

        updateBackground()
    }, Math.floor(Math.random() * (5e3 - 500)) + 500) /* timeout between 500 milliseconds and 5 seconds */
}

function setBackground(node, bg) {
    node.style.backgroundColor = bg
}

function getRandomColor() {
    const r = randomNumberRGB()
    const g = randomNumberRGB()
    const b = randomNumberRGB()

    return `rgb(${r}, ${g}, ${b})`

    function randomNumberRGB() {
        return Math.floor(Math.random() * 255)
    }
}

It randomly changes background with random interval (between 5 seconds and 500 milliseconds).

NotYouMod
§
Posted: 2023-03-27

And yeah, script works good.

VirusterDevAuthor
§
Posted: 2023-03-27

I'm copying your idea of a greasyfork dark mode.

VirusterDevAuthor
§
Posted: 2023-03-27

Yeah, but mine is terrible, and I'm running out of ideas for things to code, I can't see what im typing as the text is black and input is black (textarea)

VirusterDevAuthor
§
Posted: 2023-03-27

I like the idea of scripts for adult sites though, I might do a XHampster or Heavy-R one.

NotYouMod
§
Posted: 2023-03-27

I'm copying your idea of a greasyfork dark mode.

Try your best, buddy!

Yeah, but mine is terrible, and I'm running out of ideas for things to code, I can't see what im typing as the text is black and input is black (textarea)

You can try to create a bigger script, for example, video downloader for YouTube that created the button that redirects you to a website with download links. On YouTube, you should use MutationObserver to check if DOM had mutations and also, don't let your code create duplicate buttons, you can expand your knowledge by this, plus you will create useful script that probably will get few hundred (or maybe more) installations.

I like the idea of scripts for adult sites though, I might do a XHampster or Heavy-R one.

Yeah, you can create user-script for adult websites as well. I, personally, just expand functional and add features that are useful for me (video downloading, ad block etc.), which is also interesting to create.

NotYouMod
§
Posted: 2023-03-27

And yeah, about textarea, you should write something like that to make textarea work correctly (if it wasn't already):

textarea {
  background-color: rgb(0, 0, 0);
  color: rgb(255, 255, 255); /* color that opposite to background color */
}
VirusterDevAuthor
§
Posted: 2023-03-27

In my dark mode, I rather using sort of a blue/purple as the text, borders, and what not.

Post reply

Sign in to post a reply.