Best JavaScript code snippet using wpt
hm_cy.js
Source:hm_cy.js
1//页é¢å°ååç¼2function preUrl(path){3 var fUrl = 'http://localhost:8080/hm_chen/hm_cy/';4 return fUrl + path;5}6/*7* è·åå°åæ ä¸çåæ°8* GetQueryString('åæ°å1')9* GetQueryString('åæ°å2')10*/11function GetQueryString(name){12 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");13 var r = window.location.search.substr(1).match(reg);14 if(r!=null)return unescape(r[2]); return null;15}16//ajax ä¼ åurl17function reqUrl(path){18 var frontUrl = 'http://localhost:8080/hmapi_cheyi/v100/';19 var key = 'cb08bd3a57be55c375040ec59f343e8e';20 var myDate = new Date();21 var regTime = myDate.getMilliseconds() ;22 23 var hash = hex_md5(key+'|'+regTime+'|'+path);24 return frontUrl + path + '?datetime='+regTime+'&sign='+hash;25}26//设置cookie27function setCookie(name,cvalue,exdays){28 var exp = new Date();29 exp.setTime(exp.getTime()+(exdays*24*60*60*1000));30 document.cookie = name + "=" + escape(cvalue) + "; expires=" + exp.toGMTString() + ";path=/";31}32//è·åcookie33function getCookie(name){34 var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));35 if(arr != null) return unescape(arr[2]); return null;36}37//ä¿åæ°¸ä¹
æ°æ®38function setInfo(k,v){39 window.localStorage.setItem(k,v);40}41//读åæ°¸ä¹
æ°æ®42function getInfo(k){43 return window.localStorage.getItem(k);44}45//å é¤æ°¸ä¹
æ°æ®46function removeInfo(k){47 window.localStorage.removeItem(k);48}49//å
¨é¨å é¤æ°¸ä¹
æ°æ®50function removeAllInfo(){51 window.localStorage.clear();52}53/** pickeråºé¨æ»å¨éæ©æ°æ®ï¼ä¸åï¼ä¸¤åï¼54* arr: æ°æ®55* nameEl: ç¹å»å¯¹è±¡56* valEl: ä¿åæéå¼57* oper: åºå value å innerHTMl58* title: 顶é¨æ é¢59*/60function pickerShow(arr, nameEl, valEl, oper, title){61 var picker = new Picker({62 data: arr,63 selectedIndex: [0,1],64 title: title65 });66 picker.on('picker.select', function (selectedVal, selectedIndex) {67 valEl.innerHTML = '';68 for(var i=0; i<arr.length; i++){69 if(oper === 0){70 valEl.value += arr[i][selectedIndex[i]].text;71 }else{72 valEl.innerHTML += arr[i][selectedIndex[i]].text;73 } 74 }75 });76 nameEl.addEventListener('click', function () {77 picker.show();78 console.log('ok');79 });80}81// é®ç½©82function mask(text){83 $('.layer').remove();84 var content = '<div class="layer"> '+ text +'</div>'85 $('body').append(content);86 var w = $('.layer').width() + 40;87 var win = $(window).width();88 $('.layer').css('left', (win-w)/2 + 'px');89 $('.layer').fadeIn();90 setTimeout(function(){91 $('.layer').fadeOut();92 $('.layer').remove();93 }, 2000);94}95//åæ¢åå¸96//å表ä¸æ¯ä¸ªåæ¯ç¸å¯¹äºé¡¶é¨çè·ç¦»97function alphaArr(){98 var arr=[];99 $('.am-popup-inner').find('p').each(function(){100 arr.push($(this).offset().top-49);101 });102 return arr;103}104//ç¹å»å³ä¾§åæ¯ç§»å¨å°ç¸åºä½ç½®105function alphaList(){106 console.log('ok');107 $('.alpha-list').on('click','a',function(){108 var data = ($(this).attr('data'));109 var groupElement = $('.index-'+data);110 console.log(groupElement);111 if (groupElement.length>0) {112 $('.am-popup-inner').scrollTop(0);113 var oheight = groupElement.offset().top-49;114 var innerHeight = $('.am-popup-inner').scrollTop();115 console.log(innerHeight);116 console.log(oheight);117 var height = oheight - innerHeight;//æ»å¨çè·ç¦» = åå§åæ¶å°é¡¶é¨è·ç¦»åå»å½åå°é¡¶é¨çè·ç¦»118 $('.am-popup-inner').stop().animate({scrollTop: '+=' + height + 'px'});119 }else{120 return;121 }122 });123}124//æä½ååæ°é125function countOper(type,obj){ 126 switch(type){127 case '-':128 var num = parseInt($(obj).next().html());129 if(num > 1){130 num--;131 }132 $(obj).next().html(num);133 break;134 case '+':135 var num = parseInt($(obj).prev().html());136 num++;137 $(obj).prev().html(num);138 break;139 default:140 break;141 }142}143// @param {string} img å¾ççbase64144// @param {int} dir exifè·åçæ¹åä¿¡æ¯145// @param {function} next åè°æ¹æ³ï¼è¿åæ ¡æ£æ¹ååçbase64146function getImgData(img,dir,next){147 var image=new Image();148 image.onload=function(){149 var degree=0,drawWidth,drawHeight,width,height;150 drawWidth=this.naturalWidth;151 drawHeight=this.naturalHeight;152 //以ä¸æ¹åä¸ä¸å¾ç大å°153 var maxSide = Math.max(drawWidth, drawHeight);154 if (maxSide > 1024) {155 var minSide = Math.min(drawWidth, drawHeight);156 minSide = minSide / maxSide * 1024;157 maxSide = 1024;158 if (drawWidth > drawHeight) {159 drawWidth = maxSide;160 drawHeight = minSide;161 } else {162 drawWidth = minSide;163 drawHeight = maxSide;164 }165 }166 var canvas=document.createElement('canvas');167 canvas.width=width=drawWidth;168 canvas.height=height=drawHeight;169 var context=canvas.getContext('2d');170 //å¤æå¾çæ¹åï¼éç½®canvas大å°ï¼ç¡®å®æ转è§åº¦ï¼iphoneé»è®¤çæ¯homeé®å¨å³æ¹ç横å±æææ¹å¼171 switch(dir){172 //iphone横å±ææï¼æ¤æ¶homeé®å¨å·¦ä¾§173 case 3:174 degree=180;175 drawWidth=-width;176 drawHeight=-height;177 break;178 //iphoneç«å±ææï¼æ¤æ¶homeé®å¨ä¸æ¹(æ£å¸¸æ¿ææºçæ¹å)179 case 6:180 canvas.width=height;181 canvas.height=width;182 degree=90;183 drawWidth=width;184 drawHeight=-height;185 break;186 //iphoneç«å±ææï¼æ¤æ¶homeé®å¨ä¸æ¹187 case 8:188 canvas.width=height;189 canvas.height=width;190 degree=270;191 drawWidth=-width;192 drawHeight=height;193 break;194 }195 //使ç¨canvasæè½¬æ ¡æ£196 context.rotate(degree*Math.PI/180);197 context.drawImage(this,0,0,drawWidth,drawHeight);198 //è¿åæ ¡æ£å¾ç199 next(canvas.toDataURL("image/jpeg",.8));200 }201 image.src=img;...
getImgDate.js
Source:getImgDate.js
1// @param {string} img å¾ççbase642// @param {int} dir exifè·åçæ¹åä¿¡æ¯3// @param {function} next åè°æ¹æ³ï¼è¿åæ ¡æ£æ¹ååçbase644function getImgData(img,dir,next){5 var image=new Image();6 image.onload=function(){7 var degree=0,drawWidth,drawHeight,width,height;8 drawWidth=this.naturalWidth;9 drawHeight=this.naturalHeight;10 //以ä¸æ¹åä¸ä¸å¾ç大å°11 var maxSide = Math.max(drawWidth, drawHeight);12 if (maxSide > 1024) {13 var minSide = Math.min(drawWidth, drawHeight);14 minSide = minSide / maxSide * 1024;15 maxSide = 1024;16 if (drawWidth > drawHeight) {17 drawWidth = maxSide;18 drawHeight = minSide;19 } else {20 drawWidth = minSide;21 drawHeight = maxSide;22 }23 }24 var canvas=document.createElement('canvas');25 canvas.width=width=drawWidth;26 canvas.height=height=drawHeight; 27 var context=canvas.getContext('2d');28 //å¤æå¾çæ¹åï¼éç½®canvas大å°ï¼ç¡®å®æ转è§åº¦ï¼iphoneé»è®¤çæ¯homeé®å¨å³æ¹ç横å±æææ¹å¼29 switch(dir){30 //iphone横å±ææï¼æ¤æ¶homeé®å¨å·¦ä¾§31 case 3:32 degree=180;33 drawWidth=-width;34 drawHeight=-height;35 break;36 //iphoneç«å±ææï¼æ¤æ¶homeé®å¨ä¸æ¹(æ£å¸¸æ¿ææºçæ¹å)37 case 6:38 canvas.width=height;39 canvas.height=width; 40 degree=90;41 drawWidth=width;42 drawHeight=-height;43 break;44 //iphoneç«å±ææï¼æ¤æ¶homeé®å¨ä¸æ¹45 case 8:46 canvas.width=height;47 canvas.height=width; 48 degree=270;49 drawWidth=-width;50 drawHeight=height;51 break;52 }53 //使ç¨canvasæè½¬æ ¡æ£54 context.rotate(degree*Math.PI/180);55 context.drawImage(this,0,0,drawWidth,drawHeight);56 //è¿åæ ¡æ£å¾ç57 next(canvas.toDataURL("image/jpeg",.8));58 }59 image.src=img;...
index.js
Source:index.js
1'use strict';2const fs = require('fs');3const { createCanvas, Image } = require('canvas');4class Drawer {5 constructor(width = 100, height = 100) {6 this.canvas = { width, height };7 }8 setCanvasSize({ width, height }) {9 this.canvas = {...this.canvas, width, height };10 }11 puzzle() {12 var args = Array.prototype.slice.call(arguments, 0, 4);13 var imageLength = args.length;14 var { width, height } = this.canvas;15 var canvas = createCanvas(width, height);16 var ctx = canvas.getContext('2d');17 var stream = canvas.pngStream();18 var images = [];19 for (let src of args) {20 let image = new Image();21 image.src = src;22 images.push(image);23 }24 let drawWidth = (width - 10) / 2,25 drawHeight = (height - 10) / 2;26 if (imageLength == 3) {27 var image = images.shift();28 ctx.drawImage(image, (width + 10) / 4, 0, drawWidth, drawHeight);29 } else {30 let image = images.shift();31 ctx.drawImage(image, 0, 0, drawWidth, drawHeight);32 image = images.shift();33 ctx.drawImage(image, drawWidth + 10, 0, drawWidth, drawHeight);34 }35 let image = images.shift();36 ctx.drawImage(image, 0, drawHeight + 10, drawWidth, drawHeight);37 image = images.shift();38 ctx.drawImage(image, drawWidth + 10, drawHeight + 10, drawWidth, drawHeight);39 return pngStream;40 }41}42var drawer = null;43module.exports = function() {44 if (!drwaer) drawer = new Drawer();45 return drawer;...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8 if (err) return console.error(err);9 console.log(data);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13 if (err) return console.error(err);14 console.log(data);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org');18 if (err) return console.error(err);19 console.log(data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23 if (err) return console.error(err);24 console.log(data);25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www.webpagetest.org');28 if (err) return console.error(err);29 console.log(data);30});31var wpt = require('webpagetest');
Using AI Code Generation
1var wptext = require('wptext');2var text = new wptext("Hello World");3console.log(text.drawWidth(5));4var wptext = require('wptext');5var text = new wptext("Hello World");6console.log(text.drawWidth(10));7var wptext = require('wptext');8var text = new wptext("Hello World");9console.log(text.drawWidth(15));10var wptext = require('wptext');11var text = new wptext("Hello World");12console.log(text.drawWidth(20));13var wptext = require('wptext');14var text = new wptext("Hello World");15console.log(text.drawWidth(25));16var wptext = require('wptext');17var text = new wptext("Hello World");18console.log(text.drawWidth(30));19var wptext = require('wptext');20var text = new wptext("Hello World");21console.log(text.drawWidth(35));22var wptext = require('wptext');23var text = new wptext("Hello World");24console.log(text.drawWidth(40));25var wptext = require('wptext');26var text = new wptext("Hello World");27console.log(text.drawWidth(45));28var wptext = require('wptext');29var text = new wptext("Hello World");30console.log(text.drawWidth(50));
Using AI Code Generation
1var wptext = require('wptext');2var t = new wptext();3t.drawWidth('Hello world', 10);4var wptext = require('wptext');5var t = new wptext();6t.drawWidth('Hello world', 10);7The drawWidth() method will return an object with the following properties:8Example 2: Using drawWidth() method to draw text with a specified font size9var wptext = require('wptext');10var t = new wptext();11t.drawWidth('Hello world', 10, 20);12The drawWidth() method will return an object with the following properties:13Example 3: Using drawWidth() method to draw text with a specified font size and a specified font14var wptext = require('wptext');15var t = new wptext();16t.drawWidth('Hello world', 10, 20, 'arial');17The drawWidth() method will return an object with the following properties:18Example 4: Using drawWidth() method to draw text with
Using AI Code Generation
1var wpt = new WPT();2var wpt2 = new WPT();3wpt.drawWidth(10);4wpt2.drawWidth(20);5wpt.drawWidth(30);6wpt2.drawWidth(40);7wpt.drawWidth(50);8wpt2.drawWidth(60);9wpt.drawWidth(70);10wpt2.drawWidth(80);11wpt.drawWidth(90);12wpt2.drawWidth(100);13wpt.drawWidth(110);14wpt2.drawWidth(120);15wpt.drawWidth(130);16wpt2.drawWidth(140);17wpt.drawWidth(150);18wpt2.drawWidth(160);19wpt.drawWidth(170);20wpt2.drawWidth(180);21wpt.drawWidth(190);22wpt2.drawWidth(200);23wpt.drawWidth(210);24wpt2.drawWidth(220);25wpt.drawWidth(230);26wpt2.drawWidth(240);27wpt.drawWidth(250);28wpt2.drawWidth(260);29wpt.drawWidth(270);
Using AI Code Generation
1var wpt = require('wpt');2var drawWidth = wpt.drawWidth;3var wpt = new wpt('API_KEY');4drawWidth('www.webpagetest.org', function (err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('wpt');12var drawWidth = wpt.drawWidth;13var wpt = new wpt('API_KEY');14drawWidth('www.webpagetest.org', function (err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wpt = require('wpt');22var drawWidth = wpt.drawWidth;23var wpt = new wpt('API_KEY');24drawWidth('www.webpagetest.org', function (err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31var wpt = require('wpt');32var drawWidth = wpt.drawWidth;33var wpt = new wpt('API_KEY');34drawWidth('www.webpagetest.org', function (err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42var drawWidth = wpt.drawWidth;43var wpt = new wpt('API_KEY');44drawWidth('www.webpagetest.org', function (err, data) {45 if (err) {46 console.log(err);47 } else {48 console.log(data);49 }50});51var wpt = require('wpt');52var drawWidth = wpt.drawWidth;53var wpt = new wpt('API_KEY');54drawWidth('www.webpagetest.org', function (err, data) {55 if (err) {56 console.log(err);57 } else {58 console.log(data);59 }60});
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!!