File tree Expand file tree Collapse file tree 5 files changed +107
-0
lines changed
Expand file tree Collapse file tree 5 files changed +107
-0
lines changed Original file line number Diff line number Diff line change 1+ chrome . action . onClicked . addListener ( ( tab ) => {
2+ chrome . tabs . create ( { url : chrome . runtime . getURL ( "popup.html" ) } ) ;
3+ } ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "manifest_version" : 3 ,
3+ "name" : " Screen Recorder Extension" ,
4+ "version" : " 1.0" ,
5+ "description" : " Расширение для записи экрана" ,
6+ "permissions" : [
7+ " tabs" ,
8+ " activeTab"
9+ ],
10+ "action" : {
11+ "default_popup" : " popup.html" ,
12+ "default_icon" : {
13+ "16" : " icon.png" ,
14+ "48" : " icon.png" ,
15+ "128" : " icon.png"
16+ }
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="ru ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Запись экрана</ title >
7+ < style >
8+ body {
9+ font-family : Arial, sans-serif;
10+ text-align : center;
11+ padding : 20px ;
12+ min-width : 600px ;
13+ min-height : 500px ;
14+ }
15+ button , input {
16+ padding : 10px ;
17+ font-size : 16px ;
18+ margin : 10px ;
19+ }
20+ # stop-btn { display : none; } /* Скрываем кнопку остановки по умолчанию */
21+ </ style >
22+ </ head >
23+ < body >
24+ < h2 > Запись экрана</ h2 >
25+
26+ < label for ="username "> Имя пользователя:</ label >
27+ < input type ="text " id ="username " placeholder ="Введите имя " required >
28+
29+ < button id ="start-btn "> Начать запись</ button >
30+ < button id ="stop-btn "> Остановить запись</ button >
31+
32+ < script src ="popup.js "> </ script >
33+ </ body >
34+ </ html >
Original file line number Diff line number Diff line change 1+ const startBtn = document . getElementById ( "start-btn" ) ;
2+ const stopBtn = document . getElementById ( "stop-btn" ) ;
3+ const usernameInput = document . getElementById ( "username" ) ;
4+
5+ let mediaRecorder ;
6+ let chunks = [ ] ;
7+
8+ startBtn . addEventListener ( "click" , async ( ) => {
9+ const username = usernameInput . value . trim ( ) ;
10+
11+ if ( ! username ) {
12+ alert ( "Введите имя пользователя!" ) ;
13+ return ;
14+ }
15+
16+ try {
17+ const stream = await navigator . mediaDevices . getDisplayMedia ( { video : true } ) ;
18+
19+ mediaRecorder = new MediaRecorder ( stream ) ;
20+ chunks = [ ] ;
21+
22+ mediaRecorder . ondataavailable = event => chunks . push ( event . data ) ;
23+ mediaRecorder . onstop = ( ) => {
24+ const blob = new Blob ( chunks , { type : 'video/webm' } ) ;
25+ const url = URL . createObjectURL ( blob ) ;
26+
27+ const a = document . createElement ( 'a' ) ;
28+ a . href = url ;
29+ a . download = `${ username } _recording.webm` ; // Имя пользователя в названии файла
30+ a . click ( ) ;
31+
32+ stopBtn . style . display = "none" ;
33+ startBtn . style . display = "inline-block" ;
34+ } ;
35+
36+ mediaRecorder . start ( ) ;
37+ console . log ( "Запись началась" ) ;
38+
39+ startBtn . style . display = "none" ;
40+ stopBtn . style . display = "inline-block" ;
41+
42+ } catch ( error ) {
43+ console . error ( "Ошибка при получении доступа к экрану:" , error ) ;
44+ }
45+ } ) ;
46+
47+ stopBtn . addEventListener ( "click" , ( ) => {
48+ if ( mediaRecorder && mediaRecorder . state !== "inactive" ) {
49+ mediaRecorder . stop ( ) ;
50+ console . log ( "Запись остановлена" ) ;
51+ }
52+ } ) ;
You can’t perform that action at this time.
0 commit comments