WIP: mock selenium response
This commit is contained in:
@@ -1,4 +1,15 @@
|
||||
import { Observable } from "./observable";
|
||||
// import counters from '../../public/assets/images/counters.svg';
|
||||
// import svg from '../../public/assets/images/counters.svg';
|
||||
|
||||
// const doc = new DOMParser().parseFromString(svg, 'image/svg+xml');
|
||||
// const rifle = document.importNode(doc.querySelector('#rifle'), true);
|
||||
// const smg = document.importNode(doc.querySelector('#smg'), true);
|
||||
|
||||
// console.log('svg', counters);
|
||||
// console.log('doc', doc);
|
||||
// console.log('imported svg', rifle);
|
||||
// console.log('imported svg', smg);
|
||||
|
||||
const weapons = {
|
||||
rifle: {
|
||||
@@ -21,13 +32,15 @@ const weapons = {
|
||||
}
|
||||
}
|
||||
|
||||
const cacheBuster = Array(20).fill(null).map(() => getRandomIntInclusive(0, 9)).join('');
|
||||
|
||||
function createIcon(number) {
|
||||
const [icon, use, text] = ['svg', 'use', 'text'].map(t => document.createElementNS(svgns, t));
|
||||
|
||||
icon.setAttributeNS(null, 'viewBox', '-6 -6 12 12');
|
||||
icon.setAttribute('xmlns', svgns);
|
||||
|
||||
use.setAttributeNS(null, 'href', `assets/images/counters.svg#counter-base`);
|
||||
use.setAttributeNS(null, 'href', `assets/images/counters.svg?v=${cacheBuster}#counter-base`);
|
||||
|
||||
text.textContent = number;
|
||||
|
||||
@@ -37,6 +50,13 @@ function createIcon(number) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_integer_between_two_values_inclusive
|
||||
function getRandomIntInclusive(min, max) {
|
||||
const minCeiled = Math.ceil(min);
|
||||
const maxFloored = Math.floor(max);
|
||||
return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled); // The maximum is inclusive and the minimum is inclusive
|
||||
}
|
||||
|
||||
function createWeaponIcon(type) {
|
||||
const [icon, use] = ['svg', 'use'].map(t => document.createElementNS(svgns, t));
|
||||
|
||||
@@ -44,9 +64,11 @@ function createWeaponIcon(type) {
|
||||
icon.setAttribute('xmlns', svgns);
|
||||
icon.classList.add('weapon-icon');
|
||||
|
||||
use.setAttributeNS(null, 'href', `assets/images/counters.svg#${type}`);
|
||||
use.setAttributeNS(null, 'href', `assets/images/counters.svg?v=${cacheBuster}#${type}`);
|
||||
// use.setAttributeNS(null, 'href', `${counters}#${type}`);
|
||||
|
||||
icon.appendChild(use);
|
||||
// icon.appendChild(document.importNode(doc.querySelector(`#${type}`), true));
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user