Mediablock

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

目前為 2015-11-25 提交的版本,檢視 最新版本

  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. // @version 0.0.1.20151125025029
  20. // @namespace https://greasyfork.org/users/12417
  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 iframes = document.getElementsByTagName("iframe");
  27. for (var i in iframes)
  28. {
  29. if (iframes[i].getAttribute("src").split(".")[1] == "youtube")
  30. {
  31. isyoutube = true;
  32. iframes[i].parentNode.removeChild(iframes[i]);
  33. }
  34. }
  35. if (isyoutube != undefined)
  36. {
  37. var current = window.location.href;
  38. window.history.back(); // Attempt to go back (if it's opened in a tab with no tab history)
  39. if (window.location.href == current) // If it's still there
  40. {
  41. window.close(); // Attempt to close page
  42. if (window.location.href == current) // If it's still there (if it's the only tab)
  43. {
  44. window.location.href = "about://newtab"; // Go to a new tab; always works!
  45. }
  46. }
  47. }
  48. }
  49.  
  50.  
  51. var date1 = new Date();
  52. var hours = date1.getHours(); // Hours
  53. var day = date1.getDay(); // Day of the week
  54.  
  55. if (day === 6) // If it's a Saturday
  56. {
  57. if (hours >= 5 && hours <= 9) // Doesn't hurt to add a few more hours of work.
  58. {
  59. block();
  60. }
  61. }
  62.  
  63. else if (hours >= 6 && hours <= 17 && day !== 0) // If hours are 7 AM to 6 PM (inclusive) and not a Sunday
  64. {
  65. block();
  66. }