Blackout and Open Tab

Turns the page black, opens a new tab with hidden visibility, and makes it visible again after 3 seconds

  1. // ==UserScript==
  2. // @name Blackout and Open Tab
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Turns the page black, opens a new tab with hidden visibility, and makes it visible again after 3 seconds
  6. // @match *://*/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. // Create and style a blackout overlay
  14. const overlay = document.createElement('div');
  15. overlay.style.position = 'fixed';
  16. overlay.style.top = '0';
  17. overlay.style.left = '0';
  18. overlay.style.width = '100%';
  19. overlay.style.height = '100%';
  20. overlay.style.backgroundColor = 'black';
  21. overlay.style.zIndex = '10000';
  22. overlay.style.opacity = '1';
  23. overlay.style.transition = 'opacity 1s';
  24. document.body.appendChild(overlay);
  25.  
  26. // Create a button
  27. const button = document.createElement('button');
  28. button.textContent = 'Click for a Variety of Tampermonkey Scripts';
  29. button.style.position = 'fixed';
  30. button.style.top = '10px';
  31. button.style.left = '10px';
  32. button.style.zIndex = '10001';
  33. document.body.appendChild(button);
  34.  
  35. // Button click handler
  36. button.addEventListener('click', () => {
  37. overlay.style.opacity = '0';
  38.  
  39. // Wait for overlay to disappear
  40. setTimeout(() => {
  41. // Open a new tab
  42. const newTab = window.open('', '_blank');
  43.  
  44. // Hide new tab's visibility by setting styles
  45. if (newTab) {
  46. newTab.document.write('<style>body{display:none;}</style>');
  47. newTab.document.close();
  48.  
  49. // Make the new tab visible again after 3 seconds
  50. setTimeout(() => {
  51. newTab.document.body.style.display = 'block';
  52. }, 3000); // Time to wait before making the tab visible again
  53. }
  54. }, 1000); // Time for the overlay fade out
  55. });
  56. })();