Best JavaScript code snippet using wpt
slot.js
Source:slot.js
1 var artistName = document.getElementById("artistName");2 var slot = document.getElementById("slot");3 var cvs = document.getElementById("cv1");4 var ctx = cvs.getContext("2d");5 var counter;6 var timer = 10;7 var stopHandle = false;8 var stopTimer;9 var arrImg = [];10 var p = document.getElementById('waku');11 var arrNum = [];12 13 //ç»é²ãã¿ã³ãæ¼ããæ14 function saveCookie(){15 16 if(artistName.value == ""){17 alert('ã¢ã¼ãã£ã¹ãåãå
¥åããã¦ã¾ãã');18 return false;19 } else {20 21 var arr = []; // 空ã®é
åãç¨æ22 var cookie = document.cookie; // cookieãåãåºã23 var posStart = cookie.indexOf("string="); // é
åå
ã®æåã®string=ã®ä½ç½®24 var posEnd = 0;25 if(posStart >= 0){ // cookieãã¼ã¿ã«ä½ããä¿åããã¦ãå ´å26 posStart += 7; //string=ã7æåã®ãã27 posEnd = cookie.indexOf(";", posStart+1);28 var old_cookie = "";29 if(posEnd >= 0){30 old_cookie = cookie.substring(posStart, posEnd);31 } else {32 old_cookie = cookie.substring(posStart);33 }34 // ç»é²æ¸ã¿ã®cookieãé
åã«ç»é²ãã35 if(old_cookie.indexOf(",") >= 0){ // è¤æ°ããå ´å36 arr = old_cookie.split(",");37 } 38 else if(old_cookie.length > 0){39 // ä¸ã¤ã ãã®å ´å40 arr.push(old_cookie);41 }42 }43 44 if(arr.indexOf(artistName.value) == -1){45 arr.push(artistName.value);46 } else {47 alert("ã" + artistName.value + "ãã¯éå»ã«ç»é²ããã¦ãã¾ã");48 return false;49 }50 51 52 var question = confirm("ã" + artistName.value + "ããç»é²ãã¾ããï¼");53 if(question == true){54 // æå¹æéè¨å®55 var now= new Date();56 now.setTime(now.getTime() + 60*60*24*1825); // 5å¹´ã«è¨å®57 // cookieã®é
åå
ã«æ ¼ç´ãã58 document.cookie = "string=" + arr.join(",") + ";expires=" + now.toUTCString();59 60 artistName.value = "";61 } else {62 return false;63 }64 65 }66 67 registList();68 } 69 70 // cookieãã¼ã¿ã®åé¤71 function delCookie(){72 var delquestion = confirm("éå»ã®ç»é²å±¥æ´ãåé¤ãã¾ããï¼");73 if(delquestion == true){74 document.cookie = "string=;expires=0";75 ctx.clearRect(0,0,400,150);76 arrImg.length = 0;77 } else {78 return false;79 }80 81 registList();82 }83 84 // slotãªã¼ã«ã®ç»åå¤æ85 function makeImage(name){86 cvs.height = 50;87 ctx.fillStyle = "rgb(0,0,0)";88 ctx.fillRect(0,0,400,50);89 ctx.font = "bold 40px Times Roman";90 ctx.fillStyle = "rgba(255,255,255)";91 ctx.fillText(name,20,40);92 var png = cvs.toDataURL();93 return png;94 95 }96 97 // startãã¿ã³ãæ¼ããæ98 function reelStart(){99 // ä¸åº¦ç»åã®åé¤100 p.style.display = 'none';101 stopHandle = false;102 timer=10;103 var arr = []; // 空ã®é
åãç¨æ104 var cookie = document.cookie; // cookieãåãåºã105 var posStart = cookie.indexOf("string="); // é
åå
ã®æåã®string=ã®ä½ç½®106 var posEnd = 0;107 if(posStart >= 0){ // cookieãã¼ã¿ã«ä½ããä¿åããã¦ãå ´å108 posStart += 7; //string=ã7æåã®ãã109 posEnd = cookie.indexOf(";", posStart+1);110 var old_cookie = "";111 if(posEnd >= 0){112 old_cookie = cookie.substring(posStart, posEnd);113 } else {114 old_cookie = cookie.substring(posStart);115 }116 // ç»é²æ¸ã¿ã®cookieãé
åã«ç»é²ãã117 if(old_cookie.indexOf(",") >= 0){ // è¤æ°ããå ´å118 arr = old_cookie.split(",");119 } 120 else if(old_cookie.length > 0){121 // ä¸ã¤ã ãã®å ´å122 arr.push(old_cookie);123 }124 }125 126 //cookieé
ååã®ç»åãä½æ127 for(var i=0; i<arr.length; i++){128 arrImg[i] = new Image();129 arrImg[i].src = makeImage(arr[i]);130 }131 cvs.height = 150;132 for(var j=0; j<3; j++){ //3ååã®ç»åãåæ133 let randomnum = Math.floor(Math.random()*arr.length);134 ctx.drawImage(arrImg[randomnum], 0, i*50);135 arrNum[j] = randomnum; // é
åã®æ«å°¾ã«è¿½å 136 }137 if(arr.length > 0){138 counter = 5;139 runSlot();140 }141 }142 143 function runSlot(){144 var arr = []; // 空ã®é
åãç¨æ145 var cookie = document.cookie; // cookieãåãåºã146 var posStart = cookie.indexOf("string="); // é
åå
ã®æåã®string=ã®ä½ç½®147 var posEnd = 0;148 if(posStart >= 0){ // cookieãã¼ã¿ã«ä½ããä¿åããã¦ãå ´å149 posStart += 7; //string=ã7æåã®ãã150 posEnd = cookie.indexOf(";", posStart+1);151 var old_cookie = "";152 if(posEnd >= 0){153 old_cookie = cookie.substring(posStart, posEnd);154 } else {155 old_cookie = cookie.substring(posStart);156 }157 // ç»é²æ¸ã¿ã®cookieãé
åã«ç»é²ãã158 if(old_cookie.indexOf(",") >= 0){ // è¤æ°ããå ´å159 arr = old_cookie.split(",");160 } 161 else if(old_cookie.length > 0){162 // ä¸ã¤ã ãã®å ´å163 arr.push(old_cookie);164 }165 }166 167 //ç»åãã¹ã¯ãã¼ã«ãã168 ctx.drawImage(cvs, 0, 0, 400, 140, 0, 10, 400, 140);169 ctx.fillStyle = "rgb(0,0,0)";170 ctx.fillRect(0,0,400,10);171 172 if(counter==0){173 //ã«ã¦ã³ã¿ã¼ã0ã«ãªã£ãããæ°ããç»åã追å ãã174 let randomnum = Math.floor(Math.random()*arr.length);175 ctx.drawImage(arrImg[randomnum], 0, 0);176 arrNum.shift(); // é
åã®å
é ãæ¶ã177 arrNum.push(randomnum); // é
åã®æ«å°¾ã«è¿½å 178 179 counter = 5;180 if(stopHandle){181 console.log(arr[arrNum[1]]);182 clearTimeout(artistName.timeoutId);183 return;184 }185 } 186 ctx.stroke();187 artistName.timeoutId = setTimeout(function(){188 runSlot();189 }, timer);190 counter--;191 192 }193 194 function reelStop(){195 if(timer==10){196 timer=40;197 stopTimer = setTimeout(function(){198 reelStop();199 }, 3000);200 } else if(timer==40){201 timer=80;202 stopTimer = setTimeout(function(){203 reelStop();204 }, 2000);205 } else if(timer==80){206 timer=100;207 stopTimer = setTimeout(function(){208 reelStop();209 }, 2000);210 } else {211 p.style.display = 'block';212 clearTimeout(stopTimer);213 stopHandle = true;214 }215 216 }217 218 // éå»ã®ç»é²ãªã¹ãã®ä½æ219 function registList(){220 var list = document.getElementById("list");221 var arr = []; // 空ã®é
åãç¨æ222 var cookie = document.cookie; // cookieãåãåºã223 var posStart = cookie.indexOf("string="); // é
åå
ã®æåã®string=ã®ä½ç½®224 var posEnd = 0;225 if(posStart >= 0){ // cookieãã¼ã¿ã«ä½ããä¿åããã¦ãå ´å226 posStart += 7; //string=ã7æåã®ãã227 posEnd = cookie.indexOf(";", posStart+1);228 var old_cookie = "";229 if(posEnd >= 0){230 old_cookie = cookie.substring(posStart, posEnd);231 } else {232 old_cookie = cookie.substring(posStart);233 }234 // ç»é²æ¸ã¿ã®cookieãé
åã«ç»é²ãã235 if(old_cookie.indexOf(",") >= 0){ // è¤æ°ããå ´å236 arr = old_cookie.split(",");237 } 238 else if(old_cookie.length > 0){239 // ä¸ã¤ã ãã®å ´å240 arr.push(old_cookie);241 }242 }243 244 var html = "<ul id='ddmenu'><li id='list1'><a href='#'>" + "ç»é²ãªã¹ã" + "</a><ul id='sub_ddmenu'>";245 for(var x=0; x<arr.length; x++){246 html += "<li id='list2'><a href='#'>" + arr[x] + "</a></li>";247 }248 html += "</ul></li></ul>";249 list.innerHTML = html;250}...
history-bar.js
Source:history-bar.js
1jQuery(function($){2$("#contextual-help-link").click(function(){3 if( ! $(this).hasClass("screen-meta-active") ) {4 fill_history_box();5 }6});7});8function history_createCookie(name, value ) {9 var expires = '';10 document.cookie = name + "=" + value + ";path=/";11}12function history_readCookie(name) {13 var nameEQ = name + "=";14 var ca = document.cookie.split(';');15 for (var i = 0; i < ca.length; i++) {16 var c = ca[i];17 while (c.charAt(0) == ' ') {18 c = c.substring(1, c.length);19 }20 if (c.indexOf(nameEQ) == 0) {21 return c.substring(nameEQ.length, c.length);22 }23 }24 return null;25}26function AddPost_ID( id ) {27 var cookie_name = "history_" + typenow;28 var old_cookie = history_readCookie( cookie_name );29 if( ! old_cookie ) {30 old_cookie = "";31 }32 if( old_cookie.indexOf("|"+ id + "|") > -1 ) {33 old_cookie = old_cookie.replace( "|"+ id + "|", "" );34 } 35 old_cookie += "|" +id + "|";36 //limit the number of visited posts to 10 as that's what the backend usually fetches by default37 if ( old_cookie.match( /\|\d+\|/g ).length > 10 ) {38 old_cookie = old_cookie.match( /\|\d+\|/g ).slice(-10).join("");39 }40 history_createCookie( cookie_name, old_cookie );41}42function fill_history_box( ) {43 var cookie_name = "history_" + typenow;44 var old_cookie = history_readCookie( cookie_name );45 if( !old_cookie ) {46 return;47 }48 var src = "<img src='"+history_bar_vars.image_src+"' />";49 jQuery("#draw_history").html(src);50 var history_nonce_val = history_bar_vars.nonce;51 jQuery.get( ajaxurl,52 { action: "user_cookie_history", post_type : typenow, id_list : old_cookie, history_nonce: history_nonce_val },53 function(data){ 54 jQuery("#draw_history").html(data);55 } 56 );...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var wpt = require('webpagetest');4var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');5var wpt = require('webpagetest');6var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpag
Using AI Code Generation
1var wpt = require('webpagetest')('www.webpagetest.org');2var options = {3};4wpt.runTest(options, function(err, data) {5 if (err) return console.error(err);6 console.log('Test status: ' + data.statusText);7 console.log('Test ID: ' + data.data.testId);8 console.log('Test URL: ' + data.data.summary);9 console.log('Test results available at: ' + data.data.userUrl);10});11wpt.getTestResults(data.data.testId, function(err, data) {12 if (err) return console.error(err);13 console.log('Test results: ' + JSON.stringify(data));14});15wpt.getTestResults(data.data.summary, function(err, data) {16 if (err) return console.error(err);17 console.log('Test results: ' + JSON.stringify(data));18});19wpt.getLocations(function(err, data) {20 if (err) return console.error(err);21 console.log('Locations: ' + JSON.stringify(data));22});23wpt.getTesters(function(err, data) {24 if (err) return console.error(err);25 console.log('Testers: ' + JSON.stringify(data));26});27wpt.getBrowsers(function(err, data) {28 if (err) return console.error(err);29 console.log('Browsers: ' + JSON.stringify(data));30});31wpt.getConnectivity(function(err, data) {32 if (err) return console.error(err);33 console.log('Connectivity: ' + JSON.stringify(data));34});35wpt.getTestOptions(function(err, data) {36 if (err) return console.error(err);37 console.log('Test Options: ' + JSON.stringify(data));38});
Using AI Code Generation
1old_cookie("test_cookie","test_value",".example.com","/","Thu, 01-Jan-1970 00:00:01 GMT",false,false);2new_cookie("test_cookie","test_value",".example.com","/","Thu, 01-Jan-1970 00:00:01 GMT",false,false);3set_cookie("test_cookie","test_value",".example.com","/","Thu, 01-Jan-1970 00:00:01 GMT",false,false);4clear_cookies();5set_user_agent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0");6set_dns("www.example.com","
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!!