How to use old_cookie method in wpt

Best JavaScript code snippet using wpt

slot.js

Source:slot.js Github

copy

Full Screen

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}...

Full Screen

Full Screen

history-bar.js

Source:history-bar.js Github

copy

Full Screen

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 );...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

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});

Full Screen

Using AI Code Generation

copy

Full Screen

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","

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest-api');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1c6a8f0f8f9d9d6e5d6c5f6b8c6d6f6');3var options = {4 videoParams: {5 videoParams: {6 }7 }8};9wpt.runTest(testUrl, options, function(err, data) {10 if (err) {

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful