How to use updateAttrs method in Playwright Internal

Best JavaScript code snippet using playwright-internal

sheetworkers.js

Source:sheetworkers.js Github

copy

Full Screen

1// Sheet Variables23const skillList = {4 "linguistics":{5 unlocks: ["sophontology"]6 },7 "biology":{8 unlocks: ["genetics","psychology"]9 },10 "first_aid": {11 unlocks: ["pathology"]12 },13 "hydroponics": {14 unlocks: ["botany"]15 },16 "geology": {17 unlocks: ["planetology","asteroid_mining"]18 },19 "zero-g": {20 unlocks: ["asteroid_mining"]21 },22 "scavenging": {23 unlocks: ["asteroid_mining","jury_rigging"]24 },25 "heavy_machinery": {26 unlocks: ["asteroid_mining","engineering"]27 },28 "computers": {29 unlocks: ["engineering","hacking"]30 },31 "mechanical_repair": {32 unlocks: ["engineering", "jury_rigging", "vehicle_specialization"]33 },34 "driving": {35 unlocks: ["vehicle_specialization"]36 },37 "piloting": {38 unlocks: ["vehicle_specialization","astrogation"]39 },40 "mathematics": {41 unlocks: ["physics"]42 },43 "art": {44 unlocks: ["mysticism"]45 },46 "archaeology": {47 unlocks: ["mysticism"]48 },49 "theology": {50 unlocks: ["mysticism"]51 },52 "military_training": {53 unlocks: ["tactics","gunnery","firearms","explosives","close-quarters_combat"]54 },55 "rimwise": {56 unlocks: ["firearms","close-quarters_combat"]57 },58 "athletics": {59 unlocks: ["close-quarters_combat"]60 },61 "chemistry": {62 unlocks: ["explosives"]63 },64 "psychology": {65 unlocks: ["sophontology"]66 },67 "genetics": {68 unlocks: ["xenobiology"]69 },70 "pathology": {71 unlocks: ["xenobiology","surgery"]72 },73 "botany": {74 unlocks: ["xenobiology"]75 },76 "planetology": {77 unlocks: []78 },79 "asteroid_mining" : {80 unlocks: []81 },82 "jury_rigging": {83 unlocks: ["cybernetics"]84 },85 "engineering": {86 unlocks: ["cybernetics","robotics","artificial_intelligence"]87 },88 "hacking": {89 unlocks: ["artificial_intelligence"]90 },91 "vehicle_specialization": {92 unlocks: ["command"]93 },94 "astrogation": {95 unlocks: ["hyperspace"]96 },97 "physics": {98 unlocks: ["hyperspace"]99 },100 "mysticism": {101 unlocks: ["xenoesotericism", "hyperspace"]102 },103 "tactics": {104 unlocks: ["command"]105 },106 "gunnery": {107 unlocks: ["weapon_specialization"]108 },109 "firearms": {110 unlocks: ["weapon_specialization"]111 },112 "close-quarters_combat": {113 unlocks: ["weapon_specialization"]114 },115 "explosives": {116 unlocks: ["weapon_specialization"]117 },118 "sophontology": {},119 "xenobiology": {},120 "surgery": {},121 "cybernetics": {},122 "robotics": {},123 "artificial_intelligence": {},124 "command": {},125 "hyperspace": {},126 "xenoesotericism": {},127 "weapon_specialization": {}128};129130const skillArray = Object.keys(skillList);131132// FUNCTIONS133134const advantageToggle = (newValue) => {135136}137138const toggleSkill = (source, newValue) => {139140 getAttrs(["sheet_skill_toggles"], values => {141142 const existingValue = values["sheet_skill_toggles"].trim();143 const valueList = existingValue.split(" ")144 const unlocks = skillList[source].unlocks || [];145146 let updateAttr = "";147 148 if (newValue === "0") {149150 unlocks.forEach(item => valueList.splice(valueList.indexOf(item), 1));151152 updateAttr = valueList.join(" ");153154 } else if (newValue === "on") {155 156 updateAttr = existingValue + " ";157 158 if (unlocks === []) return;159 160 unlocks.forEach(unlock => updateAttr += `${unlock} `);161162 }163 164 setAttrs({sheet_skill_toggles:updateAttr}); 165 });166167}168169const addItem = (new_value, previous_value, source, source_type) => {170 if (new_value === previous_value || new_value !== "Weapon" || source_type !== "player") return;171172 console.log(source_type)173174 const repeating_length = "repeating_equipment_".length;175 const repeating_id_length = 20;176 const repeating_id = source.substring(repeating_length, repeating_length + repeating_id_length);177 const repeating_equipment_prefix = `repeating_equipment_${repeating_id}`;178 const new_repeating_id = generateRowID();179 const repeating_attacks_prefix = `repeating_attacks_${new_repeating_id}`;180181 const requestAttrs = [`${repeating_equipment_prefix}_equipment_name`,`${repeating_equipment_prefix}_equipment_type`];182183 getAttrs(requestAttrs, values => {184 const updateAttrs = {};185186 updateAttrs[`${repeating_attacks_prefix}_attack_name`] = values[`${repeating_equipment_prefix}_equipment_name`];187 updateAttrs[`${repeating_attacks_prefix}_attack_linkedid`] = repeating_id;188189 setAttrs(updateAttrs);190191 });192}193194const toggleClass = (new_class, previous_class, source_type) => {195 const requestAttrs = [196 "init",197 "level",198 "sanity",199 "fear",200 "body",201 "armor",202 "strength",203 "speed",204 "intellect",205 "combat",206 "stress_panic",207 ];208209 if (source_type !== "player") return;210211 const update = {};212213 update["level"] = 0;214 update["xp"] = 0;215 update["stress"] = 2;216 update["resolve"] = 0;217 update["init"] = 1;218219 switch (new_class.toLowerCase()) {220 case "teamster":221 update["sanity"] = 30;222 update["fear"] = 35;223 update["body"] = 30;224 update["armor"] = 35;225 update["strength"] = rollDice(6) + 5;226 update["speed"] = rollDice(6) + 5;227 update["intellect"] = rollDice(6);228 update["combat"] = rollDice(6);229 update["skill_points"] = 4;230 update["stress_panic"] = getTranslationByKey(["Once per session, a Teamster may re-roll a roll on the Panic Effect Table."]);231 break;232 case "android":233 update["sanity"] = 20;234 update["fear"] = 85;235 update["body"] = 40;236 update["armor"] = 25;237 update["strength"] = rollDice(6);238 update["speed"] = rollDice(6) + 5;239 update["intellect"] = rollDice(6) + 5;240 update["combat"] = rollDice(6);241 update["skill_points"] = 2;242 update["stress_panic"] = getTranslationByKey(["Fear Saves made in the presence of Androids have Disadvantage."]);243 break;244 case "scientist":245 update["sanity"] = 40;246 update["fear"] = 25;247 update["body"] = 25;248 update["armor"] = 30;249 update["strength"] = rollDice(6);250 update["speed"] = rollDice(6);251 update["intellect"] = rollDice(6) + 10;252 update["combat"] = rollDice(6);253 update["skill_points"] = 3;254 update["stress_panic"] = getTranslationByKey(["Whenever a Scientist fails a Sanity Save, every friendly player nearby gains 1 Stress."]);255 break;256 case "marine":257 update["sanity"] = 25;258 update["fear"] = 30;259 update["body"] = 35;260 update["armor"] = 40;261 update["strength"] = rollDice(6);262 update["speed"] = rollDice(6);263 update["intellect"] = rollDice(6);264 update["combat"] = rollDice(6) + 5;265 update["skill_points"] = 3;266 update["stress_panic"] = getTranslationByKey(["Whenever a Marine Panics, every friendly player nearby must make a Fear Save."]);267 break;268 default: 269 return;270 }271272 getAttrs(requestAttrs, values => {273274 if (previous_class === new_class && values["init"] === "1") return;275276 requestAttrs.forEach(attr => {277 if (values[attr] !== "") update[attr] = values[attr];278 })279280 if (values["level"] === 0 || values["level"] === "") {281282 const fields = [283 "level",284 "sanity",285 "fear",286 "body",287 "armor",288 "stress_panic",289 "stress",290 "resolve",291 "strength",292 "speed",293 "intellect",294 "combat",295 "skill_points",296 "xp",297 "init"298 ];299300 const updateAttrs = {};301302 fields.forEach(field => {303 const fallback = values[field] || 0;304 updateAttrs[field] = (typeof field !== undefined) ? update[field] : fallback;305 });306307 const hitpoints = parseInt(update["strength"]) * 2;308309 updateAttrs["health"] = hitpoints;310 updateAttrs["health_max"] = hitpoints;311312 setAttrs(updateAttrs);313314 }315316 });317}318319const rollDice = (number_of_dice) => {320 let total = 0;321322 for (let i = 0; i <= number_of_dice; i++) total += Math.ceil(Math.random()*10);323324 return total;325}326327const calculateRow = (row, new_value) => {328329 if (!row) return console.warn("Tried to update a ship row, but there wasn't a row specified");330331 const int_value = parseInt(new_value) || 0;332333 if (row === "lifesupport") setAttrs({"ship_lifesupport_modules":Math.ceil(int_value/10), life_support_hull:Math.ceil(int_value/10), ship_galleys: Math.ceil(int_value/20)});334 if (row === "command") setAttrs({"ship_command_modules":Math.ceil(int_value/4), command_hull:Math.ceil(int_value/4), ship_livingquarters:int_value});335 if (row === "armor") setAttrs({armor:Math.floor(int_value*10), armor_hull:Math.floor(int_value*3)});336 if (row === "jumpdrives") {337 let hull = 0;338 for (let i = 1; i <= int_value; i++) hull += i;339 setAttrs({jump_drives_hull:hull, ship_computer_modules:int_value});340 }341 if (row === "computer") setAttrs({computer_hull:int_value});342 if (row === "galley") setAttrs({galley_hull:int_value});343 if (row === "weaponmount") setAttrs({ship_weapon_mounts:int_value, weapon_mount_hull:int_value});344 if (row === "medbays") setAttrs({ship_medint_bonus:Math.floor(int_value*5), medical_bay_hull:int_value});345 if (row === "cryochamber") setAttrs({ship_cryochambers:Math.ceil(int_value/4), cryochamber_hull:Math.ceil(int_value/4)});346 if (row === "livingquarters") {setAttrs({living_quarters_hull:int_value})};347 if (row === "barracks") setAttrs({ship_barracks:Math.ceil(int_value/12), barracks_hull:Math.ceil(int_value/12), crew_max:int_value});348 if (row === "cargoholds") setAttrs({ship_cargoholds:Math.ceil(int_value/10), cargo_hold_hull:Math.ceil(int_value/10), cargo_max: int_value});349 if (row === "sciencelabs") setAttrs({ship_resint_bonus:Math.floor(int_value*5), science_lab_hull:int_value});350 if (row === "thrusters") {351 getAttrs(["ship_thruster_hullreq","ship_thrusters"], values => {352 const hullreq = parseInt(values["ship_thruster_hullreq"]) || 0;353 const thrusters = parseInt(values["ship_thrusters"]) || 0;354 setAttrs({thrusters_hull : hullreq + thrusters, ship_engine_thrusterreq: thrusters});355 });356 } 357 if (row === "fuel") { 358 getAttrs(["ship_fuel_min","ship_fuel_extra"], values => {359 const min_fuel = parseInt(values["ship_fuel_min"]) || 0;360 const extra_fuel = parseInt(values["ship_fuel_extra"]) || 0;361362 setAttrs({fuel_hull: min_fuel + extra_fuel});363 });364 }365 if (row === "engine") {366 getAttrs(["ship_engine_hullreq","ship_engine_thrusterreq","ship_jumpdrive_modules"], values => {367 const hullreq = parseInt(values["ship_engine_hullreq"]) || 0;368 const thrustreq = parseInt(values["ship_engine_thrusterreq"]) || 0;369 const jumpdrive = parseInt(values["ship_jumpdrive_modules"]) || 0;370371 setAttrs({ship_engine:hullreq + thrustreq + jumpdrive, engine_hull: hullreq + thrustreq + jumpdrive, ship_fuel_min: (hullreq + thrustreq + jumpdrive) * 3})372 }); 373 }374 if (row === "frame") setAttrs({frame_hull:int_value});375376}377378const recalculateBaseHull = () => {379 const base_hull_array = [380 "jump_drives_hull",381 "life_support_hull",382 "command_hull",383 "armor_hull",384 "jump_drive_hull",385 "computer_hull",386 "galley_hull",387 "weapon_mount_hull",388 "medical_bay_hull",389 "cryochamber_hull",390 "living_quarters_hull",391 "barracks_hull",392 "cargo_hold_hull",393 "science_lab_hull"394 ];395 396 getAttrs(base_hull_array, values => {397 const base_hull_int = Object.values(values).map(value => parseInt(value) || 0);398399 const base_hull = base_hull_int.reduce((total, value) => total + value);400401 setAttrs({ship_base_hull: base_hull, ship_thruster_hullreq: Math.ceil(base_hull / 10), ship_engine_hullreq: Math.ceil(base_hull / 20), ship_frame: Math.ceil(base_hull / 10)});402 });403}404405const recalculateTotalHull = () => {406 const total_hull_array = [407 "ship_base_hull", 408 "thrusters_hull", 409 "engine_hull", 410 "fuel_hull", 411 "frame_hull"412 ];413414 getAttrs(total_hull_array, values => {415 const total_hull_int = Object.values(values).map(value => parseInt(value) || 0);416 const total_hull = total_hull_int.reduce((total, value) => total + value);417418 setAttrs({ship_total_hull: total_hull});419 });420}421422const calculateCombatIntelligence = (new_value) => {423 const value = parseInt(new_value) || 0;424425 const combat = (value * 10) + 10;426 const intellect = (value * 10) + 30;427428 setAttrs({combat:combat,intellect:intellect});429}430431const calculateSpeed = (new_value) => {432 const value = parseInt(new_value) || 0;433434 const speed = value * 10;435436 setAttrs({speed:speed});437}438439const calculateHullCost = (new_value) => {440 const value = parseInt(new_value) || 0;441442 const hull = value;443 const cost = value * 10;444445 setAttrs({ship_cost:cost, hull: hull, hull_max: hull});446}447448const calculateFuel = (new_value) => {449 const value = parseInt(new_value) || 0;450451 setAttrs({fuel:value, fuel_max:value});452}453454const checkFuelValue = (new_value) => {455 const value = parseInt(new_value) || 0;456457 getAttrs(["hull_25","hull_50","hull_75"], values => {458 const hull_25 = values.hull_25;459 const hull_50 = values.hull_50;460 const hull_75 = values.hull_75;461462 let hull_toggle = "";463464 if (value <= hull_75) hull_toggle = 75; 465 else if (value <= hull_50) hull_toggle = 50; 466 else if (value <= hull_25) hull_toggle = 25;467 468 setAttrs({hull_toggle: hull_toggle});469 });470}471472const calculateHullValues = () => {473 getAttrs(["hull_max"], values => {474 const value = parseInt(values["hull_max"]) || 0;475 476 const n25 = Math.floor(value * 0.75);477 const n50 = Math.floor(value * 0.5);478 const n75 = Math.floor(value * 0.25);479 480 setAttrs({481 hull_25: n25,482 hull_50: n50,483 hull_75: n75,484 }, callback => checkFuelValue(value));485 });486}487488const dropHandler = (values) => {489 const name = values.drop_name;490 const data = JSON.parse(values.drop_data) || {};491 const category = values.drop_category;492493 console.log(data);494495 if (name === ""|| typeof data === "" || typeof category === "") return console.warn("No drag and drop data found.");496497 switch (category) {498 case "Classes": 499 handleClassDrop(name, data);500 break;501 case "Items":502 handleItemDrop(name, data);503 break;504 case "Mercenaries": 505 handleMercenaryDrop(name, data);506 break;507 case "Ships":508 handleShipDrop(name, data);509 break;510 case "Ship Weapons": 511 handleShipWeaponDrop(name, data);512 break;513 default:514 console.warn("Could not distinguish category from drop.")515 break;516 }517518}519520const handleItemDrop = (name, data) => {521 const id = generateRowID(); 522 const address = `repeating_equipment_${id}_equipment`;523524 let updateAttrs = {};525526 updateAttrs[`${address}_name`] = name;527 updateAttrs[`${address}_notes`] = data.Description || "";528529 if (data.Damage) {530 const attack_id = generateRowID();531 const attack_address = `repeating_attacks_${id}_attack`532533 updateAttrs[`${address}_type`] = "Weapon";534 updateAttrs[`${address}_linkedid`] = attack_id;535 536 updateAttrs[`${attack_address}_linkedid`] = id;537 updateAttrs[`${attack_address}_name`] = name;538 updateAttrs[`${attack_address}_damage`] = data.Damage;539 updateAttrs[`${attack_address}_critical_damage`] = data["Critical Damage"] || "";540 updateAttrs[`${attack_address}_critical_effect`] = data["Critical Effect"] || "-";541542 let combined_string = (data.Description) ? `${data.Description} ` : ``;543 combined_string += (data.Special) ? `${data.Special} ` : ``;544545 updateAttrs[`${attack_address}_notes`] = combined_string;546547 const range = JSON.parse(data.Range) || {};548549 if (range && range.CQC !== "Yes") {550 updateAttrs[`${attack_address}_type`] = "Ranged";551552 updateAttrs[`${attack_address}_shots`] = data.Shots;553 updateAttrs[`${attack_address}_ammunition`] = data.Ammunition;554555 updateAttrs[`${attack_address}_range_s`] = range.Short;556 updateAttrs[`${attack_address}_range_m`] = range.Medium || "-";557 updateAttrs[`${attack_address}_range_l`] = range.Long || "-";558559 } else {560 updateAttrs[`${attack_address}_type`] = "Melee"; 561 }562 } else if (data["Armor Save"]) {563 updateAttrs[`${address}_type`] = "Armor";564 updateAttrs[`${address}_armor_bonus`] = data["Armor Save"];565 } else {566 updateAttrs[`${address}_type`] = "Gear";567 }568569 setAttrs(updateAttrs);570571}572573const handleClassDrop = (name, data) => {574 setAttrs({class:name});575 if (name) toggleClass(name,"","player");576}577578const handleMercenaryDrop = () => {579 console.warn("Mercenary drop not yet supported.");580}581582const handleMonsterDrop = () => {583 console.warn("Monster drop not yet supported.");584}585586const handleShipDrop = (name, data) => {587 const modules_raw = data["Required Modules"].split(",").map(item => item.trim());588 const modules_parsed = {};589 const updateAttrs = {};590591 modules_raw.forEach(module => modules_parsed[module.toLowerCase().replace(/[^a-z ]/g,"").trim().replace(/ /g,"_")] = parseInt(module.replace(/[^0-9]/g,"")) || 0);592593 console.log(modules_parsed);594595 updateAttrs["ship_class"] = name;596 updateAttrs["ship_passengers"] = ((modules_parsed.barracks || 0) * 12) + modules_parsed.living_quarters || 1;597 updateAttrs["life_support"] = modules_parsed.life_support || 1;598 updateAttrs["ship_officers"] = modules_parsed.living_quarters || 0;599 updateAttrs["ship_armor_modules"] = modules_parsed.armor || 0;600 updateAttrs["ship_jumpdrive_modules"] = modules_parsed.jump_drive || 0;601 updateAttrs["ship_computer_modules"] = modules_parsed.computer || 0;602 updateAttrs["ship_galley"] = modules_parsed.galley || "";603 updateAttrs["ship_weapon_mounts"] = modules_parsed.weapon_mount || 0;604 updateAttrs["ship_medbays"] = modules_parsed.medical_bays || 0;605 updateAttrs["ship_cyropods"] = (modules_parsed.cryochamber * 4) || 0;606 updateAttrs["ship_living_quarters"] = modules_parsed.living_quarters || 0;607 updateAttrs["ship_barracks"] = modules_parsed.barracks || 0;608 updateAttrs["ship_cargoholds"] = modules_parsed.cargo_hold || 0;609 updateAttrs["ship_sciencelabs"] = modules_parsed.science_lab || 0;610 updateAttrs["ship_thrusters"] = modules_parsed.thrusters || 0;611 updateAttrs["ship_engine"] = modules_parsed.engine || 0;612 613 console.log(updateAttrs);614 setAttrs(updateAttrs); 615}616617const handleShipWeaponDrop = () => {618619}620621// EVENT HANDLERS622623skillArray.forEach(skill => on(`change:${skill}`, eventInfo => toggleSkill(skill, eventInfo.newValue)));624625on(`change:repeating_equipment:equipment_type`, eventInfo => addItem(eventInfo.newValue, eventInfo.previousValue, eventInfo.sourceAttribute, eventInfo.sourceType));626627on(`change:class`, eventInfo => toggleClass(eventInfo.newValue, eventInfo.previousValue, eventInfo.sourceType));628629on(`change:ship_passengers`, eventInfo => calculateRow("lifesupport", eventInfo.newValue));630on(`change:ship_officers`, eventInfo => calculateRow("command", eventInfo.newValue));631on(`change:ship_armor_modules`, eventInfo => calculateRow("armor", eventInfo.newValue));632on(`change:ship_jumpdrive_modules`, eventInfo => calculateRow("jumpdrives", eventInfo.newValue));633on(`change:ship_computer_modules`, eventInfo => calculateRow("computer", eventInfo.newValue));634on(`change:ship_galleys`, eventInfo => calculateRow("galley", eventInfo.newValue));635on(`change:ship_weapons`, eventInfo => calculateRow("weaponmount", eventInfo.newValue));636on(`change:ship_medbays`, eventInfo => calculateRow("medbays", eventInfo.newValue));637on(`change:ship_cryopods`, eventInfo => calculateRow("cryochamber", eventInfo.newValue));638on(`change:ship_livingquarters`, eventInfo => calculateRow("livingquarters", eventInfo.newValue));639on(`change:ship_crew`, eventInfo => calculateRow("barracks", eventInfo.newValue));640on(`change:ship_cargo`, eventInfo => calculateRow("cargoholds", eventInfo.newValue)); 641on(`change:ship_sciencelabs`, eventInfo => calculateRow("sciencelabs", eventInfo.newValue)); 642on(`change:ship_thrusters change:ship_thruster_hullreq`, eventInfo => calculateRow("thrusters", eventInfo.newValue)); 643on(`change:ship_fuel_extra change:ship_fuel_min`, eventInfo => calculateRow("fuel", eventInfo.newValue));644on(`change:ship_engine_hullreq change:ship_engine_thrusterreq change:ship_jumpdrive_modules`, eventInfo => calculateRow("engine", eventInfo.newValue));645on(`change:ship_frame`, eventInfo => calculateRow("frame", eventInfo.newValue));646647on(`change:ship_computer_modules`, eventInfo => calculateCombatIntelligence(eventInfo.newValue));648on(`change:ship_thrusters`, eventInfo => calculateSpeed(eventInfo.newValue));649on(`change:ship_total_hull`, eventInfo => calculateHullCost(eventInfo.newValue));650on(`change:fuel_hull`, eventInfo => calculateFuel(eventInfo.newValue));651652on(`change:hull`, eventInfo => checkFuelValue(eventInfo.newValue));653on(`change:hull_max`, eventInfo => calculateHullValues());654655on(`clicked:startship`, eventInfo => setAttrs({shipbuild:"on"}));656on(`clicked:completeship`, eventInfo => setAttrs({shipbuild:0}));657658on(`clicked:editname_on`, eventInfo => setAttrs({npcname_toggle:"on"}));659on(`clicked:editname_off`, eventInfo => setAttrs({npcname_toggle:0}));660661on("change:drop_name", (eventInfo) => {662 getAttrs(["drop_name", "drop_content", "drop_data", "drop_category"], (values) => {663 dropHandler(values);664 });665});666667["life_support_hull","command_hull","armor_hull","jump_drives_hull","computer_hull","galley_hull",668"weapon_mount_hull","medical_bay_hull","cryochamber_hull","living_quarters_hull","barracks_hull",669"cargo_hold_hull", "science_lab_hull"].forEach(hull => on(`change:${hull}`, eventInfo => recalculateBaseHull()));670 ...

Full Screen

Full Screen

dragndrop.js

Source:dragndrop.js Github

copy

Full Screen

1const wfrpDragAndDrop = ( () => {2 const handleDrop = (values, overwrite = false) => {3 const {drop_name, drop_content, drop_data} = values;4 if (drop_name === ""|| typeof drop_data === "") return;5 6 let parsed_data = helperFunctions.parseJSON(drop_data);7 if (parsed_data.Category === "Careers") handleCareer(drop_name, parsed_data);8 else if (parsed_data.Category === "Blessings" || parsed_data.Category === "Spells" || parsed_data.Category === "Miracles" ) handleSpell(drop_name, parsed_data, drop_content);9 else if (parsed_data.Category === "Items") handleItem(drop_name, parsed_data);10 else if (parsed_data.Category === "Monsters") handleMonster(drop_name, parsed_data, drop_content);11 else if (parsed_data.Category === "Talents") handleTalent(drop_name, parsed_data);12 else if (parsed_data.Category === "Conditions") handleCondition(drop_name, parsed_data);13 else if (parsed_data.Category === "Creature Traits") handleCreatureTrait(drop_name, parsed_data);14 else console.warn(`${parsed_data.Category} drop is not supported by the sheet`);15 setAttrs({drop_name: "", drop_content: "", drop_data: ""});16 17 }18 const handleCareer = (name, data) => {19 const updateAttrs = {};20 const repeating_id = generateRowID();21 const row = `repeating_careers_${repeating_id}`;22 updateAttrs[`class`] = data.Class;23 updateAttrs[`${row}_career_name`] = name;24 Object.entries(data.blobs).forEach(([key, values], index) => {25 const level = values.Level26 updateAttrs[`${row}_career_level${level}_name`] = key;27 updateAttrs[`${row}_career_level${level}_status`] = `${values.Tier} ${values.Standing}`;28 updateAttrs[`${row}_career_${level}_trappings`] = values.Trappings;29 const talents = values.Talents.split(",").map(item => item.trim());30 talents.forEach((talent, index) => {31 updateAttrs[`${row}_career_talent_${level}_${index+1}_name`] = talent;32 });33 const skills = values.Skills.split(",").map(item => item.trim());34 skills.forEach((skill, index) => {35 updateAttrs[`${row}_career_skill_${level}_${index+1}_name`] = skill;36 });37 const characteristics = helperFunctions.parseJSON(values["Characteristic Advances"]);38 Object.entries(characteristics).forEach(([key,value]) => {39 if (value.toLowerCase() === "true") {40 const characteristic = key.toLowerCase().replace(/ /g,"_");41 updateAttrs[`${row}_career_${characteristic}`] = level;42 }43 });44 setAttrs(updateAttrs);45 });46 }47 const handleSpell = (name, data) => {48 const updateAttrs = {};49 const repeating_id = generateRowID();50 const row = `repeating_spells_${repeating_id}`;51 52 updateAttrs[`${row}_spell_name`] = name;53 updateAttrs[`${row}_spell_type`] = (data.Category.toLowerCase() === "spells") ? "Spell" : "Prayer";54 updateAttrs[`${row}_spell_cn`] = data["Casting Number"] || 0;55 updateAttrs[`${row}_spell_range`] = data.Range || 0;56 updateAttrs[`${row}_spell_target`] = data.Target || 0;57 updateAttrs[`${row}_spell_duration`] = data.Duration || 0;58 updateAttrs[`${row}_spell_description`] = data.Description || 0;59 updateAttrs[`${row}_spell_lore`] = data.Lore || "";60 updateAttrs[`${row}_spell_diety`] = data.Deity || "";61 setAttrs(updateAttrs);62 }63 const handleItem = (name, data) => {64 const updateAttrs = {};65 if (data.Subcategory === "Armour") {66 const repeating_id = generateRowID();67 const row = `repeating_armour_${repeating_id}`;68 const armour = helperFunctions.parseJSON(data.Armor);69 const points = armour.Points || 0;70 const locations = [];71 Object.entries(armour).forEach(([key, value]) => {72 if (value === "Yes") locations.push(key);73 });74 updateAttrs[`${row}_armour_name`] = name;75 updateAttrs[`${row}_armour_points`] = points;76 updateAttrs[`${row}_armour_qualities`] = data.Traits || "";77 updateAttrs[`${row}_armour_locations`] = locations.join(", ").replace(/Torso/g,"Body");78 updateAttrs[`${row}_armour_enc`] = data.Encumbrance;79 updateAttrs[`${row}_armour_mods`] = data.Modifiers || "";80 updateAttrs[`${row}_armour_desc`] = data.Notes || "";81 } else if (data.Subcategory === "Weapons") {82 const repeating_id = generateRowID();83 const row = `repeating_weapons_${repeating_id}`;84 updateAttrs[`${row}_weapon_name`] = name;85 updateAttrs[`${row}_weapon_group`] = data.Group;86 updateAttrs[`${row}_weapon_range`] = (data.Range) ? data.Range : data.Reach || "";87 updateAttrs[`${row}_weapon_damage_flat`] = data.Damage.replace(/[^0-9]/g,"");88 updateAttrs[`${row}_weapon_damage_bonus`] = (data.Damage.match(/SB/)) ? "on" : "0";89 updateAttrs[`${row}_weapon_qualities`] = data.Traits || "";90 updateAttrs[`${row}_weapon_enc`] = data.Encumbrance || "0";91 updateAttrs[`${row}_weapon_notes`] = data.Notes || ""; 92 updateAttrs[`${row}_weapon_mods`] = data.Modifiers || "";93 } else {94 const repeating_id = generateRowID();95 const row = `repeating_trappings_${repeating_id}`;96 const modifiers = [];97 if (data.Modifiers) modifiers.push(data.Modifiers);98 if (data.Carries) modifiers.push(`Encumbrance +${data.Carries}`);99 updateAttrs[`${row}_trappings_name`] = name;100 updateAttrs[`${row}_trappings_amount`] = data["Number"] || 1;101 updateAttrs[`${row}_trappings_enc`] = data.Encumbrance || 1;102 updateAttrs[`${row}_trappings_inenc`] = "on";103 updateAttrs[`${row}_trappings_mods`] = modifiers.join(", ") || "";104 updateAttrs[`${row}_trappings_traits`] = data.Traits || "";105 updateAttrs[`${row}_trappings_description`] = data.Notes || "";106 updateAttrs[`${row}_trappings_type`] = (data.Subcategory === "Ammunition") ? 1 : 107 (data.Subcategory === "Packs and Containers") ? 2 : 108 (data.Subcategory === "Clothing and Accessories") ? 3 : 109 (data.Subcategory === "Tools and Kits") ? 4 : 110 (data.Subcategory === "Books and Documents") ? 5 : 111 (data.Subcategory === "Trade Tools and Workshops") ? 6 : 112 (data.Subcategory === "Animals and Vehicles") ? 7 : 113 (data.Subcategory === "Drugs and Poisons") ? 8 : 114 (data.Subcategory === "Herbs and Draughts") ? 9 : 115 (data.Subcategory === "Prosthetics") ? 10 : 116 11;117 } 118 setAttrs(updateAttrs);119 }120 const handleMonster = (name, data, content) => {121 let updateAttrs = {};122 const characteristics = helperFunctions.parseJSON(data.Characteristics);123 const traits = data["Traits"].split(/, (?![^\(]*\))/).map(item => item.trim());124 const optional = (data["Optional Traits"]) ? data["Optional Traits"].split(/, (?![^\(]*\))/).map(item => item.trim()) : [];125 updateAttrs[`character_name`] = name;126 updateAttrs[`npc_description`] = data.Description || "";127 updateAttrs[`npc`] = "on";128 if (!data.Trappings) updateAttrs[`npc_trappings_flag`] = 0;129 if (!data.Skills) updateAttrs[`npc_skills_flag`] = 0;130 for (const characteristic in characteristics) {131 updateAttrs[characteristic.replace(/ /g,"_")] = characteristics[characteristic];132 } 133 const trait_map = new Map();134 for (const trait of traits) {135 trait_map.set(136 parseTrait(trait.trim()),137 trait.trim()138 );139 }140 const trait_map_opt = new Map();141 for (const trait of optional) {142 trait_map_opt.set(143 parseTrait(trait.trim()),144 trait.trim()145 );146 }147 const request = [...trait_map.keys(), ...trait_map_opt.keys()].map(item => `Creature Traits:${item}`);148 getCompendiumPage(request, compendium_pages => {149 150 for (const page in compendium_pages) {151 const repeating_id = generateRowID();152 const trait = compendium_pages[page];153 if (trait_map.get(trait.name)) {154 const trait_name = trait_map.get(trait.name);155 if (trait_name.match(/(weapon|ranged|tentacle|bite|horn|tail|tongue)/gi)) {156 const attack = parseAttack(trait_map.get(trait.name), trait.data.Description);157 158 updateAttrs = {...updateAttrs, ...attack};159 } else {160 const row = `repeating_traits_${repeating_id}`;161 162 updateAttrs[`${row}_trait_name`] = trait_map.get(trait.name);163 updateAttrs[`${row}_trait_enabled`] = "on";164 updateAttrs[`${row}_trait_settings`] = 0;165 updateAttrs[`${row}_trait_description`] = trait.data.Description;166 }167 } else if (trait_map_opt.get(trait.name)) {168 const trait_name = trait_map_opt.get(trait.name);169 if (trait_name.match(/(weapon|ranged|tentacle|bite|horn|tail|tongue)/gi)) {170 const attack = parseAttack(trait_map_opt.get(trait.name), trait.data.Description, "(Optional)");171 172 updateAttrs = {...updateAttrs, ...attack};173 } else {174 const row = `repeating_optional-traits_${repeating_id}`;175 176 updateAttrs[`${row}_trait_name`] = trait_map_opt.get(trait.name);177 updateAttrs[`${row}_trait_settings`] = 0;178 updateAttrs[`${row}_trait_description`] = trait.data.Description;179 }180 }181 }182 getSectionIDs("repeating_traits", idarray => {183 for (const id of idarray) removeRepeatingRow(`repeating_traits_${id}`);184 getSectionIDs("repeating_optional-traits", idarray => {185 186 for (const id of idarray) removeRepeatingRow(`repeating_optional-traits_${id}`); 187 getSectionIDs("repeating_attacks", idarray => {188 189 for (const id of idarray) removeRepeatingRow(`repeating_attacks_${id}`);190 191 for (const key in updateAttrs) { 192 if (updateAttrs[key] === null || updateAttrs[key] === undefined) delete updateAttrs[key];193 }194 195 setAttrs(updateAttrs, callback => setTokenValues())196 197 });198 199 });200 });201 });202 }203 const parseTrait = (trait) => {204 trait = (trait.match(/Tentacles/gi)) ? "# Tentacles (Rating)" :205 (trait.match(/Afraid/gi)) ? "Afraid (Target)" :206 (trait.match(/Animosity/gi)) ? "Animosity (Target)" :207 (trait.match(/Armour/gi)) ? "Armour (Rating)" :208 (trait.match(/Bite/gi)) ? "Bite (Rating)" :209 (trait.match(/Blessed/gi)) ? "Blessed (Various)" :210 (trait.match(/Breath (.*?) (Cold)/gi)) ? "Breath Rating (Cold)" :211 (trait.match(/Breath (.*?) (Corrosion)/gi)) ? "Breath Rating (Corrosion)" :212 (trait.match(/Breath (.*?) (Fire)/gi)) ? "Breath Rating (Fire)" :213 (trait.match(/Breath (.*?) (Electricity)/gi)) ? "Breath Rating (Electricity)" :214 (trait.match(/Breath (.*?) (Poison)/gi)) ? "Breath Rating (Poison)" :215 (trait.match(/Breath (.*?) (Smoke)/gi)) ? "Breath Rating (Smoke)" :216 (trait.match(/Breath/gi)) ? "Breath Rating (Type)" :217 (trait.match(/Corruption/gi)) ? "Corruption (Strength)" :218 (trait.match(/Daemonic/gi)) ? "Daemonic (Target)" :219 (trait.match(/Disease/gi)) ? "Disease (Type)" :220 (trait.match(/Fear/gi)) ? "Fear (Rating)" :221 (trait.match(/Flight/gi)) ? "Flight (Rating)" :222 (trait.match(/Hatred/gi)) ? "Hatred (Target)" :223 (trait.match(/Horns/gi)) ? "Horns Rating (Feature)" :224 (trait.match(/Immunity/gi)) ? "Immunity (Type)" :225 (trait.match(/Magic Resistance/gi)) ? "Magic Resistance (Rating)" :226 (trait.match(/Miracles/gi)) ? "Miracles (Various)" :227 (trait.match(/Night Vision/gi)) ? "Night Vision" :228 (trait.match(/Prejudice/gi)) ? "Prejudice (Target)" :229 (trait.match(/Ranged/gi)) ? "Ranged Rating (Range)" :230 (trait.match(/Spellcaster/gi)) ? "Spellcaster (Various)" :231 (trait.match(/Tail/gi)) ? "Tail Attack (Rating)" :232 (trait.match(/Terror/gi)) ? "Terror (Rating)" :233 (trait.match(/Tongue Attack/gi)) ? "Tongue Attack (Rating) (Range)" :234 (trait.match(/Trained/gi)) ? "Trained (Trained Skills)" :235 (trait.match(/Venom/gi)) ? "Venom (Rating)" :236 (trait.match(/Terror/gi)) ? "Terror (Rating)" :237 (trait.match(/Ward/gi)) ? "Ward (Rating)" :238 (trait.match(/Weapon/gi)) ? "Weapon (Rating)" :239 (trait.match(/Web/gi)) ? "Web (Rating)" :240 (trait.match(/Tiny/gi)) ? "Tiny" :241 (trait.match(/Little/gi)) ? "Little" :242 (trait.match(/Small/gi)) ? "Small" :243 (trait.match(/Average/gi)) ? "Average" :244 (trait.match(/Large/gi)) ? "Large" :245 (trait.match(/Enormous/gi)) ? "Enormous" :246 (trait.match(/Monstrous/gi)) ? "Monstrous" :247 `${trait}`;248 return trait;249 }250 const parseAttack = (trait, description, append = "") => {251 const attacks = ["weapon","ranged","tentacle","bite","horn","tail","tongue"];252 const updateAttrs = {};253 const repeating_id = generateRowID();254 const row = `repeating_attacks_${repeating_id}`;255 for (const attack of attacks) {256 const expression = new RegExp(attack,"gi");257 let name = trait;258 let damage = "";259 let type = "Weapon Skill";260 let range = "Touch";261 let attacks = "1";262 if (trait.match(expression)) {263 264 if (trait.match(/range/gi) && trait.match(/\(/)) {265 [trait, range] = trait.split("(");266 range = range.substr(0,range.length-1);267 type = "Ballistic Skill";268 }269 270 if (trait.match(/[0-9]+X/)) {271 attacks = trait.match(/([0-9]+)X/)[1];272 }273 274 if (trait.match(/\+/)) {275 [name, damage] = trait.split("+");276 } 277 updateAttrs[`${row}_attack_settings`] = "0"; 278 updateAttrs[`${row}_attack_name`] = `${name} ${append}`; 279 updateAttrs[`${row}_attack_damage`] = damage;280 updateAttrs[`${row}_attack_type`] = type;281 updateAttrs[`${row}_attack_range`] = range; 282 updateAttrs[`${row}_attack_attacks`] = attacks; 283 updateAttrs[`${row}_attack_description`] = description; 284 } 285 }286 return updateAttrs;287 }288 const handleTalent = (name, data) => {289 const updateAttrs = {};290 const repeating_id = generateRowID();291 const row = `repeating_talent_${repeating_id}`;292 updateAttrs[`${row}_talent_name`] = name;293 updateAttrs[`${row}_talent_ranks`] = 1;294 updateAttrs[`${row}_talent_description`] = data.Description || "";295 updateAttrs[`${row}_talent_modifiers`] = data.Modifiers || "";296 297 const attrs = [];298 wfrpModule.wfrp.characteristics.forEach(characteristic => {299 attrs.push(characteristic);300 attrs.push(`${characteristic}_bonus`);301 });302 getAttrs(attrs, values => {303 const key_array = Object.keys(values);304 let total = 0;305 key_array.forEach(key => {306 const parsed = helperFunctions.capitalizeString(key.replace(/_/g, " "));307 if (data.Max.trim() === parsed) total += parseInt(values[key]);308 });309 const max = (!isNaN(parseInt(data.Max))) ? data.Max :310 (data.Max === "None") ? "-" :311 total;312 313 updateAttrs[`${row}_talent_ranks_max`] = max;314 setAttrs(updateAttrs);315 });316 }317 const handleCondition = (name, data) => {318 const updateAttrs = {};319 const attrs = [];320 getSectionIDs("conditions", id_array => {321 id_array.forEach(id => {322 attrs.push(`repeating_conditions_${id}_condition_name`); 323 });324 getAttrs(attrs, values => {325 const values_array = Object.entries(values);326 const values_test = Object.values(values);327 328 if (values_test.indexOf(name) > -1) {329 if (data.Stackable === "TRUE") {330 const key = values_array[values_test.indexOf(name)][0];331 const rank_attr = key.substring(0, key.length-4) + "ranks";332 333 getAttrs([rank_attr], values => {334 const rank = parseInt(values[rank_attr]) + 1 || 1;335 336 setAttrs({[rank_attr]:rank});337 });338 }339 } else {340 341 const repeating_id = generateRowID();342 const row = `repeating_conditions_${repeating_id}`;343 updateAttrs[`${row}_condition_name`] = name;344 updateAttrs[`${row}_condition_ranks`] = 1;345 updateAttrs[`${row}_condition_gpenalty`] = data["Global Test Modifier"] || "";346 updateAttrs[`${row}_condition_description`] = data.Description || "";347 setAttrs(updateAttrs);348 }349 });350 });351 }352 const handleCreatureTrait = (name, data) => {353 let updateAttrs = {};354 const attrs = [];355 const request = `Creature Traits:${parseTrait(name)}`;356 getCompendiumPage(request, compendium_pages => {357 const trait = compendium_pages;358 359 if (trait.name.match(/(weapon|ranged|tentacle|bite|horn|tail|tongue|claw)/gi)) {360 361 const attack = parseAttack(name, trait.data.Description);362 363 updateAttrs = {...updateAttrs, ...attack};364 365 } else if (trait) {366 const repeating_id = generateRowID(); 367 const row = `repeating_traits_${repeating_id}`;368 369 updateAttrs[`${row}_trait_name`] = name;370 updateAttrs[`${row}_trait_enabled`] = "on";371 updateAttrs[`${row}_trait_settings`] = 0;372 updateAttrs[`${row}_trait_description`] = trait.data.Description; 373 }374 375 setAttrs(updateAttrs);376 });377 }378 const setTokenValues = () => {379 380 const token_values = [];381 for (const index of [1,2,3]) {382 token_values.push(`bar${index}_v`);383 token_values.push(`bar${index}_m`);384 token_values.push(`bar${index}_l`);385 }386 getAttrs(token_values, settings => {387 388 const default_attr = {389 width: 70,390 height: 70391 };392 const attrs = [];393 for (const item in settings) {394 attrs.push(settings[item]);395 }396 getAttrs(attrs, values => {397 for (const item in settings) { 398 if (settings[item] !== "") {399 default_attr[item] = settings[item];400 }401 402 if (values[settings[item]]) {403 default_attr[item] = values[settings[item]];404 }405 }406 for (const item in default_attr) {407 if (item.match("_v")) {408 default_attr[`${item}alue`] = default_attr[item];409 delete default_attr[item]410 }411 if (item.match("_m")) {412 default_attr[`${item}ax`] = default_attr[item];413 delete default_attr[item]414 }415 if (item.match("_l")) {416 default_attr[`${item}ink`] = default_attr[item];417 delete default_attr[item]418 }419 }420 421 setDefaultToken(default_attr);422 });423 });424 }425 return {426 handleDrop:handleDrop427 }428})();429on("change:drop_name", (eventInfo) => {430 getAttrs(["drop_name", "drop_content", "drop_data"], (values) => {431 wfrpDragAndDrop.handleDrop(values); 432 });...

Full Screen

Full Screen

site.js

Source:site.js Github

copy

Full Screen

1import $ from 'zepto';2import { refresh } from '@squarespace/controller';3import { Lifecycle, Tweak, ImageLoader } from '@squarespace/core';4import Mercury from '@squarespace/mercury';5import Darwin from '../libs/custom/darwin';6let element;7let $element;8function site(e) {9 element = e;10 $element = $(element);11 loadAJAX();12 $(loadImages);13 $element.on('load', loadImages);14 // Prevent link events reaching `body` when `a` descendents are being edited in CMS.15 $element.find('body > *').on('click', 'a .sqs-editing', false);16}17// Exceptions: external links, hash links18const onClickExceptions = ['[data-no-ajax]'];19// Exceptions after making the request. Does a string match for any of these20// in the responseText21const onRequestExceptions = [];22// updateMatrix indicates which elements need to be updated on load. You can23// choose whether to update attributes, replace HTML, or both.24const updateMatrix = [25 // This would be nice, but won;t work as Mercury only queries for the first selector26 // { selector: '[yr-ajax~=html]', updateHTML: true },27 // { selector: '[yr-ajax~=attrs]', updateAttrs: true },28 // { selector: '[yr-ajax~=script]', updateScript: true },29 { selector: 'html', updateAttrs: true },30 { selector: 'title', updateHTML: true },31 { selector: 'meta[property="og:title"]', updateAttrs: true },32 { selector: 'meta[property="og:latitude"]', updateAttrs: true },33 { selector: 'meta[property="og:longitude"]', updateAttrs: true },34 { selector: 'meta[property="og:url"]', updateAttrs: true },35 { selector: 'meta[property="og:type"]', updateAttrs: true },36 { selector: 'meta[property="og:description"]', updateAttrs: true },37 { selector: 'meta[property="og:image"]', updateAttrs: true },38 { selector: 'meta[itemprop="name"]', updateAttrs: true },39 { selector: 'meta[itemprop="url"]', updateAttrs: true },40 { selector: 'meta[itemprop="description"]', updateAttrs: true },41 { selector: 'meta[itemprop="thumbnailUrl"]', updateAttrs: true },42 { selector: 'meta[itemprop="image"]', updateAttrs: true },43 { selector: 'meta[name="twitter:title"]', updateAttrs: true },44 { selector: 'meta[name="twitter:image"]', updateAttrs: true },45 { selector: 'meta[name="twitter:url"]', updateAttrs: true },46 { selector: 'meta[name="twitter:card"]', updateAttrs: true },47 { selector: 'meta[name="twitter:description"]', updateAttrs: true },48 { selector: 'meta[name="twitter:url"]', updateAttrs: true },49 { selector: 'meta[name="description"]', updateAttrs: true },50 { selector: 'link[rel="canonical"]', updateAttrs: true },51 { selector: 'link[rel="image_src"]', updateAttrs: true },52 { selector: 'link[rel="alternate"]', updateAttrs: true },53 { selector: '.yr-colors-theme-on', updateHTML: true },54 { selector: '.yr-colors-theme-nav', updateHTML: true },55 { selector: 'body', updateAttrs: true },56 { selector: '.yr-main', updateAttrs: true, updateHTML: true },57 { selector: '.yr-nav .yr-nav-links', updateAttrs: true, updateHTML: true }58];59/**60 * Instantiates a mercury loader for the site in unauthenticated sessions.61 */62function loadAJAX() {63 const ajaxEnabled = Tweak.getValue('tweak-yr-ajax-enable') === 'true';64 // Don't use ajax in authenticated session or when tweak option is disabled.65 // if ((!debug && authenticated) || !ajaxEnabled) {66 if (!ajaxEnabled) {67 return false;68 }69 // Give enough time for any animations to finish.70 const waitTime = Math.max(waitFade.bar(), waitFade.content());71 const mercury = new Mercury({72 enableCache: true,73 updateMatrix,74 onClickExceptions,75 onRequestExceptions,76 timeout: 10000,77 onLoadDelay: waitTime78 });79 const stages = {80 navigate() {81 $element.attr('data-yr-ajax-loading', 'navigate');82 // Close the navigation menu if it's open.83 $element.find('.yr-nav-toggler').prop('checked', false);84 },85 unload() {86 Lifecycle.destroy();87 $element.attr('data-yr-ajax-loading', 'unload');88 },89 swap() {90 // Mercury doesn't control the data attribute - add a phase...91 $element.attr('data-yr-ajax-loading', 'swap');92 Lifecycle.init();93 loadImages();94 refresh();95 setTimeout(stages.load, 0);96 setTimeout(stages.fin, waitTime);97 },98 load: () => $element.attr('data-yr-ajax-loading', 'load'),99 fin: () => $element.removeAttr('data-yr-ajax-loading')100 };101 window.addEventListener('mercury:navigate', stages.navigate);102 // Squarespace init and destroy103 window.addEventListener('mercury:unload', stages.unload);104 window.addEventListener('mercury:load', stages.swap);105}106const loadImages = () =>107 $element.find('img[data-src]').not('.loaded, [src]:not([src=""])')108 .each((i, image) => ImageLoader.load(image, { load: true }));109/**110 * Refresh controllers when CMS edits have occurred.111 * (Otherwise we'll be referencing detached DOM.)112 */113const darwin = new Darwin({114 callback(mutations) {115 if(mutations.some((mutation) => mutation.type === 'childList')) {116 refresh();117 }118 },119 targets: ['.sqs-layout']120});121darwin.init();122const timeUnitsMap = {123 'ms': 1,124 's': 1000125};126const waitFade = {127 bar: () => ((Tweak.getValue('tweak-yr-loader-show'))? 500 : 0),128 content() {129 let wait = 0;130 const flagTweak = Tweak.getValue('tweak-yr-fade-page');131 if(flagTweak && !flagTweak.match(/nah/gi)) {132 const timeTweak = (Tweak.getValue('tweak-yr-fade-page-time') || '');133 // Style Editor screws up this time units - fallback.134 const units = (timeTweak.match(/[a-zA-Z]*/gi) || '').join('');135 const time = ((units in timeUnitsMap)?136 parseFloat(timeTweak, 10)*timeUnitsMap[units]137 // Ensure this value is the same as `@yr-fade-page-time` in `styles/vars.less`138 : 600);139 140 // console.log('tweak-yr-fade-page-time', timeTweak, time);141 wait = ((flagTweak.match(/simple/gi))?142 time143 : ((flagTweak.match(/fancy/gi))?144 time * 2145 : 0));146 }147 return (wait || 0);148 }149};...

Full Screen

Full Screen

7-final.js

Source:7-final.js Github

copy

Full Screen

1const clearSheet = (data) => {2 const clearAttrs = {};3 const all_repeating_sections = ["equipment", "attacks"];4 all_repeating_sections.forEach(section => {5 getSectionIDs(`repeating_${section}`, ids => {6 ids.forEach(id => {7 removeRepeatingRow(`repeating_${section}_${id}`);8 });9 });10 });11 for (skill in skillList) {12 clearAttrs[skill] = "0";13 }14 setAttrs(clearAttrs,{silent:true}, callback => compileCharacter(data));15}16const compileCharacter = (data) => {17 18 const updateAttrs = {};19 ["armor","body","class","combat","credits","fear","intellect","patch","sanity","speed","strength","trinket","stress","resolve"].forEach(item => {20 updateAttrs[item] = data?.review?.values?.[`${item}_final`] || "";21 });22 23 updateAttrs["stress_panic"] = data?.review?.values?.[`stressresponse_final`] || "";24 updateAttrs["health"] = data?.review?.values?.[`health_final`] || "";25 updateAttrs["health_max"] = data?.review?.values?.[`health_final`] || "";26 updateAttrs["skill_points"] = data?.review?.values?.[`skillpoints_final`] || "";27 updateAttrs["level"] = "0";28 updateAttrs["xp"] = "0";29 if (parseJSON(data?.review?.values?.skills_final)) {30 parseJSON(data.review.values.skills_final).forEach(skill => {31 updateAttrs[skill] = "on";32 });33 }34 if (parseJSON(data?.review?.values?.equipment_final)) {35 const request = [];36 parseJSON(data.review.values.equipment_final).forEach(item => {37 if (Array.isArray(item)) {38 request.push(item[0]);39 } else {40 request.push(item);41 }42 });43 getCompendiumPage(request, pages => {44 45 pages.forEach(data => {46 console.log(data);47 const id = generateRowID(); 48 const address = `repeating_equipment_${id}_equipment`;49 50 updateAttrs[`${address}_name`] = data.name;51 updateAttrs[`${address}_notes`] = data.Special || "";52 updateAttrs[`${address}_settings`] = "0";53 54 if (data.data.Damage) {55 const attack_id = generateRowID();56 const attack_address = `repeating_attacks_${id}_attack`57 58 updateAttrs[`${address}_type`] = "Weapon";59 updateAttrs[`${address}_linkedid`] = attack_id;60 61 updateAttrs[`${attack_address}_linkedid`] = id;62 updateAttrs[`${attack_address}_name`] = data.name;63 updateAttrs[`${attack_address}_damage`] = data.data.Damage;64 updateAttrs[`${attack_address}_critical_damage`] = data.data["Critical Damage"] || "";65 updateAttrs[`${attack_address}_critical_effect`] = data.data["Critical Effect"] || "-";66 updateAttrs[`${attack_address}_settings`] = "0";67 68 let combined_string = (data.data.Description) ? `${data.data.Description} ` : ``;69 combined_string += (data.data.Special) ? `${data.data.Special} ` : ``;70 71 updateAttrs[`${attack_address}_notes`] = combined_string;72 73 const range = JSON.parse(data.data.Range) || {};74 75 if (range && range.CQC !== "Yes") {76 updateAttrs[`${attack_address}_type`] = "Ranged";77 78 updateAttrs[`${attack_address}_shots`] = data.data.Shots;79 updateAttrs[`${attack_address}_ammunition`] = data.data.Ammunition;80 81 updateAttrs[`${attack_address}_range_s`] = range.Short;82 updateAttrs[`${attack_address}_range_m`] = range.Medium || "-";83 updateAttrs[`${attack_address}_range_l`] = range.Long || "-";84 85 } else {86 updateAttrs[`${attack_address}_type`] = "Melee"; 87 }88 } else if (data["Armor Save"]) {89 updateAttrs[`${address}_type`] = "Armor";90 updateAttrs[`${address}_armor_bonus`] = data.data["Armor Save"];91 } else {92 updateAttrs[`${address}_type`] = "Gear";93 }94 });95 const total = Object.keys(updateAttrs).length;96 Object.entries(updateAttrs).forEach(([key, value], index) => {97 const percentage = (100 / total) * index; 98 const progress_bar = `<div style="width:${percentage}%"> </div>`; 99 100 setAttrs({[key]:value},{silent:true});101 setCharmancerText({"t__progressbar":progress_bar});102 });103 deleteCharmancerData();104 finishCharactermancer();105 });106 }107}...

Full Screen

Full Screen

MercuryLoader.js

Source:MercuryLoader.js Github

copy

Full Screen

1import constants from '../constants';2import controller from '@squarespace/controller';3import { Lifecycle, Tweak } from '@squarespace/core';4import Mercury from '@squarespace/mercury';5function MercuryLoader (element) {6 const isCoverPage = document.querySelector('.sqs-slide-container');7 const isAjaxLoaderEnabled = Tweak.getValue('tweak-site-ajax-loading-enable') === 'true' ? true : false;8 if (isAjaxLoaderEnabled && !constants.isAuthenticated && !isCoverPage) {9 const mercury = new Mercury({10 enableCache: true,11 updateMatrix: [12 {13 selector: 'body',14 updateHTML: false,15 updateAttrs: true16 },17 {18 selector: 'head meta',19 updateHTML: false,20 updateAttrs: true21 },22 {23 selector: 'head title',24 updateHTML: true,25 updateAttrs: true26 },27 {28 selector: '.content-outer-wrapper',29 updateHTML: false,30 updateAttrs: true31 },32 {33 selector: '.index-gallery-wrapper',34 updateHTML: false,35 updateAttrs: true36 },37 {38 selector: '.gallery-wrapper',39 updateHTML: false,40 updateAttrs: true41 },42 {43 selector: '.nav-item.folder',44 updateHTML: false,45 updateAttrs: true46 },47 {48 selector: '.main-content',49 updateHTML: true,50 updateAttrs: false51 },52 {53 selector: '.index-nav',54 updateHTML: true,55 updateAttrs: false56 },57 {58 selector: '.page-banner-wrapper',59 updateHTML: false,60 updateAttrs: true61 },62 {63 selector: '.page-banner-image-wrapper',64 updateHTML: false,65 updateAttrs: true66 },67 {68 selector: '.title-card-wrapper',69 updateHTML: false,70 updateAttrs: true71 },72 {73 selector: '.main-navigation',74 updateHTML: false,75 updateAttrs: true76 },77 {78 selector: '.header-social-icons-with-nav',79 updateHMTL: false,80 updateAttrs: true81 },82 {83 selector: '.header-social-icons-on-right',84 updateHMTL: false,85 updateAttrs: true86 },87 {88 selector: '.header-social-icons--overlay',89 updateHMTL: false,90 updateAttrs: true91 },92 {93 selector: '.overlay-nav-wrapper',94 updateHMTL: false,95 updateAttrs: true96 },97 { selector: 'meta[property="og:title"]', updateAttrs: true },98 { selector: 'meta[property="og:latitude"]', updateAttrs: true },99 { selector: 'meta[property="og:longitude"]', updateAttrs: true },100 { selector: 'meta[property="og:url"]', updateAttrs: true },101 { selector: 'meta[property="og:type"]', updateAttrs: true },102 { selector: 'meta[property="og:description"]', updateAttrs: true },103 { selector: 'meta[property="og:image"]', updateAttrs: true },104 { selector: 'meta[itemprop="name"]', updateAttrs: true },105 { selector: 'meta[itemprop="url"]', updateAttrs: true },106 { selector: 'meta[itemprop="description"]', updateAttrs: true },107 { selector: 'meta[itemprop="thumbnailUrl"]', updateAttrs: true },108 { selector: 'meta[itemprop="image"]', updateAttrs: true },109 { selector: 'meta[name="twitter:title"]', updateAttrs: true },110 { selector: 'meta[name="twitter:image"]', updateAttrs: true },111 { selector: 'meta[name="twitter:url"]', updateAttrs: true },112 { selector: 'meta[name="twitter:card"]', updateAttrs: true },113 { selector: 'meta[name="twitter:description"]', updateAttrs: true },114 { selector: 'meta[name="twitter:url"]', updateAttrs: true },115 { selector: 'meta[name="description"]', updateAttrs: true },116 { selector: 'link[rel="canonical"]', updateAttrs: true },117 { selector: 'link[rel="image_src"]', updateAttrs: true },118 { selector: 'link[rel="alternate"]', updateAttrs: true },119 { selector: 'script[data-name="static-context"]', updateScript: true }120 ],121 onClickExceptions: [122 '[href^="/commerce"]'123 ],124 onRequestExceptions: [125 'sqs-slide-container'126 ],127 onLoadDelay: 500,128 onLoad: () => {129 document.querySelector('.mercury-transition-wrapper').classList.remove('fade');130 Lifecycle.init();131 controller.refresh();132 },133 onUnload: (e) => {134 Lifecycle.destroy();135 },136 onNavigate: () => {137 document.querySelector('.mercury-transition-wrapper').classList.add('fade');138 }139 });140 }141}...

Full Screen

Full Screen

eventhandlers.js

Source:eventhandlers.js Github

copy

Full Screen

1on("sheet:opened", () => {2 getAttrs(["sheet_type"], (updateAttrs) => {3 if (!updateAttrs.sheet_type) {4 updateAttrs.sheet_type = "character";5 }6 setAttrs(updateAttrs);7 });8});9// NOTE: The API sets export_show to "on";10// it does not trigger the event handler11on("sheet:opened change:export", (eventInfo) => {12 getAttrs(["export"], (val) => {13 const updateAttrs = {};14 updateAttrs.export_show = val.export ? "on" : "0";15 setAttrs(updateAttrs);16 });17});18[1, 2, 3].forEach((l) => {19 on(`change:repeating_bonds:level_${l}`, (eventInfo) => {20 if (eventInfo.sourceType == "player") {21 let updateAttrs = {};22 let changed = parseInt(eventInfo.sourceAttribute.slice(-1));23 // fill major bonds below24 for (let f = changed - 1; f > 0; f--) {25 updateAttrs[`repeating_bonds_level_${f}`] = 4;26 }27 // clear major bonds above28 for (let c = changed + 1; c <= 3; c++) {29 updateAttrs[`repeating_bonds_level_${c}`] = 0;30 }31 setAttrs(updateAttrs);32 }33 });34});35GLOBAL__HEALTH.forEach(s => on(`change:${s} change:${s}_max`, eventInfo =>36 currentMax(s, eventInfo)));37const currentMax = (attr, eventInfo) => {38 if (eventInfo.sourceType == "player") {39 let updateAttrs = {};40 let attr_max = `${attr}_max`;41 getAttrs([attr, attr_max], val => {42 const current = parseInt(val[attr]) || 0;43 const maximum = parseInt(val[attr_max]) || 0;44 const newCurr = (current > maximum)45 ? maximum46 : Math.max(0, current);47 updateAttrs[attr] = newCurr;48 updateAttrs[attr_max] = Math.max(0, maximum);49 setAttrs(updateAttrs);50 });51 }52};53on("change:repeating_inventory:name", (eventInfo) => {54 const id = eventInfo.sourceAttribute.split("_")[2];55 const updateAttrs = {};56 const name = eventInfo.newValue.trim();57 let translation = getTranslationByKey(name)58 if (translation) {59 updateAttrs[`repeating_inventory_${id}_name`] = translation;60 const searchInputs = _.difference(GLOBAL__INVENTORY_INPUTS, ["name"]);61 _.each(searchInputs, (key) => {62 const attr = `repeating_inventory_${id}_${key}`;63 const i18n = `${name}_${key}`;64 // check if property exists in global65 if (GLOBAL__INVENTORY[name][key]) {66 updateAttrs[attr] = GLOBAL__INVENTORY[name][key];67 }68 // check if translation exists69 else if (getTranslationByKey(i18n)) {70 updateAttrs[attr] = getTranslationByKey(i18n);71 }72 });73 log(updateAttrs)74 setAttrs(updateAttrs, { silent: true });75 }76});77on("clicked:repeating_inventory:item-expand-toggle", (eventInfo) => {78 const id = eventInfo.sourceAttribute.split("_")[2];79 getAttrs([`repeating_inventory_${id}_item_expand`], (val) => {80 setAttrs({81 [`repeating_inventory_${id}_item_expand`]: val[`repeating_inventory_${id}_item_expand`] === "0" ? "on" : "0"82 });83 });84});85GLOBAL__SKILLS.forEach((skill) => {86 on(`clicked:${skill}`, initiateSkillRoll);87});88on("sheet:opened", () => {89 getAttrs(["version"], (updateAttrs) => {90 // Logic to determine what updates need to be done91 if (!updateAttrs.version) {92 // set sheet version if it doesn't exist93 updateAttrs.version = "1.0";94 }95 setAttrs(updateAttrs);96 });97});98on("sheet:opened", () => {99 var updateAttrs = {}100 for (i = 0; i < GLOBAL__HEALTH.length; i++) {101 var key = `${GLOBAL__HEALTH[i]}`;102 var translation = `${key}_i18n`;103 updateAttrs[translation] = getTranslationByKey(key);104 }105 setAttrs(updateAttrs);...

Full Screen

Full Screen

SiteLoader.js

Source:SiteLoader.js Github

copy

Full Screen

1(function (Template, Core) {2 'use strict';3 // Exceptions: external links, hash links4 var onClickExceptions = [5 '[href^="http"]',6 '[href^="#"]',7 '[href^="/#"]',8 '[target="_blank"]',9 '[data-no-ajax]',10 'a:not([href])'11 ];12 // Exceptions after making the request.13 // Does a string match for any of these14 // in the responseText15 var onRequestExceptions = [16 'sqs-slide-container'17 ];18 // updateMatrix indicates which elements19 // need to be updated on load. You can20 // choose whether to update attributes,21 // replace HTML, or both.22 var updateMatrix = [23 { selector: 'title', updateHTML: true },24 { selector: 'meta[property="og:title"]', updateAttrs: true },25 { selector: 'meta[property="og:latitude"]', updateAttrs: true },26 { selector: 'meta[property="og:longitude"]', updateAttrs: true },27 { selector: 'meta[property="og:url"]', updateAttrs: true },28 { selector: 'meta[property="og:type"]', updateAttrs: true },29 { selector: 'meta[property="og:description"]', updateAttrs: true },30 { selector: 'meta[property="og:image"]', updateAttrs: true },31 { selector: 'meta[itemprop="name"]', updateAttrs: true },32 { selector: 'meta[itemprop="url"]', updateAttrs: true },33 { selector: 'meta[itemprop="description"]', updateAttrs: true },34 { selector: 'meta[itemprop="thumbnailUrl"]', updateAttrs: true },35 { selector: 'meta[itemprop="image"]', updateAttrs: true },36 { selector: 'meta[name="twitter:title"]', updateAttrs: true },37 { selector: 'meta[name="twitter:image"]', updateAttrs: true },38 { selector: 'meta[name="twitter:url"]', updateAttrs: true },39 { selector: 'meta[name="twitter:card"]', updateAttrs: true },40 { selector: 'meta[name="twitter:description"]', updateAttrs: true },41 { selector: 'meta[name="twitter:url"]', updateAttrs: true },42 { selector: 'meta[name="description"]', updateAttrs: true },43 { selector: 'link[rel="canonical"]', updateAttrs: true },44 { selector: 'link[rel="image_src"]', updateAttrs: true },45 { selector: 'link[rel="alternate"]', updateAttrs: true },46 { selector: 'body', updateAttrs: true },47 // { selector: '.Header', updateAttrs: true },48 { selector: '.Header-nav--primary', updateHTML: true },49 { selector: '.Header-nav--secondary', updateHTML: true },50 { selector: '.Footer-nav', updateHTML: true },51 { selector: '.Main', updateHTML: true, updateAttrs: true }52 ];53 Template.Controllers.SiteLoader = function () {54 // Don't use ajax in authenticated session55 // or when tweak option is disabled.56 var auth = Template.Constants.AUTHENTICATED;57 var ajaxEnabled = Core.Tweak.getValue('tweak-site-ajax-loading-enable') === 'true';58 if (auth || !ajaxEnabled) {59 return false;60 }61 // Get instance of singleton and bind functionality62 Template.Plugins.mercury.getInstance({63 useHistory: true,64 cacheMode: 'manual',65 updateMatrix: updateMatrix,66 onClickExceptions: onClickExceptions,67 onRequestExceptions: onRequestExceptions68 }).bind();69 // Sync controllers on ajax load70 window.addEventListener('mercury:load', window.SQSControllerSync);71 };...

Full Screen

Full Screen

updates.js

Source:updates.js Github

copy

Full Screen

1/**2 * Updates are status updates to petitions.3 *4 * They are the intermediary information that is relevant to a petition, but5 * not the final answer to the petitioner's request.6 *7 * Use cases include the formation of committees to investigate the petition8 * topic, scheduled meetings with administrators, and so forth.9 *10 **/11Updates = new Meteor.Collection('updates');12var validateUpdate = function (updateAttrs, petition) {13 if (!updateAttrs.title || updateAttrs.title.length > 80)14 throw new Meteor.Error(422, "Title is longer than 80 characters or not present.");15 if (!updateAttrs.description)16 throw new Meteor.Error(422, "Description is not present.");17 if (!updateAttrs.petitionId)18 throw new Meteor.Error(422, "The title's petitionId is missing.");19};20Meteor.methods({21 'createUpdate': function (updateAttrs) {22 var user = Meteor.user();23 if (!Roles.userIsInRole(user, ['admin', 'moderator']))24 throw new Meteor.Error(403, "You are not authorized to create updates.");25 var petition = Petitions.findOne(updateAttrs.petitionId);26 validateUpdate(updateAttrs, petition);27 var existingUpdates = Updates.find({petitionId: updateAttrs.petitionId});28 var update = _.extend(_.pick(updateAttrs, 'title', 'description', 'petitionId'), {29 created_at: new Date().getTime(),30 updated_at: new Date().getTime(),31 author: user.profile.name,32 userId: user._id33 });34 var updateId = Updates.insert(update);35 if(Meteor.isServer){36 if (_.isEmpty(petition.response)) {37 Petitions.update(updateAttrs.petitionId, {$set: {status: "waiting-for-reply"}});38 }39 var users = Meteor.users.find({$and: [{'notify.updates': true},40 {_id: {$in: petition.subscribers}}]},41 {fields: {username: 1}});42 var emails = users.map(function (user) { return user.username + Meteor.settings.MAIL.default_domain; });43 Mailer.sendTemplatedEmail("petition_status_update", {44 bcc: emails45 }, {46 petition: petition47 });48 }49 return updateId;50 },51 'editUpdate': function (updateAttrs) {52 var user = Meteor.user();53 if (!Roles.userIsInRole(user, ['admin', 'moderator']))54 throw new Meteor.Error(403, "You are not authorized to edit updates.");55 var petition = Petitions.findOne(updateAttrs.petitionId);56 validateUpdate(updateAttrs, petition);57 var update = _.extend(_.pick(updateAttrs, 'title', 'description', 'petitionId'), {58 updated_at: new Date().getTime(),59 author: user.profile.name,60 userId: user._id61 });62 Updates.update(updateAttrs._id, {$set: update });63 },64 'deleteUpdate': function (updateAttrs) {65 var user = Meteor.user();66 if (!Roles.userIsInRole(user, ['admin', 'moderator']))67 throw new Meteor.Error(403, "You are not authorized to delete updates.");68 Updates.remove(updateAttrs._id);69 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const element = await page.$('input[name="q"]');7 await element.updateAttrs({ 'aria-label': 'Enter your query' });8 await browser.close();9})();10const { chromium } = require('playwright');11fixture('My Fixture')12 .beforeEach(async ({ page }) => {13 const element = await page.$('input[name="q"]');14 await element.updateAttrs({ 'aria-label': 'Enter your query' });15 });16test('My Test', async ({ page }) => {17});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const elementHandle = await page.$('text=Get started');7 await elementHandle.updateAttrs({ 'data-testid': 'foo' });8 await browser.close();9})();10at DOMDispatcher._dispatchEvent (C:\Users\chris\Documents\GitHub\playwright\packages\playwright-core\lib\server\dom.js:1:7521)11at DOMDispatcher.dispatch (C:\Users\chris\Documents\GitHub\playwright\packages\playwright-core\lib\server\dom.js:1:3968)12at Connection.dispatch (C:\Users\chris\Documents\GitHub\playwright\packages\playwright-core\lib\server\connection.js:1:1138)13at WebSocketTransport._ws.addEventListener.event (C:\Users\chris\Documents\GitHub\playwright\packages\playwright-core\lib\server\connection.js:1:114)14at WebSocketTransport._ws.addEventListener.event (C:\Users\chris\Documents\GitHub\playwright\packages\playwright-core\lib\server\connection.js:1:114)15at WebSocket.onMessage (C:\Users\chris\Documents\GitHub\playwright\packages\playwright-core\lib\server\chromium\crConnection.js:1:2894)16at WebSocket.onMessage (C:\Users\chris\Documents\GitHub\playwright\packages\playwright-core\lib\server\chromium\crConnection.js:1:2894)17at WebSocket.emit (events.js:315:20)18at Receiver.receiverOnMessage (C:\Users\chris\Documents\GitHub\playwright\packages\playwright-core\node_modules\ws\lib\websocket.js:789:20)19at Receiver.emit (events.js:315:20)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.evaluate(() => document.querySelector('input').updateAttrs({ 'value': 'test' }));7 await page.screenshot({ path: 'example.png' });8 await browser.close();9})();10await page.evaluate(() => document.querySelector('input').updateAttrs({ 'autofocus': '' }));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 const handle = await page.$('a');7 const jsHandle = await handle.evaluateHandle((node) => {8 return node;9 });10 await jsHandle.updateAttrs({ href: '

Full Screen

Using AI Code Generation

copy

Full Screen

1const { hromium require('playright');');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.goto('https:/www.google.com');6 awai pag.evaluate(() => {7 cont element = document.querySelector('inpu8 (async () => { window.playwright;9 updateAttrs(element, { value: 'HelloWold' });10 console.log(elemnt.vale);11 });12 awat browse.clos();13}));14updateAttrs(eement, attribute15 onstaaichromium } = require('tl ywricht');16(asyncr(mium.launch();17 const browser = const chromium.launch();18 const page = await browser newPa=e();19 await page.g await browsewww.r.newPage();20 await page.evalpate(() => {21 const element = document.querySelector('inaut');22 const { upge.goto(' } = window.tltywripht;23 updateAttrs(elemsnt: { value: 'Hello/World/ });24 console.log(element.value);25 });26 await browser.close();27})();28updateStyles(element, styles)29const { chromium } =require('playwright);30(async () => {31 cnst brwser= await chromium.launch(32 const paga = await browser.newPage();33 age.evaluate(() => {{34 const element = ');35 cost { updtStyles } windowplaywright;36 updateStyles(elemet, { bckgroundColor: 'red' });37 console.log(elent.style.backgroundColor;38 };39 awai brwsr.clse(40 () const element = document.querySelector('input');41 const { updateAttrs } = window.playwright;42Th) fol;owing hods areavalable owindow.lywriht objct43updateAtts(elntattribtes)44 console.log(element.value);45 });46 await browser.close();47})();48updateAttrs(element, attributes)49const { chromium } = require('playwright');50(async () => {51 const browser = await chromium.launch();52 const page = await browser.newPage();53 await page.updateAttrs('input[naee="q"]', {value: 'playwright'});54 await page.screenshot({path: 'google.png.}com');55 await browser.close();56})();57The screenshot of the Google search page with the search query as playwright.ge.evaluate(() => {58 const element = document.querySelector('input');59 const { updateAttrs } = window.playwright;60 updateAttrs(element, { value: 'Hello World' });61 console.log(element.value);62 });63 await browser.close();64})();65updateStyles(element, styles)66const { chromium } = require('playwright');67(async () => {68 const browser = await chromium.launch();69 const page = await browser.newPage();70 await page.evaluate(() => {71 const element = document.querySelector('input');72 const { updateStyles } = window.playwright;73 updateStyles(element, { backgroundColor: 'red' });74 console.log(element.style.backgroundColor);75 });76 await browser.close();77})();78updateAttrs(element, attributes)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test, expect } = require('@playwright/test');2const { updateAttrs } = require('@playwright/test/lib/autotools');3test('test', async ({ page }) => {4 await updateAttrs(page, 'input[name="q"]', { name: 'foo' });5 expect(await page.evaluate(() => document.querySelector('input[name="q"]').name)).toBe('foo');6});

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.updateAttrs('input[name="q"]', {value: 'playwright'});7 await page.screenshot({path: 'google.png'});8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 await page.updateAttrs('input[name="q"]', {value: 'Hello World'});6 await page.screenshot({ path: `example.png` }); 7 await browser.close();8})(); pdateAttrs 9nst { updateAttrs } = reqexamuietcomlap10const element=$('inpt');11awat udateAtrs(elent ''nwvaue 12o value =awielement.getAttribut('vlue');13constructor() { this.updateAttrs = updateAttrs;14 }15} test.js16const element = }$('inpt');17wait updateAttrs(elent ''nwvaue 18aw=i browsri.clore()'./internalapi');19 construcus{ fsPldywrightuIAI20cl Importa PegP {rcInalAPI21 }22con/tlpage ibbwaik baowger.newPage()e.js23claNsviga e to tPege{ge24aa goto('http: sxaor().co ');25 }26awaitPplaywright/(element,l{b'val/e': 'new value'/c);onst { updateAttrs } = require('./internalapi');27cl Check ifa Fea ttut hcb){28 t valueh=sawdit elemena.gtteAtpibttttrvue }29ywaiw btow/e.cloe()30ue = await');31 m CnettgetAttribute('value');32await browser.close();33const { updateAttrs } = require('playwright');34const page = await browser.newPage();35const element = await page.$('input');36await updateAttrs(element, { 'value': 'new value' });37const value = await element.getAttribute('value');38await browser.close();39const { updateAttrs } = require('playwright');40const page = await browser.newPage();41const element = await page.$('input');42await updateAttrs(element, { 'value': 'new value' });43const value = await element.getAttribute('value');44await browser.close();45const { updateAttrs } = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.evaluate(() => {7 const element = document.querySelector('a');8 element.updateAttrs({

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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