gimmickCellar

screen recorder

Mar 6th, 2026
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. (function() {
  2. let recorder = null;
  3. let chunks = [];
  4. let isRecording = false;
  5. let cropCanvas = document.createElement("canvas");
  6. let cropCtx = cropCanvas.getContext("2d");
  7. let recordRegion = new RegionSelection();
  8.  
  9. // UI Elements
  10. const container = document.createElement("div");
  11. container.style = "position:absolute; top:50px; left:10px; z-index:10000; background:white; padding:10px; border:1px solid black; font-family:Verdana; display:flex; flex-direction:column; gap:5px;";
  12. container.innerHTML = `
  13. <b style="font-size:12px;">OWOT Screen Recorder</b>
  14. <button id="btn-select">1. Select Area</button>
  15. <button id="btn-start" disabled>2. Start Recording</button>
  16. <button id="btn-stop" disabled>3. Stop & Save</button>
  17. <div id="rec-status" style="font-size:10px; color:red; display:none;">● Recording...</div>
  18. `;
  19. document.body.appendChild(container);
  20.  
  21. let bounds = null;
  22.  
  23. // 1. Selection Logic
  24. document.getElementById("btn-select").onclick = () => {
  25. recordRegion.startSelection();
  26. w.doAnnounce("Drag to select the recording area.");
  27. };
  28.  
  29. recordRegion.onselection((coordA, coordB, regWidth, regHeight) => {
  30. // Calculate pixel coordinates from world coordinates
  31. const posA = tileAndCharsToWindowCoords(coordA[0], coordA[1], coordA[2], coordA[3]);
  32. const posB = tileAndCharsToWindowCoords(coordB[0], coordB[1], coordB[2], coordB[3]);
  33.  
  34. // Account for high-DPI displays (zoomRatio)
  35. const ratio = window.devicePixelRatio || 1;
  36.  
  37. const x = posA[0] * ratio;
  38. const y = posA[1] * ratio;
  39. const width = (posB[0] - posA[0] + (cellW / zoomRatio)) * ratio;
  40. const height = (posB[1] - posA[1] + (cellH / zoomRatio)) * ratio;
  41.  
  42. bounds = { x, y, width, height };
  43.  
  44. document.getElementById("btn-start").disabled = false;
  45. w.doAnnounce("Area selected. Ready to record.");
  46. });
  47.  
  48. // 2. Recording Logic
  49. document.getElementById("btn-start").onclick = () => {
  50. if (!bounds) return;
  51.  
  52. // Prepare recording canvas
  53. cropCanvas.width = bounds.width;
  54. cropCanvas.height = bounds.height;
  55.  
  56. chunks = [];
  57. const stream = cropCanvas.captureStream(30); // 30 FPS
  58. recorder = new MediaRecorder(stream, {
  59. mimeType: 'video/webm;codecs=vp9'
  60. });
  61.  
  62. recorder.ondataavailable = (e) => {
  63. if (e.data.size > 0) chunks.push(e.data);
  64. };
  65.  
  66. recorder.onstop = () => {
  67. const blob = new Blob(chunks, { type: 'video/webm' });
  68. const url = URL.createObjectURL(blob);
  69. const a = document.createElement('a');
  70. a.href = url;
  71. a.download = `owot-capture-${Date.now()}.webm`;
  72. a.click();
  73. w.doAnnounce("Recording saved!");
  74. };
  75.  
  76. recorder.start();
  77. isRecording = true;
  78.  
  79. document.getElementById("btn-start").disabled = true;
  80. document.getElementById("btn-stop").disabled = false;
  81. document.getElementById("rec-status").style.display = "block";
  82. };
  83.  
  84. document.getElementById("btn-stop").onclick = () => {
  85. isRecording = false;
  86. recorder.stop();
  87. document.getElementById("btn-stop").disabled = true;
  88. document.getElementById("btn-start").disabled = false;
  89. document.getElementById("rec-status").style.display = "none";
  90. };
  91.  
  92. // 3. Frame Processing Hook
  93. // We hook into OWOT's internal render loop to copy the area to our hidden canvas
  94. w.on("frame", () => {
  95. if (isRecording && bounds) {
  96. // Copy the specific region from the main OWOT canvas to our capture canvas
  97. cropCtx.drawImage(
  98. owot,
  99. bounds.x, bounds.y, bounds.width, bounds.height, // Source
  100. 0, 0, bounds.width, bounds.height // Destination
  101. );
  102. }
  103. });
  104.  
  105. w.doAnnounce("Recorder script loaded.");
  106. })();
Advertisement
Add Comment
Please, Sign In to add comment