Mediablock

Closes social media from 7 AM to 6 PM inclusive on weekdays, 6 AM to 10 AM Saturdays, and completely free on Sundays!

  1. // ==UserScript==
  2. // @name Mediablock
  3. // @description Closes social media from 7 AM to 6 PM inclusive on weekdays, 6 AM to 10 AM Saturdays, and completely free on Sundays!
  4. // @include https://*.reddit.com
  5. // @include https://*.reddit.com/*
  6. // @include https://*.facebook.com
  7. // @include https://*.facebook.com/*
  8. // @include https://*.twitter.com
  9. // @include https://*.twitter.com/*
  10. // @include https://scratch.mit.edu
  11. // @include https://scratch.mit.edu/*
  12. // @include https://*.newgrounds.com
  13. // @include https://*.newgrounds.com/*
  14. // @include https://*.myspace.com
  15. // @include https://*.myspace.com/*
  16. // @include https://*.youtube.com
  17. // @include https://*.youtube.com/*
  18. // @run-at document-start
  19. // @namespace https://greasyfork.org/users/12417
  20. // @version 0.0.1.20151125025222
  21. // ==/UserScript==
  22.  
  23. // For any further inquiries, please contact me at scratch.mit.edu/users/iamunknown2 or reddit/u/iamunknowntwo
  24. function block() // Function will block the website.
  25. {
  26. var current = window.location.href;
  27. window.history.back(); // Attempt to go back (if it's opened in a tab with no tab history)
  28. if (window.location.href == current) // If it's still there
  29. {
  30. window.close(); // Attempt to close page
  31. if (window.location.href == current) // If it's still there (if it's the only tab)
  32. {
  33. window.location.href = "about://newtab"; // Go to a new tab; always works!
  34. }
  35. }
  36. }
  37.  
  38. var date1 = new Date();
  39. var hours = date1.getHours(); // Hours
  40. var day = date1.getDay(); // Day of the week
  41.  
  42. if (day === 6) // If it's a Saturday
  43. {
  44. if (hours >= 5 && hours <= 9) // Doesn't hurt to add a few more hours of work.
  45. {
  46. block();
  47. }
  48. }
  49.  
  50. else if (hours >= 6 && hours <= 17 && day !== 0) // If hours are 7 AM to 6 PM (inclusive) and not a Sunday
  51. {
  52. block();
  53. }