Best JavaScript code snippet using wpt
movie.ts
Source:movie.ts
1import guards from '../common/typeguards'2export const movieJS = (root: HTMLDocument): void => {3 // /^video\/.*/ breaks syntax highlight4 const reVideoType = new RegExp('^video/.*')5 const reAudioType = new RegExp('^audio/.*')6 const reImageType = new RegExp('^image/.*')7 const reader = new FileReader()8 const screen = root.getElementsByClassName('CommentScreen')[0]9 const layersColl = root.getElementsByClassName('hc-layer')10 const layer = layersColl[layersColl.length - 1]11 if (!guards.isHTMLElem(screen)) return console.log('No screen found')12 if (!guards.isHTMLElem(layer)) return console.log('No layer found')13 const loadVideo = (file: File): () => void => {14 return () => {15 const blobUrl = window.URL.createObjectURL(file)16 const type = appendVideo.tagName.toLowerCase()17 appendVideo.setAttribute('src', blobUrl)18 appendVideo.className = `drop_${type} drop_playing`19 appendVideo.style.display = 'block'20 if (guards.isVideo(appendVideo)) appendVideo.play()21 }22 }23 const loadAudio = (file: File): () => void => {24 return () => {25 const blobUrl = window.URL.createObjectURL(file)26 const type = appendVideo.tagName.toLowerCase()27 appendAudio.setAttribute('src', blobUrl)28 appendAudio.className = `drop_${type} drop_playing`29 appendAudio.style.display = 'block'30 if (guards.isAudio(appendAudio)) appendAudio.play()31 }32 }33 // image34 const loadImg = (file: File): () => void => {35 return () => {36 const blobUrl = window.URL.createObjectURL(file)37 const img = `url(${blobUrl})`38 boxNode.style.backgroundImage = img39 }40 }41 const handleDragOver = (event: DragEvent): boolean => {42 event.stopPropagation()43 event.preventDefault()44 event.dataTransfer.dropEffect = 'copy'45 return false46 }47 const handleDrop = (event: DragEvent): void => {48 event.stopPropagation()49 event.preventDefault()50 const files = event.dataTransfer.files51 const file = files[0]52 console.log('load')53 switch (true) {54 case reVideoType.test(file.type):55 if (!guards.isVideo(videoElement)) return56 if (videoElement.canPlayType(file.type) !== '') {57 console.log('load video')58 reader.onload = loadVideo(file)59 // Don't use image to background.60 boxNode.style.backgroundImage = 'none'61 reader.readAsDataURL(file)62 }63 break64 case reAudioType.test(file.type):65 if (!guards.isAudio(audioElement)) return66 if (audioElement.canPlayType(file.type) !== '') {67 console.log('load audio')68 reader.onload = loadAudio(file)69 reader.readAsDataURL(file)70 }71 break72 case reImageType.test(file.type):73 console.log('load img')74 reader.onload = loadImg(file)75 reader.readAsDataURL(file)76 break77 }78 }79 // stop, delete media element if exists80 const haltMedia = (): void => {81 const media = root.getElementsByClassName('drop_playing')[0]82 if (!guards.isAudio(media) && !guards.isVideo(media)) return console.log('No media found.')83 console.log('rm media')84 media.removeAttribute('src')85 media.load()86 media.className = 'drop_' + media.tagName.toLowerCase()87 media.style.display = 'none'88 }89 // media handling constructor90 const mediaBox = (): HTMLDivElement => {91 const divElem = root.createElement('div')92 divElem.style.position = 'relative'93 divElem.style.display = 'block'94 divElem.style.height = '100%'95 divElem.style.width = '100%'96 divElem.style.zIndex = '-1'97 divElem.setAttribute('class', 'drop_media_box')98 divElem.style.backgroundSize = 'cover'99 divElem.style.backgroundPosition = 'center center'100 return divElem101 }102 const mediaToAppend = (type: string): HTMLElement => {103 const mediaElem = root.createElement(type)104 mediaElem.style.position = 'relative'105 mediaElem.style.display = 'none'106 mediaElem.style.height = '100%'107 mediaElem.style.width = '100%'108 mediaElem.style.zIndex = '-1'109 if (guards.isAudio(mediaElem) || guards.isVideo(mediaElem)) mediaElem.loop = true110 return mediaElem111 }112 const createDropArea = (): void => {113 const dropArea = root.getElementsByClassName('CommentPanel is-active')[0]114 if (!guards.isHTMLElem(dropArea)) return console.log('No dropArea found')115 dropArea.setAttribute('draggable', 'true')116 dropArea.addEventListener('dragover', handleDragOver, false)117 dropArea.addEventListener('drop', haltMedia, false)118 dropArea.addEventListener('drop', handleDrop, false)119 }120 const appendBox = mediaBox()121 const boxNode = screen.insertBefore(appendBox, layer)122 const appendVideo = mediaToAppend('video')123 appendVideo.className = 'drop_video'124 const videoElement = boxNode.appendChild(appendVideo)125 const appendAudio = mediaToAppend('audio')126 appendAudio.className = 'drop_audio'127 const audioElement = boxNode.appendChild(appendAudio)128 const appendColor = mediaToAppend('div')129 appendColor.className = 'bg_color'130 appendColor.style.zIndex = '-3'131 appendColor.style.backgroundColor = 'transparent'132 appendColor.style.display = 'block'133 appendColor.style.position = 'absolute'134 appendColor.style.top = '0.0em'135 appendColor.style.left = '0.0em'136 screen.insertBefore(appendColor, layer)137 createDropArea()...
sw.https.window.js
Source:sw.https.window.js
...34 const w = iframe.contentWindow;35 // Trigger a cross-origin range request using media36 const url = new URL('long-wav.py?action=range-header-filter-test', w.location);37 url.hostname = REMOTE_HOST;38 appendAudio(w.document, url);39 // See rangeHeaderFilterTest in resources/range-sw.js40 await fetch_tests_from_worker(reg.active);41}, `Defer range header filter tests to service worker`);42promise_test(async t => {43 const scope = BASE_SCOPE + Math.random();44 const reg = await setupRegistration(t, scope);45 const iframe = await with_iframe(scope);46 const w = iframe.contentWindow;47 // Trigger a cross-origin range request using media48 const url = new URL('long-wav.py', w.location);49 url.searchParams.set('action', 'range-header-passthrough-test');50 url.searchParams.set('range-received-key', token());51 url.hostname = REMOTE_HOST;52 appendAudio(w.document, url);53 // See rangeHeaderPassthroughTest in resources/range-sw.js54 await fetch_tests_from_worker(reg.active);55}, `Defer range header passthrough tests to service worker`);56promise_test(async t => {57 const scope = BASE_SCOPE + Math.random();58 await setupRegistration(t, scope);59 const iframe = await with_iframe(scope);60 const w = iframe.contentWindow;61 const id = Math.random() + '';62 const storedRangeResponse = awaitMessage(w.navigator.serviceWorker, id);63 // Trigger a cross-origin range request using media64 const url = new URL('partial-script.py', w.location);65 url.searchParams.set('require-range', '1');66 url.searchParams.set('action', 'store-ranged-response');67 url.searchParams.set('id', id);68 url.hostname = REMOTE_HOST;69 appendAudio(w.document, url);70 await storedRangeResponse;71 // Fetching should reject72 const fetchPromise = w.fetch('?action=use-stored-ranged-response', { mode: 'no-cors' });73 promise_rejects(t, new TypeError(), fetchPromise);74 // Script loading should error too75 const loadScriptPromise = loadScript('?action=use-stored-ranged-response', { doc: w.document });76 promise_rejects(t, new Error(), loadScriptPromise);77 await loadScriptPromise.catch(() => {});78 assert_false(!!w.scriptExecuted, `Partial response shouldn't be executed`);79}, `Ranged response not allowed following no-cors ranged request`);80promise_test(async t => {81 const scope = BASE_SCOPE + Math.random();82 await setupRegistration(t, scope);83 const iframe = await with_iframe(scope);84 const w = iframe.contentWindow;85 const id = Math.random() + '';86 const storedRangeResponse = awaitMessage(w.navigator.serviceWorker, id);87 // Trigger a range request using media88 const url = new URL('partial-script.py', w.location);89 url.searchParams.set('require-range', '1');90 url.searchParams.set('action', 'store-ranged-response');91 url.searchParams.set('id', id);92 appendAudio(w.document, url);93 await storedRangeResponse;94 // This should not throw95 await w.fetch('?action=use-stored-ranged-response');96 // This shouldn't throw either97 await loadScript('?action=use-stored-ranged-response', { doc: w.document });98 assert_true(w.scriptExecuted, `Partial response should be executed`);99}, `Non-opaque ranged response executed`);100promise_test(async t => {101 const scope = BASE_SCOPE + Math.random();102 await setupRegistration(t, scope);103 const iframe = await with_iframe(scope);104 const w = iframe.contentWindow;105 const fetchId = Math.random() + '';106 const fetchBroadcast = awaitMessage(w.navigator.serviceWorker, fetchId);107 const audioId = Math.random() + '';108 const audioBroadcast = awaitMessage(w.navigator.serviceWorker, audioId);109 const url = new URL('long-wav.py', w.location);110 url.searchParams.set('action', 'broadcast-accept-encoding');111 url.searchParams.set('id', fetchId);112 await w.fetch(url, {113 headers: { Range: 'bytes=0-10' }114 });115 assert_equals((await fetchBroadcast).acceptEncoding, null, "Accept-Encoding should not be set for fetch");116 url.searchParams.set('id', audioId);117 appendAudio(w.document, url);118 assert_equals((await audioBroadcast).acceptEncoding, null, "Accept-Encoding should not be set for media");...
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var request = require('request');4var util = require('util');5var exec = require('child_process').exec;6var wiki = wptools.page('Cats').get(function(err, resp) {7 if (err) {8 console.log(err);9 }10 else {11 var audio = resp.data.image[0];12 var url = audio.url;13 var file = fs.createWriteStream('test.mp3');14 var req = request.get(url);15 req.on('response', function (res) {16 res.pipe(file);17 });18 req.on('error', function (err) {19 console.log(err);20 });21 req.on('end', function () {22 console.log('done');23 });24 }25});26var wptools = require('wptools');27var fs = require('fs');28var request = require('request');29var util = require('util');30var exec = require('child_process').exec;31var wiki = wptools.page('Cats').get(function(err, resp) {32 if (err) {33 console.log(err);34 }35 else {36 var audio = resp.data.image[0];37 var url = audio.url;38 var file = fs.createWriteStream('test.mp3');39 var req = request.get(url);40 req.on('response', function (res) {41 res.pipe(file);42 });43 req.on('error', function (err) {44 console.log(err);45 });46 req.on('end', function () {47 console.log('done');48 });49 }50});51var wptools = require('wptools');52var fs = require('fs');53var request = require('request');54var util = require('util');55var exec = require('child_process').exec;56var wiki = wptools.page('Cats').get(function(err, resp) {57 if (err) {58 console.log(err);59 }60 else {61 var audio = resp.data.image[0];62 var url = audio.url;63 var file = fs.createWriteStream('test.mp3');64 var req = request.get(url);65 req.on('response', function
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var page = wptools.page('Albert_Einstein');4page.appendAudio('test.mp3', function(err, resp) {5 if (err) {6 console.log(err);7 } else {8 console.log(resp);9 }10});11var wptools = require('wptools');12var fs = require('fs');13var page = wptools.page('Albert_Einstein');14page.appendVideo('test.mp4', function(err, resp) {15 if (err) {16 console.log(err);17 } else {18 console.log(resp);19 }20});21var wptools = require('wptools');22var fs = require('fs');23var page = wptools.page('Albert_Einstein');24page.appendVideo('test.mp4', function(err, resp) {25 if (err) {26 console.log(err);27 } else {28 console.log(resp);29 }30});31var wptools = require('wptools');32var fs = require('fs');33var page = wptools.page('Albert_Einstein');34page.appendVideo('test.mp4', function(err, resp) {35 if (err) {36 console.log(err);37 } else {38 console.log(resp);39 }40});41var wptools = require('wptools');42var fs = require('fs');43var page = wptools.page('Albert_Einstein');44page.appendVideo('test.mp4', function(err, resp) {45 if (err) {46 console.log(err);47 } else {48 console.log(resp);49 }50});51var wptools = require('wptools');52var fs = require('fs');53var page = wptools.page('Albert_Einstein');54page.appendVideo('test.mp4', function(err, resp) {55 if (err) {56 console.log(err);57 } else {58 console.log(resp);59 }60});
Using AI Code Generation
1var wptool = require('./wptool.js');2var fs = require('fs');3var wp = new wptool();4var mp3 = fs.readFileSync('./test.mp3');5wp.appendAudio('Test', 'Test.mp3', mp3, 'Test', 'Test', 'Test', function(err, data) {6 if(err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12var wptool = require('./wptool.js');13var fs = require('fs');14var wp = new wptool();15var jpg = fs.readFileSync('./test.jpg');16wp.appendImage('Test', 'Test.jpg', jpg, 'Test', 'Test', 'Test', function(err, data) {17 if(err) {18 console.log(err);19 } else {20 console.log(data);21 }22});23var wptool = require('./wptool.js');24var fs = require('fs');25var wp = new wptool();26var mp4 = fs.readFileSync('./test.mp4');27wp.appendVideo('Test', 'Test.mp4', mp4, 'Test', 'Test', 'Test', function(err, data) {28 if(err) {29 console.log(err);30 } else {31 console.log(data);32 }33});34var wptool = require('./wptool.js');
Using AI Code Generation
1var toolbox = require('./wptoolbox.js');2var fs = require('fs');3var audio = fs.readFileSync('./test.mp3');4toolbox.appendAudio(audio, 'test2.mp3', function(err, data){5 if(err) throw err;6 console.log('appended audio');7});8### appendAudioSync(audio, filename, [options])
Using AI Code Generation
1var audio = new wptb_audio();2audio.appendAudio('audio.mp3', 'audio title', 'audio description', 'audio credits');3var audio = new wptb_audio();4audio.appendAudio('audio.mp3', 'audio title', 'audio description', 'audio credits');5var audio = new wptb_audio();6audio.appendAudio('audio.mp3', 'audio title', 'audio description', 'audio credits');7var audio = new wptb_audio();8audio.appendAudio('audio.mp3', 'audio title', 'audio description', 'audio credits');9var audio = new wptb_audio();10audio.appendAudio('audio.mp3', 'audio title', 'audio description', 'audio credits');11var audio = new wptb_audio();12audio.appendAudio('audio.mp3', 'audio title', 'audio description', 'audio credits');13var audio = new wptb_audio();14audio.appendAudio('audio.mp3', 'audio title', 'audio description', 'audio credits');15var audio = new wptb_audio();16audio.appendAudio('audio.mp3', 'audio title', 'audio description', 'audio credits');
Using AI Code Generation
1const audio = new WPTBAudio();2audio.appendAudio(path);3const audio = new WPTBAudio();4audio.appendAudio(path);5audio.playAudio();6const audio = new WPTBAudio();7audio.appendAudio(path);8audio.playAudio();9audio.pauseAudio();10const audio = new WPTBAudio();11audio.appendAudio(path);12audio.playAudio();13audio.stopAudio();14const audio = new WPTBAudio();15audio.appendAudio(path);16audio.playAudio();17audio.muteAudio();18const audio = new WPTBAudio();19audio.appendAudio(path);20audio.playAudio();21audio.muteAudio();22audio.unmuteAudio();23const audio = new WPTBAudio();24audio.appendAudio(path);25audio.playAudio();26audio.changeVolume(0.5);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!