Skip to content

Instantly share code, notes, and snippets.

@baidut
Created July 17, 2019 00:29
Show Gist options
  • Select an option

  • Save baidut/e279c31b5a1d729d283e3c7c4a1c3ca6 to your computer and use it in GitHub Desktop.

Select an option

Save baidut/e279c31b5a1d729d283e3c7c4a1c3ca6 to your computer and use it in GitHub Desktop.

Revisions

  1. baidut renamed this gist Jul 17, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. baidut created this gist Jul 17, 2019.
    59 changes: 59 additions & 0 deletions Mediablock.userscripts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    // ==UserScript==
    // @name Mediablock
    // @description Closes social media from 7 AM to 6 PM inclusive on weekdays, 6 AM to 10 AM Saturdays, and completely free on Sundays!
    // @include https://*.reddit.com
    // @include https://*.reddit.com/*
    // @include https://*.facebook.com
    // @include https://*.facebook.com/*
    // @include https://*.twitter.com
    // @include https://*.twitter.com/*
    // @include https://scratch.mit.edu
    // @include https://scratch.mit.edu/*
    // @include https://*.newgrounds.com
    // @include https://*.newgrounds.com/*
    // @include https://*.myspace.com
    // @include https://*.myspace.com/*
    // @include https://*.youtube.com
    // @include https://*.youtube.com/*
    // @include https://*.zhihu.com/
    // @include https://*.zhihu.com/*
    // @include https://*.instagram.com
    // @include https://*.instagram.com/*
    // @include https://*.youtube.com
    // @include https://*.youtube.com/*
    // @run-at document-start
    // @namespace https://greasyfork.org/users/12417
    // @version 0.0.1.20151125025222
    // ==/UserScript==

    // For any further inquiries, please contact me at scratch.mit.edu/users/iamunknown2 or reddit/u/iamunknowntwo
    function block() // Function will block the website.
    {
    var current = window.location.href;
    window.history.back(); // Attempt to go back (if it's opened in a tab with no tab history)
    if (window.location.href == current) // If it's still there
    {
    window.close(); // Attempt to close page
    if (window.location.href == current) // If it's still there (if it's the only tab)
    {
    window.location.href = "about://newtab"; // Go to a new tab; always works!
    }
    }
    }

    var date1 = new Date();
    var hours = date1.getHours(); // Hours
    var day = date1.getDay(); // Day of the week

    if (day === 6) // If it's a Saturday
    {
    if (hours >= 5 && hours <= 9) // Doesn't hurt to add a few more hours of work.
    {
    block();
    }
    }

    else if (hours >= 6 && hours <= 17 && day !== 0) // If hours are 7 AM to 6 PM (inclusive) and not a Sunday
    {
    block();
    }