Best JavaScript code snippet using wpt
games-dashboard.js
Source:games-dashboard.js
1/*ACCESSING ALL HTML ELEMENTS*/2let searchInput = document.querySelector(`#search`);3let searchBtn = document.querySelector(`.ri-search-line`);4let index = ``;5let container = document.querySelector('.container');6let listAll = document.querySelector('.all');7let listStratgies = document.querySelector('.strategies');8let listShooter = document.querySelector('.shooter');9let listMM = document.querySelector('.mmorpg');10let main = document.querySelector('main');11let button = document.querySelector('.more-btn')12let btn;13/*BUILD ARRAYS FOR CATEGORIES*/14let allRandomCategoriesArray = [];15let strategiesArray = [];16let shooterArray = [];17let mmArray = [];18let i = 0;19/*FETCH API LINK START*/20fetch('https://free-to-play-games-database.p.rapidapi.com/api/games?platform=pc',21 {22 method: 'GET',23 headers: {24 'x-rapidapi-host': 'free-to-play-games-database.p.rapidapi.com',25 'x-rapidapi-key': '93b272acdamsh10e28390fcb3114p1a8d21jsn6bd1fef7e35a',26 },27 }28)29.then((response) => response.json())30.then((data) => {31 /* SEARCH METHOD WITH KEYUP EVENT START */32 searchInput.addEventListener(`keyup`, (e) =>{33 let searchString = e.target.value.toLowerCase();34 let results = data.filter((games) => {35 return games.title.toLowerCase().includes(searchString);36 });37 container.style.display = `none`;38 if (results.length === 0) {39 if (main.lastElementChild.classList.contains(`sara`) || main.lastElementChild.classList.contains(`dahman`)) {40 main.lastElementChild.remove();41 let empty = document.createElement(`div`);42 empty.classList = `message sara`;43 let emptyPara = document.createElement(`p`);44 emptyPara.textContent = `No matching results !`;45 empty.appendChild(emptyPara);46 main.appendChild(empty);47 }else {48 49 let empty = document.createElement(`div`);50 empty.classList = `error sara`;51 let emptyPara = document.createElement(`p`);52 emptyPara.textContent = `No matching results !`;53 empty.appendChild(emptyPara);54 main.appendChild(empty);55 }56 }else if (main.lastElementChild.classList.contains(`dahman`) || main.lastElementChild.classList.contains(`sara`)) {57 main.lastElementChild.remove();58 let newContainer = document.createElement(`div`);59 newContainer.addEventListener(`click`, btnClicked);60 newContainer.classList = `container dahman`;61 main.appendChild(newContainer);62 for(let i = 0; i < results.length; i++) {63 let createCard = document.createElement('div');64 createCard.setAttribute('class', 'card');65 let createImg = document.createElement('img');66 createImg.src = results[i].thumbnail;67 createImg.alt = results[i].title;68 let createBtn = document.createElement('button');69 createBtn.setAttribute('index', i);70 createBtn.setAttribute('data-id', results[i].id);71 let createAnchor = document.createElement(`a`);72 createAnchor.href = `../games-details/games-details.html`;73 createAnchor.textContent = 'More';74 createAnchor.classList = `btn`;75 createAnchor.setAttribute('data-id', results[i].id);76 createBtn.appendChild(createAnchor);77 createCard.appendChild(createImg);78 createCard.appendChild(createBtn);79 newContainer.appendChild(createCard);80 }81 }else {82 let newContainer = document.createElement(`div`);83 newContainer.addEventListener(`click`, btnClicked);84 newContainer.classList = `container dahman`;85 main.appendChild(newContainer);86 for(let i = 0; i < results.length; i++) {87 let createCard = document.createElement('div');88 createCard.setAttribute('class', 'card');89 let createImg = document.createElement('img');90 createImg.src = results[i].thumbnail;91 createImg.alt = results[i].title;92 let createBtn = document.createElement('button');93 createBtn.setAttribute('data-id', results[i].id);94 let createAnchor = document.createElement(`a`);95 createAnchor.href = `../games-details/games-details.html`;96 createAnchor.textContent = 'More';97 createAnchor.classList = `btn`;98 createAnchor.setAttribute('data-id', results[i].id);99 createBtn.appendChild(createAnchor);100 createCard.appendChild(createImg);101 createCard.appendChild(createBtn);102 newContainer.appendChild(createCard);103 104 }105 }106 if (searchString === '') {107 main.lastElementChild.remove();108 container.style.display = `flex`;109 }110 });111 /* SEARCH METHOD WITH KEYUP EVENT END */112 /* GET ALL RANDOM FUNCTION START */113 listAll.addEventListener('click', getAllRandom);114 function getAllRandom(){115 for (let i = 0; i < 14; i++){116 let randomAll = Math.floor(Math.random() * data.length);117 let createCard = document.createElement('div');118 createCard.setAttribute('class', 'card');119 let createImg = document.createElement('img');120 createImg.src = data[randomAll].thumbnail;121 createImg.alt = data[randomAll].title;122 let createBtn = document.createElement('button');123 createBtn.setAttribute('index', randomAll);124 createBtn.classList = `btn`;125 createBtn.setAttribute('data-id', data[randomAll].id);126 let createAnchor = document.createElement(`a`);127 createAnchor.href = `../games-details/games-details.html`;128 createAnchor.textContent = 'More';129 createAnchor.classList = `btn`;130 createAnchor.setAttribute('data-id', data[randomAll].id);131 createBtn.appendChild(createAnchor);132 createCard.appendChild(createImg);133 createCard.appendChild(createBtn);134 container.replaceChild(createCard, container.childNodes[i]);135 }136 listAll.style.color = `#6fce6d`;137 listStratgies.style.color = `#ffffff`;138 listMM.style.color = `#ffffff`;139 listShooter.style.color = `#ffffff`;140 }141 /* GET ALLRANDOM FUNCTION END */142 /*PUSH STRATEGIES FUNCTION START*/143 function pushStrategies(){144 for (let i = 0; i < data.length; i++){145 146 if(data[i].genre === 'Strategy'){147 148 strategiesArray.push(data[i]);149 150 }151 152 }153 }154 pushStrategies() //CALLING FUNCTION155 /*PUSH STRATEGIES FUNCTION END*/156 /* GET STRATEGIES FUNCTION START */157 listStratgies.addEventListener('click', getStrategies);158 function getStrategies(){159 for(let i = 0; i < 15; i++){160 let createCard = document.createElement('div');161 createCard.setAttribute('class', 'card');162 let createImg = document.createElement('img');163 createImg.src = strategiesArray[i].thumbnail;164 createImg.alt = strategiesArray[i].title;165 let createBtn = document.createElement('button');166 createBtn.setAttribute('index', i);167 createBtn.classList = `btn`;168 createBtn.setAttribute('data-id', strategiesArray[i].id);169 let createAnchor = document.createElement(`a`);170 createAnchor.href = `../games-details/games-details.html`;171 createAnchor.textContent = 'More';172 createAnchor.classList = `btn`;173 createAnchor.setAttribute('data-id', strategiesArray[i].id);174 createBtn.appendChild(createAnchor);175 createCard.appendChild(createImg);176 createCard.appendChild(createBtn);177 container.replaceChild(createCard, container.childNodes[i]);178 }179 listStratgies.style.color = `#6d8ece`;180 listMM.style.color = `#ffffff`;181 listShooter.style.color = `#ffffff`;182 listAll.style.color = `#ffffff`;183 }184 /* GET STRATEGIES FUNCTION END */185 /* PUSH SHOOTER FUNCTION START */186 function pushShooter(){187 for(let i = 0; i < data.length; i++){188 if(data[i].genre === 'Shooter'){189 shooterArray.push(data[i]);190 }191 }192 }193 pushShooter(); //CALLING FUNCTION194 /* PUSH SHOOTER FUNCTION END */195 /* GET SHOOTER FUNCTION START */196 listShooter.addEventListener('click', getShooter);197 function getShooter(){198 for(let i = 0; i< 15; i++){199 let randomShooter = Math.floor(Math.random() * shooterArray.length);200 let createCard = document.createElement('div');201 createCard.setAttribute('class', 'card');202 let createImg = document.createElement('img');203 createImg.src = shooterArray[randomShooter].thumbnail;204 createImg.alt = shooterArray[randomShooter].title;205 let createBtn = document.createElement('button');206 createBtn.setAttribute('index', randomShooter);207 createBtn.classList = `btn`;208 createBtn.setAttribute('data-id', shooterArray[randomShooter].id);209 let createAnchor = document.createElement(`a`)210 createAnchor.href = `../games-details/games-details.html`;211 createAnchor.textContent = 'More';212 createAnchor.classList = `btn`;213 createAnchor.setAttribute('data-id', shooterArray[randomShooter].id);214 createBtn.appendChild(createAnchor);215 createCard.appendChild(createImg);216 createCard.appendChild(createBtn);217 container.replaceChild(createCard, container.childNodes[i]);218 }219 listShooter.style.color = `#ce6d6d`;220 listMM.style.color = `#ffffff`;221 listStratgies.style.color = `#ffffff`;222 listAll.style.color = `#ffffff`;223 }224 /* PUSH MMORPG FUNCTION START */225 function pushmm(){226 for(let i = 0; i< data.length; i++){227 if(data[i].genre === 'MMORPG'){228 mmArray.push(data[i]);229 }230 }231 232 }233 pushmm(); //CALLING FUNCTION234 /*PUSH MMORPG FUNCTION END*/235 /*GET MMORPG FUNCTION START*/236 listMM.addEventListener('click', getMm);237 function getMm(){238 for(let i = 0; i < 15; i++){239 let randomMm = Math.floor(Math.random() * mmArray.length);240 let createCard = document.createElement('div');241 createCard.setAttribute('class', 'card');242 let createImg = document.createElement('img');243 createImg.src = mmArray[randomMm].thumbnail;244 createImg.alt = mmArray[randomMm].title;245 let createBtn = document.createElement('button');246 createBtn.setAttribute('index', randomMm);247 createBtn.classList = `btn`;248 createBtn.setAttribute('data-id', mmArray[randomMm].id);249 let createAnchor = document.createElement(`a`);250 createAnchor.href = `../games-details/games-details.html`;251 createAnchor.textContent = 'More';252 createAnchor.classList = `btn`;253 createAnchor.setAttribute('data-id', mmArray[randomMm].id);254 createBtn.appendChild(createAnchor);255 createCard.appendChild(createImg);256 createCard.appendChild(createBtn);257 container.replaceChild(createCard, container.childNodes[i]);258 259 }260 listMM.style.color = `#cc6dce`;261 listShooter.style.color = `#ffffff`;262 listStratgies.style.color = `#ffffff`;263 listAll.style.color = `#ffffff`;264 }265 /* GET MMORPG FUNCTION END */266 /* GET RANDOM CARD FROM API START */267 for(let i = 0; i < 15; i++){268 let randomAll = Math.floor(Math.random() * data.length);269 let createCard = document.createElement('div');270 createCard.setAttribute('class', 'card');271 let createImg = document.createElement('img');272 createImg.src = data[randomAll].thumbnail;273 createImg.alt = data[randomAll].title;274 let createBtn = document.createElement('button');275 createBtn.setAttribute('data-id', data[randomAll].id);276 createBtn.classList = `btn`;277 let createAnchor = document.createElement(`a`)278 createAnchor.href = `../games-details/games-details.html`;279 createAnchor.textContent = 'More';280 createAnchor.classList = `btn`;281 createAnchor.setAttribute('data-id', data[randomAll].id);282 createBtn.appendChild(createAnchor);283 createCard.appendChild(createImg);284 createCard.appendChild(createBtn);285 container.appendChild(createCard);286 }287 /* GET RANDOM CARD FROM API END */288 listAll.style.color = `#6fce6d`;289}).catch(Error);290/*FETCH API LINK START*/291/* SAVE INDEX OF OBJECT BY BUTTON FUNCTION START */292container.addEventListener(`click`, btnClicked);293function btnClicked (e) {294 if(e.target.classList.contains(`btn`)){295 let itemText = e.target.getAttribute("data-id");296 localStorage.setItem(`index`, itemText);297 }298}299/* SAVE INDEX OF OBJECT BY BUTTON FUNCTION END */300/*LIGHT AND DARK MODE START*/301//? accessing the elements302let toggleBtn = document.querySelector(".ri-sun-fill");303let changeTitle = document.querySelector("h1");304// console.log(main);305//? toggling the class306function setLightTheme() {307 main.classList.toggle("light");308}309//? add event listener to the btn310toggleBtn.addEventListener("click", changeTheme);311function changeTheme() {312 let lightMode = localStorage.getItem("light");313 if (lightMode !== "on") {314 setLightTheme();315 lightMode = localStorage.setItem("light", "on");316 } else {317 setLightTheme();318 lightMode = localStorage.setItem("light", "off");319 }320}321//? reload the page322let lightMode = localStorage.getItem("light");323if (lightMode === "on") {324 setLightTheme();325}326/*LIGHT AND DARK MODE END*/327/*Digital clock*/328function showTime() {329 let clock = document.querySelector(".clock");330 let time = new Date();331 let hours = time.getHours();332 let minutes = time.getMinutes();333 let seconds = time.getSeconds();334 let period = "AM";335 336 337 if (hours == 0){338 hours = 12;339 }340 341 if (hours > 12)342 hours -= 12;343 period = "PM";344 345 hours = (hours < 10) ? "0" + hours : hours;346 minutes = (minutes < 10) ? "0" + minutes : minutes;347 seconds = (seconds < 10) ? "0" + seconds : seconds;348 349 // var time = hours + ":" + minutes + ":" + seconds + "" + period;350 time = `${hours}:${minutes}:${seconds} ${period}`351 352 clock.textContent = time;353}354setInterval(showTime);355function time() {356 let clock = document.querySelector(".clock");357 let rand = Math.floor(Math.random() * 240);358 clock.style.background = `hsl(${rand}, 100%, 50%)`;359}360setInterval(time, 1000);361// for (let i = 1; i < 15; i++){362// container.childNodes[i].style.display = `none`;363// }364// if (searchString === '') {365// for(let i = 1; i < 15; i++){366// container.childNodes[i].style.display = `flex`;367// }...
CreateAnchor.spec.ts
Source:CreateAnchor.spec.ts
...18 })1920 test("doesn't create invalid anchor", async done => {21 const badanchor: any = { 'id': 'id' }22 const response = await anchorGateway.createAnchor(badanchor)23 expect(response.success).toBeFalsy()24 done()25 })2627 test("creates valid anchor", async done => {28 const validanchor: IAnchor = {29 nodeId: 'node.id',30 anchorId: 'anchor.id',31 contentList: ["Hello Chai Hello Chai"],32 authorList: ["Chai"],33 type: "node",34 createdAt: new Date()35 }3637 const getResponse = await anchorGateway.getAnchor(validanchor.anchorId)38 expect(getResponse.success).toBeFalsy()3940 const response = await anchorGateway.createAnchor(validanchor)41 expect(response.success).toBeTruthy()4243 const getResponse2 = await anchorGateway.getAnchor(validanchor.anchorId)44 expect(getResponse2.success).toBeTruthy()45 expect(getResponse2.payload.contentList).toEqual(["Hello Chai Hello Chai"])46 expect(getResponse2.payload.authorList).toEqual(["Chai"])47 expect(getResponse2.payload.type).toBe("node")48 done()49 })505152 test("creates valid anchor, fails to create valid anchor with same id", async done => {53 const validanchor: IAnchor = {54 nodeId: 'node.id',55 anchorId: 'anchor.id2',56 contentList: ["I like this a lot mmm!"],57 authorList: ["Jinoo"],58 type: "media",59 createdAt: new Date()60 }6162 const getResponse = await anchorGateway.getAnchor(validanchor.anchorId)63 expect(getResponse.success).toBeFalsy()6465 const response = await anchorGateway.createAnchor(validanchor)66 expect(response.success).toBeTruthy()6768 const getResponse2 = await anchorGateway.getAnchor(validanchor.anchorId)69 expect(getResponse2.success).toBeTruthy()70 expect(getResponse2.payload.contentList).toEqual(["I like this a lot mmm!"])71 expect(getResponse2.payload.authorList).toEqual(["Jinoo"])72 expect(getResponse2.payload.type).toBe("media")7374 const invalidanchor: IAnchor = {75 nodeId: 'id2',76 anchorId: 'anchor.id2',77 contentList: ["invalid content"],78 authorList: ["invalid author"],79 type: "media",80 createdAt: new Date()81 }8283 const response2 = await anchorGateway.createAnchor(invalidanchor)84 expect(response2.success).toBeFalsy()8586 const getResponse3 = await anchorGateway.getAnchor(invalidanchor.anchorId)87 expect(getResponse3.success).toBeTruthy()88 expect(getResponse3.payload.contentList).toEqual(["I like this a lot mmm!"])89 expect(getResponse3.payload.authorList).toEqual(["Jinoo"])90 expect(getResponse3.payload.type).toBe("media")91 done()92 })9394 95 96 // if nodeId is wrong type97 // if nodeId is ''98 // if nodeId is null99 test("fails to create anchor when nodeId wrong", async done => {100 const invalidanchor: any = {101 nodeId: 1,102 anchorId: 'a',103 contentList: ["content a"],104 authorList: ["author a"],105 type: "media",106 createdAt: new Date()107 }108 const response = await anchorGateway.createAnchor(invalidanchor)109 expect(response.success).toBeFalsy()110111 const invalidanchor2: any = {112 nodeId: '',113 anchorId: 'a',114 contentList: ["content a"],115 authorList: ["author a"],116 type: "media",117 createdAt: new Date()118 }119 const response2 = await anchorGateway.createAnchor(invalidanchor2)120 expect(response2.success).toBeFalsy()121 122 const invalidanchor3: any = {123 nodeId: null,124 anchorId: 'a',125 contentList: ["content a"],126 authorList: ["author a"],127 type: "media",128 createdAt: new Date()129 }130 const response3 = await anchorGateway.createAnchor(invalidanchor3)131 expect(response3.success).toBeFalsy()132 done()133 })134135 // if anchorId is wrong type136 test("fails to create when anchorId is null", async done => {137 const invalidanchor: any = {138 nodeId: 'id4',139 anchorId: null,140 contentList: ["I like this a lot mmm!"],141 authorList: ["Jinoo"],142 type: "media",143 createdAt: new Date()144 }145 const response = await anchorGateway.createAnchor(invalidanchor)146 expect(response.success).toBeFalsy()147 done()148 })149150 // if anchorId is null151 test("fails to create anchor when anchorId is number", async done => {152 const invalidanchor: any = {153 nodeId: 'id4',154 anchorId: 5,155 contentList: ["content a"],156 authorList: ["author a"],157 type: "media",158 createdAt: new Date()159 }160 const response = await anchorGateway.createAnchor(invalidanchor)161 expect(response.success).toBeFalsy()162 done()163 })164165 // if anchorId is ''166 test("fails to create anchor when anchorId is empty", async done => {167 const invalidanchor: any = {168 nodeId: 'id4',169 anchorId: '',170 contentList: ["content a"],171 authorList: ["author a"],172 type: "media",173 createdAt: new Date()174 }175 const response = await anchorGateway.createAnchor(invalidanchor)176 expect(response.success).toBeFalsy()177 done()178 })179 180181 test("fails to create anchor when type is wrong", async done => {182 const invalidanchor: any = {183 nodeId: "hi",184 anchorId: 'a',185 contentList: ["content a"],186 authorList: ["author a"],187 type: "watermelon",188 createdAt: new Date()189 }190 const response = await anchorGateway.createAnchor(invalidanchor)191 expect(response.success).toBeFalsy()192193 const invalidanchor2: any = {194 nodeId: '',195 anchorId: 'a',196 contentList: ["content a"],197 authorList: ["author a"],198 type: null,199 createdAt: new Date()200 }201 const response2 = await anchorGateway.createAnchor(invalidanchor2)202 expect(response2.success).toBeFalsy()203 204 const invalidanchor3: any = {205 nodeId: null,206 anchorId: 'a',207 contentList: ["content a"],208 authorList: ["author a"],209 type: '',210 createdAt: new Date()211 }212 const response3 = await anchorGateway.createAnchor(invalidanchor3)213 expect(response3.success).toBeFalsy()214 done()215 })216 217 test("fails to create anchor when contentList is wrong", async done => {218 const invalidanchor: IAnchor = {219 nodeId: 'node.id',220 anchorId: 'anchor.id',221 contentList: [],222 authorList: ["K"],223 type: "node",224 createdAt: new Date()225 }226 const response = await anchorGateway.createAnchor(invalidanchor)227 expect(response.success).toBeFalsy()228229 const invalidanchor2: any = {230 nodeId: 'node.id',231 anchorId: 'anchor.id',232 contentList: "oop",233 authorList: ["K"],234 type: "node",235 createdAt: new Date()236 }237 const response2 = await anchorGateway.createAnchor(invalidanchor2)238 expect(response2.success).toBeFalsy()239 done()240241 })242 243 test("fails to create anchor when authorList is wrong", async done => {244 const invalidanchor: any = {245 nodeId: 'node.id',246 anchorId: 'anchor.id',247 contentList: ["oop"],248 authorList: [],249 type: "node",250 createdAt: new Date()251 }252 const response = await anchorGateway.createAnchor(invalidanchor)253 expect(response.success).toBeFalsy()254255 const invalidanchor2: any = {256 nodeId: 'node.id',257 anchorId: 'anchor.id',258 contentList: ["oop"],259 authorList: "oh",260 type: "node",261 createdAt: new Date()262 }263 const response2 = await anchorGateway.createAnchor(invalidanchor2)264 expect(response2.success).toBeFalsy() 265 done()266267 })
...
index.js
Source:index.js
...17 * className:è¦æçæ ·å¼ç±»18 * text:ä¸é´ææ¬19 * newPage: ç¹å»å跳转å°åªä¸é¡µ20 */21 function createAnchor(className, text, newPage) {22 var a = document.createElement('a');23 a.className = className; // æä¸å¯¹åºçæ ·å¼ç±»24 a.innerText = text; // 设置ä¸é´çææ¬25 divPager.appendChild(a);26 // ç¹å»è¿ä¸ª a æ ç¾è·³è½¬å°ç¬¬å 页27 a.onclick = function () {28 // åæï¼æè°è·³è½¬ï¼å
¶å®å°±æ¯éæ°è°ç¨ createPager29 // ä½æ¯ï¼ä½ è¦æ³¨æï¼æå ç§æ
åµæ¯ä¸è½å¤è·³è½¬30 if (newPage < 1 || newPage > pageNumber || newPage === page) {31 return;32 }33 // 没æè¿å
¥å°ä¸é¢ç ifï¼è¯´ææ¯å¯ä»¥è·³è½¬ç34 createPager(newPage, pageNumber, mostNumber, container);35 // å页跳转ä¹åï¼è¿ä¼åå
¶ä»çäºæ
36 // åé请æ±è·åæ°æ®....37 }38 }39 // 2. æ们è¦å¼å§å建å页40 // éè¿åæï¼æ们åç°å建è¿ä¸ªå页å¯ä»¥å为 4 个é¨å41 // ï¼1ï¼é¦é¡µåä¸ä¸é¡µ42 if (page === 1) {43 // 说æå½åæ¯ç¬¬ä¸é¡µ44 // ç±äºèèå°å建å
·ä½å页项ç®çé»è¾è¦ç¨çå°æ¹å¾å¤ï¼æ以æä¹å°å
¶å°è£
æä¸ä¸ªå½æ°45 // 该å½æ°éè¦ç¥éçä¿¡æ¯ï¼1. è¦ä¸è¦ææ ·å¼ç±» 2. ä¸é´çææ¬åä»ä¹ 3. ç¹å»å跳转å°ç¬¬å 页46 createAnchor('disabled', 'é¦é¡µ', 1)47 createAnchor('disabled', 'ä¸ä¸é¡µ', page - 1)48 } else {49 createAnchor('', 'é¦é¡µ', 1)50 createAnchor('', 'ä¸ä¸é¡µ', page - 1)51 }52 // ï¼2ï¼ä¸é´çæ°å53 // é¦å
æ们éè¦è®¡ç®ä¸å¤´ä¸å°¾54 var min = Math.floor(page - mostNumber / 2);55 if (min < 1) {56 min = 1;57 }58 var max = min + mostNumber - 1;59 if (max > pageNumber) {60 max = pageNumber;61 }62 // æ¥ä¸æ¥æ们就éè¦éè¿å¾ªç¯æ¥çæå页项ç®63 for (var i = min; i <= max; i++) {64 if (i === page) {65 // è¿å
¥æ¤ ifï¼è¯´ææ¯å½å页ï¼éè¦æä¸ active ç±»66 createAnchor("active", i, i);67 } else {68 createAnchor("", i, i)69 }70 }71 // ï¼3ï¼ä¸ä¸é¡µå尾页72 if (page === pageNumber) {73 // 说æå½åæ¯ç¬¬ä¸é¡µ74 // ç±äºèèå°å建å
·ä½å页项ç®çé»è¾è¦ç¨çå°æ¹å¾å¤ï¼æ以æä¹å°å
¶å°è£
æä¸ä¸ªå½æ°75 // 该å½æ°éè¦ç¥éçä¿¡æ¯ï¼1. è¦ä¸è¦ææ ·å¼ç±» 2. ä¸é´çææ¬åä»ä¹ 3. ç¹å»å跳转å°ç¬¬å 页76 createAnchor('disabled', 'ä¸ä¸é¡µ', page + 1)77 createAnchor('disabled', '尾页', pageNumber)78 } else {79 createAnchor('', 'ä¸ä¸é¡µ', page + 1)80 createAnchor('', '尾页', pageNumber)81 }82 // ï¼4ï¼å½å页ç 83 var span = document.createElement('span');84 span.innerText = page + "/" + pageNumber;85 divPager.appendChild(span);86 // 以åå°çæ好çæ´ä¸ªå页ç»ä»¶æå°å®¹å¨ä¸é¢å³å¯87 container.appendChild(divPager);...
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');32var wpt = new WebPageTest('www.webpagetest.org');
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4});5{ responseCode: 200,6 statusText: 'Ok' }7var wpt = require('wpt');8var wpt = new WebPageTest('www.webpagetest.org');9wpt.getLocations(function(err, data) {10 console.log(data);11});12{ responseCode: 200,13 { '2': 14 { location: 'Dulles, VA',15 'from': 'Dulles, VA' },16 { location: 'Dulles, VA',17 'from': 'Dulles, VA' },18 { location: 'Dulles, VA',19 'from': 'Dulles, VA' },20 { location: 'Dulles, VA',
Using AI Code Generation
1var wptools = require('wptools');2var wp = wptools.page('Barack Obama');3wp.createAnchor('Barack Obama', 'Barack Obama', function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var wp = wptools.page('Barack Obama');8wp.createAnchor('Barack Obama', 'Barack Obama', function(err, data) {9 console.log(data);10});11var wptools = require('wptools');12var wp = wptools.page('Barack Obama');13wp.createAnchor('Barack Obama', 'Barack Obama', function(err, data) {14 console.log(data);15});16var wptools = require('wptools');17var wp = wptools.page('Barack Obama');18wp.createAnchor('Barack Obama', 'Barack Obama', function(err, data) {19 console.log(data);20});21var wptools = require('wptools');22var wp = wptools.page('Barack Obama');23wp.createAnchor('Barack Obama', 'Barack Obama', function(err, data) {24 console.log(data);25});26var wptools = require('wptools');27var wp = wptools.page('Barack Obama');28wp.createAnchor('Barack Obama', 'Barack Obama', function(err, data) {29 console.log(data);30});31var wptools = require('wptools');32var wp = wptools.page('Barack Obama');33wp.createAnchor('Barack Obama', 'Barack Obama', function(err, data) {34 console.log(data);35});36var wptools = require('wptools');37var wp = wptools.page('Barack Obama');38wp.createAnchor('Barack Obama', 'Barack Obama
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('API_KEY');3 console.log(data);4});5{anchor_id: "8d8c9e9d25e1a1c1e8e8d1f1a1f1a1e1"}6var wpt = require('webpagetest');7var test = wpt('API_KEY');8test.getAnchor('8d8c9e9d25e1a1c1e8e8d1f1a1f1a1e1', function(err, data) {9 console.log(data);10});11var wpt = require('webpagetest');12var test = wpt('API_KEY');13 console.log(data);14});
Using AI Code Generation
1var wpt = require("wpt");2var wptConfig = require("./wptConfig");3var wptConfig = new wptConfig();4var wptModule = new wpt(wptConfig.apiKey, wptConfig.serverUrl, wptConfig.location, wptConfig.connection, wptConfig.browser);5var label = "google";6wptModule.createAnchor(url, label, function (error, data) {7 if (error) {8 console.log(error);9 } else {10 console.log(data);11 }12});13### wpt.getAnchors(callback)14var wpt = require("wpt");15var wptConfig = require("./wptConfig");16var wptConfig = new wptConfig();17var wptModule = new wpt(wptConfig.apiKey, wptConfig.serverUrl, wptConfig.location, wptConfig.connection, wptConfig.browser);18wptModule.getAnchors(function (error, data) {19 if (error) {20 console.log(error);21 } else {22 console.log(data);23 }24});25### wpt.getAnchorDetails(anchorId, callback)26var wpt = require("wpt");27var wptConfig = require("./wptConfig");28var wptConfig = new wptConfig();29var wptModule = new wpt(wptConfig.apiKey, wptConfig.serverUrl, wptConfig.location, wptConfig.connection, wptConfig.browser);30var anchorId = "1234567890";31wptModule.getAnchorDetails(anchorId, function (error, data) {32 if (error) {33 console.log(error);34 } else {35 console.log(data);36 }37});38### wpt.editAnchor(anchorId, label, url, callback)
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!!