Best JavaScript code snippet using wpt
common.js
Source:common.js
1// Updates originate in community/js/common/common.js2function loadParams(paramStr,hashStr) {3 // Priority: 1st hash, 2nd url search4 var request = {};5 var pairs = paramStr.substring(paramStr.indexOf('?') + 1).split('&');6 for (var i = 0; i < pairs.length; i++) {7 if(!pairs[i])8 continue;9 var pair = pairs[i].split('=');10 request[decodeURIComponent(pair[0]).toLowerCase()] = decodeURIComponent(pair[1]);11 }12 // Next we override with the Hash for older browser that cannot update the URL from script.13 // And for embedding where URL variables may not be usable.14 var hashPairs = hashStr.substring(hashStr.indexOf('#') + 1).split('&');15 for (var i = 0; i < hashPairs.length; i++) {16 if(!hashPairs[i])17 continue;18 if (i==0 && hashPairs[i].indexOf("=") == -1) {19 request[""] = hashPairs[i]; // Allows for initial # param without =.20 continue;21 }22 var hashPair = hashPairs[i].split('=');23 request[decodeURIComponent(hashPair[0]).toLowerCase()] = decodeURIComponent(hashPair[1]);24 }25 return request;26}27var param = loadParams(location.search,location.hash);28function loadMarkupPage(pagePath, divID, target) {29 d3.text(pagePath).then(function(data) {30 var converter = new showdown.Converter({tables:true}),31 html = converter.makeHtml(data);32 document.getElementById(divID).innerHTML = html;33 });34}35function consoleLog(text,value) {36 $("#ds_command").show();37 if (value) {38 $("#ds_command textarea").append(text + " " + value + "\n");39 } else {40 $("#ds_command textarea").append(text + "\n");41 }42 var dsconsole = $("#ds_command textarea");43 if(dsconsole.length)44 dsconsole.scrollTop(dsconsole[0].scrollHeight - dsconsole.height() - 17); // Adjusts for bottom alignment45 console.log(text, value);46}47// Convert json to html48var selected_array=[];49var omit_array=[];50function formatRow(key,value,level,item) {51 var addHtml = '';52 if (key == 'color') {53 // JQuery uses this attribute to set the bar color where class level1 immediately above this div.54 addHtml += "<div class='colorHolder' currentlevel='" + level + "' currentitem='" + item + "' color='" + value + "'></div>"55 }56 if (level==1 && selected_array.length > 0 && !selected_array.includes(key) ) {57 return addHtml;58 }59 if (level==1 && omit_array.length > 0 && omit_array.includes(key) ) {60 return addHtml;61 }62 level = level + 1;63 //if (level==1) { // Span rightcell64 // level=2;65 // addHtml += "<div class='hidden titlecell level1' style='width:100%'>" + key + "</div><div style='clear:both' class='hidden level" + level + "'>"66 //} else {67 addHtml += "<div class='hidden titlecell level" + level + "'>" + key + "</div><div class='hidden rightcell level" + level + "'>"68 //}69 70 //if (value.length == 0) {71 // addHtml += "<div class='level" + level + "'> </div>\n";72 // console.log("Blank: " + key + " " + value);73 //} else 74 if (isObject(value)) {75 for (c in value) {76 console.log("isObject: " + key + " " + value);77 78 //if (json.data[a].constructor === Array && selected_array.includes(a) ) {79 if (isObject(value[c])) {80 // NEVER REACHED?81 console.log("This code is reached for location: " + key + " " + value);82 if (value[c].length >1){83 for (d in value[c]){ 84 85 if (isObject(value[c][d])) {86 //addHtml += "<b>Add something else here</b>\n";87 for (e in value[c][d]){88 //addHtml += "<div class='level" + level + "'>" + e + ":: " + value[c][d][e] + "</div>\n";89 addHtml += formatRow(e,"-- " + value[c][d][e],level);90 }91 } else {92 //addHtml += "<div class='level" + level + "'>" + d + "::: " + value[c][d] + "</div>\n";93 addHtml += formatRow(d,"---- " + value[c][d],level);94 }95 }96 }97 } else {98 addHtml += formatRow(c,value[c],level);99 //addHtml += "<div class='level'>" + c + ":::: " + value[c] + "</div>\n";100 }101 } 102 } 103 104 /*if (Object.keys(value).length >1){105 console.log(b);106 }*/107 // value.constructor === Array108 else if (isArray(value)) { // was b. && selected_array.includes(key) seems to prevent overload for DiffBot. Need to identify why.109 //console.log(value.length);110 console.log("isArray: " + key + " " + value + " " + value.length);111 if (value.length > 0) {112 for (c in value) {113 curLine="" 114 //console.log(value[c],b,c); //c is 0,1,2 index115 116 if (isObject(value[c]) || isArray(value[c])) {117 for (d in value[c]){118 119 if (isObject(value[c][d])) { // Error in Drupal json120 //addHtml += "<b>Add something else here</b>\n";121 for (e in value[c][d]){122 addHtml += formatRow(e,value[c][d][e],level);123 //addHtml += "<div class='level5'>" + e + ": " + value[c][d][e] + "</div>\n";124 }125 } else {126 //console.log("Found: " + value[c][d])127 addHtml += formatRow(d,value[c][d],level);128 //addHtml += "<div class='level4'>" + d + ":: " + value[c][d] + "</div>\n";129 }130 // if (value[c].constructor === Array && selected_array.includes(c) ) {131 // addHtml += "<b>Add loop here</b>\n";132 // }133 // if (isArray(value[c][d])) {134 // addHtml += "<b>Add something here</b>\n";135 // }136 137 }138 /*139 } else if (isArray(value[c])) {140 for (d in value[c]) {141 if (isObject(value[c][d])) {142 //addHtml += "<b>Add something else here</b>\n";143 for (e in value[c][d]){144 addHtml += formatRow(e,value[c][d][e],level);145 //addHtml += "<div class='level5'>" + e + ": " + value[c][d][e] + "</div>\n";146 }147 } else {148 //console.log("Found: " + value[c][d]); // Returns error since not object149 console.log("Found: " + d);150 //addHtml += formatRow(d,d,level); // BUG151 addHtml += "<div class='level4'>" + d + "</div>\n";152 }153 //addHtml += "<div class='level" + level + "'>" + value[c] + "</div>\n";154 }155 */156 } else {157 // For much of first level single names.158 addHtml += "<div class='level" + level + "'>" + value[c] + "</div>\n";159 }160 161 162 163 }164 } else {165 console.log("Array of 0: " + key + " " + value);166 //addHtml += formatRow(c,value[c],level);167 addHtml += "<div class='level" + level + "'>" + value + " </div>\n";168 }169 } else if (key == "url") {170 addHtml += "<a href='" + value + "'>" + value + "</a>"171 } else if (key.indexOf("Uri")>=0) {172 uriLink = (value.indexOf("http")==0) ? value : "https://" + value; // Brittle173 addHtml += "<a href='" + uriLink + "'>" + value + "</a>"174 } else if (key == "logo") {175 addHtml += "<img src='" + value + "' class='rightlogo'><br>"176 } else if (key.toLowerCase().includes("timestamp")) {177 addHtml += "<div class='level" + level + "'>" + new Date(value) + "</div>\n";178 } else {179 //console.log("Last: " + key + " " + value);180 addHtml += "<div class='level" + level + "'>" + value + "</div>\n";181 }182 addHtml += "</div>\n";183 //result.innerHTML = result.innerHTML + addHtml;184 return addHtml;185}186isObject = function(a) {187 return (!!a) && (a.constructor === Object);188};189function isArray(obj){190 //return !!obj && obj.constructor === Array;191 //return Array.isArray(obj);192 //if (obj.toString.indexOf("[") != 0) {193 if (typeof obj == "string") {194 //return false; // no effect195 }196 return $.isArray(obj);197}198Object.size = function(obj) {199 return Object.keys(obj).length;200}201function inIframe() {202 try {203 return window.self !== window.top;204 } catch (e) {205 return true;206 }207}208addEventListener("load", function(){209 var getParentAnchor = function (element) {210 while (element !== null && element.tagName !== undefined) {211 if (element.tagName.toUpperCase() === "A") {212 return element;213 }214 element = element.parentNode;215 }216 return null;217 };218 document.querySelector("body").addEventListener('click', function(e) {219 //consoleLog('click ' + Date.now())220 var anchor = getParentAnchor(e.target);221 if(anchor !== null) {222 $('#ds_command').hide();223 }224 }, false);...
templet_member_home.js
Source:templet_member_home.js
1/*-----------------------------------------------------------------------------2* @Description: 模æ¿-个人ä¸å¿-é¦é¡µ3* @author: åæ¦4* @date 2017.11.155* ---------------------------------------------------------------------------*/6$(function(){7 var templet_entities;8 var data = {9 "orderBy": "-shangshishijian",10 "pageNo": 1,11 "pageSize": 412 };13 var windowWidth = $(window).width();14 if(windowWidth<576){15 var recommendBoxWidth = $('.js_memberRecommendBox').width();16 $('.js_memberRecommendTitle').css('width',recommendBoxWidth-103 +'px')17 }18 if(windowWidth>1199){19 var obj={20 'obj':$('.js_memberRecommendTitle>p'), //éè¦æªåç对象ï¼å¯ä»¥æ¯åä¸classçå¤ä¸ªå¯¹è±¡21 'fontSize':'20', //æªå对象çåä½å¤§å°22 'lineNub':'2', //ä¿ççè¡æ°23 'width':$('.js_memberRecommendTitle').width() //éå¿
å¡«ï¼å¯¹è±¡ç宽度ï¼å¦æä¼ å
¥ç对象ä¸æ¯å¨ææ±å
¥çæ¤é¡¹å¯çç¥ï¼24 };25 //è°ç¨æ¹æ³26 textLength(obj)27 }28 $.ajax({29 url: siteConfig.userUrl + "/interaction-search/front/recommendation/list/",30 data: JSON.stringify(data),31 applicationType: true,32 login: true,33 success_cb: function (data) {34 templet_entities = data.data.entities;35 //大äº575æ¾ç¤ºä¸¤ä¸ª å°äº575æ¾ç¤ºä¸ä¸ª36 if($(window).width()<=575){37 smallfreshen(templet_entities);38 }else{39 freshenA(templet_entities);40 }41 $('.js-freshen').live('click',function () {42 if($(window).width()<=575){43 smallfreshen(templet_entities);44 }else{45 if ($('.js-recommendation').attr('freshen') == 'A') {46 freshenB(templet_entities);47 $('.js-recommendation').attr('smallfreshen',0);48 }49 else if ($('.js-recommendation').attr('freshen') == 'B') {50 freshenA(templet_entities);51 $('.js-recommendation').attr('smallfreshen',2);52 }53 }54 })55 }56 });57 //ç»å¶æ°å58 orderListCount();59})60//第ä¸ç¬¬äºä¸ªäº§å(大äº575)61function freshenA(templet_entities) {62 $('.js-recommendation').attr('freshen','A');63 var templet_addhtml='';64 var templet_branches=2;65 //å¦æ产åæ»æ°å°äº266 if(templet_branches>templet_entities.length){67 templet_branches=templet_entities.length;68 }69 for(var i=0;i<templet_branches;i++){70 var templet_docpuburl=templet_entities[i].docpuburl;71 var templet_location=templet_docpuburl.lastIndexOf("\/");72 var templet_picUrl=templet_docpuburl.substring(0,templet_location+1)+templet_entities[i].appfile;73 templet_addhtml+='<div class="o_u o_df_1-2 o_lg_1-2 o_sm_1-2 o_xs_2-2 js_memberRecommendBox js-product">';74 templet_addhtml+='<div class="member-home-down-cont">';75 templet_addhtml+='<a class="o_u " href="'+templet_docpuburl+'">';76 templet_addhtml+='<img src="'+templet_picUrl+'"/></a>';77 templet_addhtml+='<div class="member-home-down-info o_u js_memberRecommendTitle"><a href="'+templet_docpuburl+'"> ';78 templet_addhtml+='<p class="pro-info-title">'+templet_entities[i].pname+'</p>';79 templet_addhtml+='<span class="pro-info-type">'+templet_entities[i].modelno+'</span>';80 templet_addhtml+='<strong>ï¿¥'+templet_entities[i].price+'.00</strong></a></div></div></div> ';81 }82 $('.js-recommendation').html(templet_addhtml);83}84//第ä¸ç¬¬å个产å(大äº575)85function freshenB(templet_entities) {86 //å¦æ产åæ»æ°å°äº2å°±ä¸æ§è¡Bæ¹æ³87 if(3>templet_entities.length){88 return;89 }90 $('.js-recommendation').attr('freshen','B');91 var templet_addhtml='';92 for(var i=2;i<templet_entities.length;i++){93 var templet_docpuburl=templet_entities[i].docpuburl;94 var templet_location=templet_docpuburl.lastIndexOf("\/");95 var templet_picUrl=templet_docpuburl.substring(0,templet_location+1)+templet_entities[i].appfile;96 templet_addhtml+='<div class="o_u o_df_1-2 o_lg_1-2 o_sm_1-2 o_xs_2-2 js_memberRecommendBox js-product">';97 templet_addhtml+='<div class="member-home-down-cont">';98 templet_addhtml+='<a class="o_u " href="'+templet_docpuburl+'">';99 templet_addhtml+='<img src="'+templet_picUrl+'"/></a>';100 templet_addhtml+='<div class="member-home-down-info o_u js_memberRecommendTitle"> <a href="'+templet_docpuburl+'">';101 templet_addhtml+='<p class="pro-info-title">'+templet_entities[i].pname+'</p>';102 templet_addhtml+='<span class="pro-info-type">'+templet_entities[i].modelno+'</span>';103 templet_addhtml+='<strong>ï¿¥'+templet_entities[i].price+'.00</strong></a></div></div></div> ';104 }105 $('.js-recommendation').html(templet_addhtml);106}107//å°äº575çæ¶åæ ¹æ®Divéé¢çsmallfreshenæ¥åå¼108function smallfreshen(templet_entities){109 var templet_count=$('.js-recommendation').attr('smallfreshen')110 var templet_addhtml='';111 var templet_docpuburl=templet_entities[templet_count].docpuburl;112 var templet_location=templet_docpuburl.lastIndexOf("\/");113 var templet_picUrl=templet_docpuburl.substring(0,templet_location+1)+templet_entities[templet_count].appfile;114 templet_addhtml+='<div class="o_u o_df_1-2 o_lg_1-2 o_sm_1-2 o_xs_2-2 js_memberRecommendBox js-product">';115 templet_addhtml+='<div class="member-home-down-cont">';116 templet_addhtml+='<a class="o_u" href="'+templet_docpuburl+'">';117 templet_addhtml+='<img src="'+templet_picUrl+'"/></a>';118 templet_addhtml+='<div class="member-home-down-info o_u js_memberRecommendTitle"><a href="'+templet_docpuburl+'"> ';119 templet_addhtml+='<p class="pro-info-title">'+templet_entities[templet_count].pname+'</p>';120 templet_addhtml+='<span class="pro-info-type">'+templet_entities[templet_count].modelno+'</span>';121 templet_addhtml+='<strong>ï¿¥'+templet_entities[templet_count].price+'.00</strong></a></div></div></div> ';122 $('.js-recommendation').html(templet_addhtml);123 templet_count++;124 if(templet_count>=templet_entities.length){125 $('.js-recommendation').attr('smallfreshen',0);126 }else{127 $('.js-recommendation').attr('smallfreshen',templet_count);128 }129}130//ç»å¶æ é¢æ æ°å131function orderListCount(){132 var templet_datePay={133 "orderStatus":1134 };135 $.ajax({136 url: siteConfig.userUrl + "/buy/order/order-front/list/",137 data: JSON.stringify(templet_datePay),138 applicationType: true,139 login: true,140 success_cb: function (data) {141 if(!data.data.entityCount==0){142 $('.js-countPay').html('<div class="member-home-top-list-nub">'+data.data.entityCount+'</div>');143 }144 }145 })146 var templet_dateReceived={147 "orderStatus":3148 };149 $.ajax({150 url: siteConfig.userUrl + "/buy/order/order-front/list/",151 data: JSON.stringify(templet_dateReceived),152 applicationType: true,153 login: true,154 success_cb: function (data) {155 if(!data.data.entityCount==0){156 $('.js-countReceived').html('<div class="member-home-top-list-nub">'+data.data.entityCount+'</div>');157 }158 }159 })160 var templet_comment={161 "commentStatus":0,162 "pageNo":1,163 "pageSize":1164 };165 $.ajax({166 url: siteConfig.userUrl + "/interaction-comment/comment/orderComment/getOrderListByCommSta/",167 type:"get",168 data: templet_comment,169 login: true,170 success_cb: function (data) {171 if(!data.data.entityCount==0){172 $('.js-countComment').html('<div class="member-home-top-list-nub">'+data.data.entityCount+'</div>');173 }174 }175 });...
VScodePlugin.js
Source:VScodePlugin.js
1window.onload = function(){2 readTextFile("../notes/VScodePlugin.json",function(text){Readflie(text);});3}4function showMarkdown(url,content,addhtml) {5 // è·å表ååé6 // å建XMLHttpRequest对象7 var xmlhttp;8 if (window.XMLHttpRequest) {9 // IE7+, Firefox, Chrome, Opera, Safari æµè§å¨æ§è¡ä»£ç 10 xmlhttp = new XMLHttpRequest();11 }12 else {13 // IE6, IE5 æµè§å¨æ§è¡ä»£ç 14 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");15 }16 // å¾å°æå¡å¨ååºåï¼å¯¹å¾å°çMarkdownææ¡£è¿è¡è§£æ17 xmlhttp.onreadystatechange = function () {18 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {19 // è¿éè°ç¨äºmarkedæ¡æ¶ä¸çmarkedå½æ°å®ç°Markdown2HTMLç解æ20 content.innerHTML += addhtml + marked(xmlhttp.responseText);21 }22 }23 // åæå¡å¨åé请æ±ï¼è·åä½ éè¦çMarkdownææ¡£24 xmlhttp.open("GET", url, true);25 xmlhttp.send(null);26}27function Readflie(text){28 var data = (JSON.parse(text));29 //åå¾å
容çå30 let content = document.getElementById("content");31 let addhtml = content.innerHTML;32 for (let i in data) {33 //æ·»å ä¸çº§æ é¢34 addhtml = addhtml + "<h1>" + i + "</h1>";35 //éåæå¤å± i == VScode36 let master = data[i];37 for (const a in master) {38 //éååç±»æ39 let mas = master[a];40 for (let b = 0; b <= mas.length - 1; b++) {41 if (typeof mas[b] == "object") {42 //è·åäºçº§æ é¢ä¸çåç±»æ°ç»å¯¹è±¡43 let mas_1 = mas[b];44 for (const c in mas_1) {45 //éååç±»æ°ç»å¯¹è±¡46 let mas_2 = mas_1[c];47 for (let d = 0; d <= mas_2.length - 1; d++) {48 if (typeof mas_2[d] == "object") {49 let el_v = mas_2[d];50 let str = "<li><strong>" + el_v.name + "</strong><div class ='description'>æè¿°:<span>" + el_v.description51 + "</span><p><img src='" + el_v.imgsrc + "' alt='" + el_v.name + "'></p></div></li>";52 switch (d) {53 //å¤çå¼å¤´54 case 1: {55 addhtml += "<ol>" + str;56 }57 break;58 //å¤çç»å°¾59 case mas_2.length - 1: {60 addhtml += str + "</ol>"61 }62 break;63 default: {64 addhtml += str;65 }66 break;67 }68 } else {69 //æ·»å äºçº§æ é¢ä¸çåç±»70 addhtml += "<h4 id='" + mas_2[d] + "'>" + c + "</h4>";71 }72 }73 }74 } else {75 //æ·»å äºçº§æ é¢76 addhtml += "<h2 id='" + mas[b] + "'>" + a + "</h2>";77 }78 }79 }80 }81 showMarkdown("../notes/VScodePlugin.md",content,addhtml);82}83function readTextFile(file, callback) {84 var rawFile = new XMLHttpRequest();85 rawFile.overrideMimeType("application/json");86 //console.log(rawFile.readyState);87 rawFile.open("GET", file, true);88 rawFile.onreadystatechange = function () {89 //console.log(rawFile.readyState);90 if (rawFile.readyState === 4 && rawFile.status == "200") {91 callback(rawFile.responseText);92 } else {93 //console.log(rawFile.readyState);94 }95 }96 rawFile.send(null);...
Using AI Code Generation
1wpt.addHTML('<p>hello world</p>');2wpt.addHTML('<p>hello world</p>');3wpt.addHTML('<p>hello world</p>');4wpt.addHTML('<p>hello world</p>');5wpt.addHTML('<p>hello world</p>');6wpt.addHTML('<p>hello world</p>');7wpt.addHTML('<p>hello world</p>');8wpt.addHTML('<p>hello world</p>');9wpt.addHTML('<p>hello world</p>');10wpt.addHTML('<p>hello world</p>');11wpt.addHTML('<p>hello world</p>');12wpt.addHTML('<p>hello world</p>');13wpt.addHTML('<p>hello world</p>');14wpt.addHTML('<p>hello world</p>');15wpt.addHTML('<p>hello world</p>');16wpt.addHTML('<p>hello world</p>');17wpt.addHTML('<p>hello world</p>');18wpt.addHTML('<p>hello world</p>');19wpt.addHTML('<p>hello world</p>');20wpt.addHTML('<
Using AI Code Generation
1var wptoolbox = require('wptoolbox');2wptoolbox.addHTML('test.html', 'test.js', 'test2.html', function(err, result) {3 if (err) console.log(err);4 console.log(result);5});6## addHTML(html, js, out, callback)7## addJS(js, out, callback)8## addCSS(css, out, callback)9## minifyHTML(html, out, callback)10## minifyJS(js, out, callback)11## minifyCSS(css, out, callback)12## minifyJSON(json, out, callback)
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools('Albert Einstein');3wiki.addHTML().then(function (result) {4 console.log(result);5});6### addImages()7var wptools = require('wptools');8var wiki = wptools('Albert Einstein');9wiki.addImages().then(function (result) {10 console.log(result);11});12### addInfo()13var wptools = require('wptools');14var wiki = wptools('Albert Einstein');15wiki.addInfo().then(function (result) {16 console.log(result);17});18### addLinks()19var wptools = require('wptools');20var wiki = wptools('Albert Einstein');21wiki.addLinks().then(function (result) {22 console.log(result);23});24### addPageprops()25var wptools = require('wptools');26var wiki = wptools('Albert Einstein');27wiki.addPageprops().then(function (result) {28 console.log(result);29});30### addParsedText()31var wptools = require('wptools');32var wiki = wptools('Albert Einstein');33wiki.addParsedText().then(function (result) {34 console.log(result);35});36### addRevisions()37var wptools = require('wptools');38var wiki = wptools('Albert Einstein');39wiki.addRevisions().then(function (result) {40 console.log(result);41});42### addText()43var wptools = require('wptools');44var wiki = wptools('Albert Einstein');45wiki.addText().then(function (result) {46 console.log(result);47});
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!!