Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
June 07, 2026 - @3.31 (what is this?)
Activity rating: Four Stars Posts & Arts: 63/1k.beats ~ Boop! The forum will close in 997.beats! Random | Recent Posts | Guild Recents
News: inconvenience is counterculture :eyes: Guild Events: Happy Pride Month Fibre Artists!

+  MelonLand Forum
|-+  Materials & Info
| |-+  ♺ ∙ Web Crafting Materials
| | |-+  Simple Site Closer Script!


« previous next »
Pages: 1 [2] Print Embed
Author Topic: Simple Site Closer Script!  (Read 10671 times)
TAS_1K
Casual Poster
*
View Profile


⛺︎ My Room

Artifacts:
First 1000 Members!Joined 2022!
« Reply #15 on: September 23, 2025 @770.65 » Embed

I'd love to see if other variants of the idea could be implemented. Can you close a site for certain hours? The entire year except one month, one week, one week, one hour, one minute?  :dunno:

Of course, sounds kinda counterproductive, but it could lead to some fun ideas, methinks  :tongue:

Definitely - the API reference for the Date API will have more info if you want to try other variants, but here's a modified version that lets you play around with them!

First, the base script, which is a modified version of Melon's:

Code
// Simple Site Closer script v0.1
// This script shuts down certain pages automatically on some days of the week so you can close your site!
//
// How to use:
// Just place this script in the head of any page you'd like to close!
// Make a page called closed.html and put your closed info on there!
// Add this code after you link the script:
// <script>
// 	// sc.closedPage = "closed.html"; // Optional: change the closed page url
// 	// sc.closedDays = ["Thursday"]; // Optional: change the days to close (default is Monday)
// 	shutItDown();
// </script>
//
// You can also set a function that returns a boolean indicating whether the site is closed:
// <script>
//     sc.isSiteClosed = function (now) {
//         // Example: Check if the current hour is greater than 8:00 p.m. local time
//         return now.getHours() >= 20;
//     }
// </script>
// This will override the default check, which looks at the current day.

var sc = {};
sc.closedPage = "closed.html";
sc.closedDays = ["Monday"];
sc.weekDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

sc.isSiteClosed = function (now) {
    sc.dayNow = sc.weekDays[now.getDay()];

    return sc.closedDays.includes(sc.dayNow);
}

// Trigger this site closer!
function shutItDown() {
    if (sc.isSiteClosed(new Date())) {
        console.log("Gordon Ramsay screams: Shut it Down!!!");
        window.location.replace(sc.closedPage);
    }
}

After including this script on your site, you would set the sc.isSiteClosed property instead of sc.closedDays, assigning it to a function that takes a Date object and returns a boolean. The boolean indicates whether the site is currently closed (true) or not (false).

For example, this checks if it's 8:00 p.m. or later:

Code
sc.isSiteClosed = function (now) {
    return now.getHours() >= 20;
}

shutItDown();

Or this could check if it's currently between 12:00 and 12:30 p.m., to simulate a lunch break:

Code
sc.isSiteClosed = function (now) {
    return now.getHours() === 12 && now.getMinutes() < 30;
}

shutItDown();

Haven't tested this yet so if you have any issues with it let me know!
Logged
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!
« Reply #16 on: May 12, 2026 @715.93 » Embed

@IndigoGolem, @mae_h, @snufkin and I were discussion in the Shoutbox today whether it'd be possible to adapt @Melooon's "site closer script" so that instead of applying to days-of-the-week (e.g. "closed on Mondays") it could apply to arbitrary dates.

So I've thrown something together that does that. Here you go.

It works basically the same way, except you specify in your JavaScript a list of date patterns that the site will be closed, like this:


Code
sc.closedDays = [/^2026-01-01/, /^2026-12-../, /^....-..-01/];

That one says the site is closed on the 1st January 2026 (/^2026-01-01/), all of December 2026 (/^2026-12-../), and on the 1st of every month (/^....-..-01/).

Otherwise It's got all the same strengths and limitations of the original.

Hope that helps somebody!




For completeness/keeping everything in one place, here's the entire script plus its documentation comments, ready to save as e.g. site-closer.js, link to with a <script> tag, and then do what it says in the docs:

Code
// DATED Simple Site Closer script v0.1
// This script shuts down certain pages automatically on some dates, expressed as regular expressions of ISO8601 datestamps!
// With thanks to MelonKing's original version: https://melonking.net/scripts/site-closer.js
//
// How to use:
// Just place this script in the head of any page you'd like to close!
// Make a page called closed.html and put your closed info on there!
//
// Add this code after you link the script:
// <script>
//   sc.closedPage = "closed.html"; // Optional: change the closed page url
//   sc.closedDays = [/^2026-01-01/, /^2026-12-../, /^....-..-01/]; // Specify the dates you'll be closed; syntax explained below
//   shutItDown();
// </script>
//
// closedDays are all regular expressions. But you don't need to know regular expressions to use this!
// Just remember that each date looks like this:
// /^....-..-../
//   yyyy mm dd
// Replace the dots with the yyyy-mm-dd date you want to be closed.
// Anything that's still a dot is a WILDCARD. So the following are all valid:
// /^2017-..-../   =   closed all of 2017!
// /^....-..-01/   =   closed on the first of every month
// /^....-04-01/   =   closed every 1st of April
// /^2020-01-01/   =   closed 1st of January 2020
//
// You can list as many dates as you want, separated by commas. Just remember the starting /^
// and the ending / - they're important!

let sc = {};
sc.closedPage = "closed.html";
sc.closedDays = [];

// Trigger this site closer!
function shutItDown() {
  sc.dayNow = new Date().toISOString();
  const closedToday = !!sc.closedDays.find(matcher=>today.match(matcher));
  if(closedToday) {
    console.log("Gordon Ramsay screams: Shut it Down!!!");
    window.location.replace(sc.closedPage);
  }
}
Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif

Artifact Swap: I met Dan Q on Melonland!Polyamorousradio polyJoined 2025!
Pages: 1 [2] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
MelonLand @000

Want to Login or Join ?

Minecraft: Online
Join: craft.melonking.net