Comments (13)
Something like this in playground.html
const url = new URL (document .location .href) .searchParams .get ("url");
if (url .toLowerCase() .endsWith (".x3d")) {
editor .setValue ("Starting to fetch " + url);
fetch (url)
.then ( (r) => r .ok ? r .text () : "<!--Response was not ok trying to fetch url.-->\n" + box)
.then ( (t) => editor .setValue (t))
.catch ( () => editor .setValue ("failed loading"));
}
else {editor . setValue (box .replace(/ {3}/g, " "));}
seems to work well enough.
from x_ite.
I have modified playground.html according to your lines of code and it seems to work fine.
from x_ite.
Thanks. Works great:
from x_ite.
This works as well:
from x_ite.
Thanks again. It turns out that there was a problem with data urls .
I finally discovered that the searchParams property does not work with data urls. It destroys some characters, probably trying to find multiple parameters.
Here is a simple regex match instead which worked well:
const url = new URL(document.location.href).search.match(/^\?url=(.*)/);
if (url) {
try {
const response = await fetch(url[1]) //first capture group
, text = response.ok ? await response.text() : "Response was not ok trying to fetch url: " + url[1];
editor.setValue(text);
} catch (error) {
editor.setValue(error.message);
}
} else {
editor.setValue(box.replace(/ {3}/g, " "));
}
from x_ite.
Yes, parts of search param must be encoded with encodeURIComponent
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent), and thus later be decoded with decodeURIComponent
.
from x_ite.
This means, I would rather do:
const url = decodeURIComponent (new URL (document .location .href) .searchParams .get ("url"));
...
from x_ite.
I tried that, it did not work, unfortunately.
Wait,
const url = decodeURIComponent (new URL (encodeURIComponent(document .location .href)) .searchParams .get ("url"));
might work.
No, new URL() does not accept it.
from x_ite.
const url = new URL(document.location.href);
if (url.searchParams.get("url")) {
const dummyURL = new URL( 'http://dummy/' + encodeURIComponent (url.search.slice ( 5 ) )); //?url= exists but may not be first
const realUrl = decodeURIComponent ( dummyURL.pathname.slice ( 1 ));
...
seems to work but it may be messier than the regex?
Actually I think this is pretty much the same as simply
if (url.searchParams.get("url")) {
const realUrl = url.search.slice ( 5 );
....
That would be the simplest.
It does not work for multiple search params (/?date=Jan4_1999,?url=htt
) but failure for this is acceptable.
This does work like the regex and gets rid of the obscure array[1] use.
from x_ite.
If I encode data:model/x3d+xml,<Shape><Text string='"Hello: ?&"'/></Shape>
and then create the link https://create3000.github.io/x_ite/playground/?url=data%3Amodel%2Fx3d%2Bxml%2C%3CShape%3E%3CText%20string%3D%27%22Hello%3A%20%3F%26amp;%22%27%2F%3E%3C%2FShape%3E, which will work.
from x_ite.
ok, percentencoded dataurls, will work, and are probably ok to expect.
(This is almost black)
from x_ite.
Files loaded with url parameter, do now support relative URL's inside, even if they are edited later. :)
from x_ite.
Very nice !
from x_ite.
Related Issues (20)
- Issue with model in X3D archives HOT 2
- Can't use x_ite from inside a Firefox extension; can ResizeSensor.js be pruned? HOT 9
- Scientific data visualization HOT 6
- Weird shader effects, missing images, possibly due to reconfiguring Firewall, hostname, DNS servers HOT 1
- Custom elements issue with x_ite.mjs in Microsoft Edge? HOT 3
- npx sunrize [files] HOT 5
- X_ITE React implementation questions HOT 5
- "aspectRatio" not supported? HOT 4
- Despite no errors on the console, X_ITE shows no graphics HOT 10
- Use RENDERER on Firefox HOT 1
- ExternProtoDeclare not downloading? X3D checks in X3D-Edit. HOT 3
- Mono Sound plays only over left speaker HOT 3
- How to start X_ITE in a browser window in fullscreen mode HOT 3
- "Better" webpack.config.js, for Git Bash under Windows 10 HOT 5
- Replace webpack "string-replace-webpack-plugin" or provide dependency overrides in package.json HOT 2
- Adding a new node HOT 13
- Filling up an empty scene with Javascript HOT 8
- IndexedFaceSet solid false and alpha HOT 1
- EnvironmentLight has no effect (noob question number 3) HOT 3
- Unknown node type 'ProtoDeclare' 'ProtoBody' 'InstancedShape' HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from x_ite.