WIP: mock selenium response
This commit is contained in:
32
src/index.js
32
src/index.js
@@ -93,28 +93,28 @@ function roll(die) {
|
||||
function load() {
|
||||
const svg = this.contentDocument.querySelector('svg'),
|
||||
startLocs = svg.querySelector('.start-locations')
|
||||
// , scriptEl = this.contentDocument.querySelector('script')
|
||||
, scriptEl = this.contentDocument.querySelector('script')
|
||||
;
|
||||
|
||||
// const linkEl = document.createElement('link');
|
||||
// linkEl.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
||||
// linkEl.setAttribute('rel', 'stylesheet');
|
||||
// linkEl.setAttribute('href', 'http://localhost:8080/assets/css/map.css');
|
||||
// linkEl.setAttribute('type', 'text/css');
|
||||
const linkEl = document.createElement('link');
|
||||
linkEl.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
||||
linkEl.setAttribute('rel', 'stylesheet');
|
||||
linkEl.setAttribute('href', '../../assets/css/map.css');
|
||||
linkEl.setAttribute('type', 'text/css');
|
||||
|
||||
// linkEl.onload = function (e) {
|
||||
// console.log('map.css loaded');
|
||||
linkEl.onload = function (e) {
|
||||
console.log('map.css loaded');
|
||||
|
||||
// if (scriptEl) {
|
||||
// scriptEl.onload = function () {
|
||||
// console.log('map.js loaded');
|
||||
if (scriptEl) {
|
||||
scriptEl.onload = function () {
|
||||
console.log('map.js loaded');
|
||||
|
||||
// };
|
||||
// scriptEl.setAttribute('href', 'http://localhost:8080/map.js');
|
||||
// }
|
||||
// };
|
||||
};
|
||||
scriptEl.setAttribute('href', '../../map.js');
|
||||
}
|
||||
};
|
||||
|
||||
// svg.prepend(linkEl);
|
||||
svg.prepend(linkEl);
|
||||
|
||||
this.style.opacity = 1;
|
||||
mapPlaceholder.style.opacity = 0;
|
||||
|
||||
13
src/index.js.test
Normal file
13
src/index.js.test
Normal file
@@ -0,0 +1,13 @@
|
||||
const svgns = 'http://www.w3.org/2000/svg';
|
||||
const [icon, use] = ['svg', 'use'].map(t => document.createElementNS(svgns, t));
|
||||
|
||||
icon.setAttributeNS(null, 'viewBox', '-6 -6 12 12');
|
||||
icon.setAttribute('xmlns', svgns);
|
||||
icon.classList.add('weapon-icon');
|
||||
|
||||
// use.setAttributeNS(null, 'href', `assets/images/counters.svg#rifle`);
|
||||
use.setAttributeNS(null, 'href', `assets/images/counters2.svg#smg`);
|
||||
|
||||
icon.appendChild(use);
|
||||
|
||||
document.querySelector('body').appendChild(icon);
|
||||
@@ -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