Entrance Chat Gallery Guilds Search Everyone Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
October 14, 2025 - @601.59 (what is this?)
Activity rating: Two Stars Posts & Arts: 18/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts Start New Topic  Submit Art
News: :eyes: ~ Inconvenience is counterculture ~ :eyes: Guild Events: There are no events!

+  MelonLand Forum
|-+  World Wild Web
| |-+  ♺ ∙ Web Crafting Materials
| | |-+  Simple Site Closer Script!


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


⛺︎ My Room

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

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
Pages: 1 [2] Print 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | ~ Send Feedback ~ 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