Page Confiscation with Code Entry

Adds a button to turn the page black with a message and code entry for downloading website files.

  1. // ==UserScript==
  2. // @name Page Confiscation with Code Entry
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Adds a button to turn the page black with a message and code entry for downloading website files.
  6. // @match *://*/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. // Function to generate a unique code
  14. function generateCode() {
  15. return Math.random().toString(36).substr(2, 6).toUpperCase(); // Generate a 6-character code
  16. }
  17.  
  18. // Function to start the confiscation process
  19. function startConfiscation() {
  20. // Hide the button and create the black screen with message
  21. document.getElementById('confiscation-button').style.display = 'none';
  22.  
  23. // Generate a unique code
  24. const code = generateCode();
  25.  
  26. document.body.innerHTML = `
  27. <div id="confiscation-screen" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: black; color: green; display: flex; flex-direction: column; justify-content: center; align-items: center; font-family: monospace; text-align: center; z-index: 10000;">
  28. <h1>Your device has been confiscated</h1>
  29. <p>Enter the code to regain access:</p>
  30. <input type="text" id="code-input" placeholder="Enter code" style="font-size: 20px; text-align: center; margin-bottom: 10px; padding: 5px; width: 200px;">
  31. <button id="submit-code" style="padding: 10px 20px; font-size: 16px; cursor: pointer; background-color: #4CAF50; color: white; border: none; border-radius: 5px;">Submit Code</button>
  32. <p id="code-display" style="position: absolute; top: 10px; right: 10px; color: green; font-size: 18px;">Code: ${code}</p>
  33. </div>
  34. `;
  35.  
  36. // Function to handle code submission
  37. function handleCodeSubmission() {
  38. const inputCode = document.getElementById('code-input').value.trim();
  39. if (inputCode === code) {
  40. // Code is correct, prepare to download website data
  41. setTimeout(() => {
  42. const htmlContent = document.documentElement.outerHTML;
  43. const cssContent = Array.from(document.querySelectorAll('style')).map(style => style.innerHTML).join('\n');
  44. const jsContent = Array.from(document.querySelectorAll('script')).map(script => script.innerHTML).join('\n');
  45. const combinedContent = `
  46. <html>
  47. <head>
  48. <title>Saved Page</title>
  49. <style>${cssContent}</style>
  50. </head>
  51. <body>
  52. ${htmlContent}
  53. <script>${jsContent}</script>
  54. </body>
  55. </html>
  56. `;
  57.  
  58. const blob = new Blob([combinedContent], { type: 'text/html' });
  59. const url = URL.createObjectURL(blob);
  60. const a = document.createElement('a');
  61. a.href = url;
  62. a.download = 'saved_page.html';
  63. document.body.appendChild(a);
  64. a.click();
  65. URL.revokeObjectURL(url);
  66. document.body.removeChild(a);
  67. }, 1000); // 1 second delay for download
  68. } else {
  69. alert('Incorrect code. Please try again.');
  70. }
  71. }
  72.  
  73. // Attach event listener to the submit button
  74. document.getElementById('submit-code').addEventListener('click', handleCodeSubmission);
  75. }
  76.  
  77. // Create and display the confiscation button
  78. function createConfiscationButton() {
  79. const button = document.createElement('button');
  80. button.id = 'confiscation-button';
  81. button.textContent = 'Confiscate Device';
  82. button.style.position = 'fixed';
  83. button.style.top = '10px';
  84. button.style.left = '10px';
  85. button.style.padding = '10px 20px';
  86. button.style.fontSize = '16px';
  87. button.style.cursor = 'pointer';
  88. button.style.backgroundColor = '#f44336'; // Red color for high visibility
  89. button.style.color = 'white';
  90. button.style.border = 'none';
  91. button.style.borderRadius = '5px';
  92. button.style.zIndex = '9999';
  93. document.body.appendChild(button);
  94.  
  95. button.addEventListener('click', startConfiscation);
  96. }
  97.  
  98. // Create the button when the page loads
  99. window.addEventListener('load', createConfiscationButton);
  100. })();