Tool: HtmlPreprocessor for SpiderBasic
Tool: HtmlPreprocessor for SpiderBasic
If the prophet does not come to the mountain the mountain must come to the prophet.
Referring to this feature request i wrote a little SpiderBasic-Tool which allow to manipulate the HTML file generated by SpiderBasic before displaying it in the browser.
More informations here: https://github.com/spiderbytes/HtmlPreprocessor
Greetings ... Peter
Referring to this feature request i wrote a little SpiderBasic-Tool which allow to manipulate the HTML file generated by SpiderBasic before displaying it in the browser.
More informations here: https://github.com/spiderbytes/HtmlPreprocessor
Greetings ... Peter
- SparrowhawkMMU
- Posts: 281
- Joined: Wed Aug 19, 2015 3:02 pm
- Location: United Kingdom
Re: Tool: HtmlPreprocessor for SpiderBasic
Thanks Peter, great bit of code. Works great on Mac too.
Re: Tool: HtmlPreprocessor for SpiderBasic
you're welcome, SparrowhawkMMU.
Thanks for your feedback & Greetings ... Peter
I'm glad to read this. I could only test it under windows and linux so far.SparrowhawkMMU wrote:Works great on Mac too.
Thanks for your feedback & Greetings ... Peter
Re: Tool: HtmlPreprocessor for SpiderBasic
Hello Peter,
Thanks, works fine.
Lets hope Fred comes with a final solution in sb.
Regards
Hans-Peter
Thanks, works fine.
Lets hope Fred comes with a final solution in sb.
Regards
Hans-Peter
Re: Tool: HtmlPreprocessor for SpiderBasic
Hello Hans-Peter,
thank you for the feedback.
Greetings ... Peter
thank you for the feedback.
yes, a native solution would be better. But there may still be some time to go until then.HPW wrote:Lets hope Fred comes with a final solution in sb.
Greetings ... Peter
Re: Tool: HtmlPreprocessor for SpiderBasic
Hello Peter,
For a one-liner replacement this works fine.
I now try to insert a larger block of JavaScript. Now I fighting with error popup
json error in htmlpreprocessot: invalid escape character
So how about extending the preprozessor to allow the Parameter "replace": followed by a filename with full path to insert the complete file.
Or where can I have the wrong escape character? Which characters have to be escaped?
This is my JavaScript to insert:
Regards
For a one-liner replacement this works fine.
I now try to insert a larger block of JavaScript. Now I fighting with error popup
json error in htmlpreprocessot: invalid escape character
So how about extending the preprozessor to allow the Parameter "replace": followed by a filename with full path to insert the complete file.
Or where can I have the wrong escape character? Which characters have to be escaped?
This is my JavaScript to insert:
Code: Select all
<script type='text/javascript'>
<!--
// ================== careful changing anything below ===================
// EMSCRIPTEN loading newlisp-js-lib.js showing progress of downloading
// importing newlispEvaklStr and defining preRun and postRun functions
var Module = {
preRun: [],
postRun: [(function() {
// import newlispEvalStr from newlisp-js-lib.js library
newlispEvalStr = Module.cwrap('newlispEvalStr', 'string', ['string']);
// preload newLISP functions from code textarea id='code'
// newlispEvalStr(document.getElementById('code').value);
// preload memoizing table
// newlispEvalStr('(fibo 150)(fibo 300)(fibo 450)');
})],
print: (function() { return function(text) { }; })(),
printErr: function(text) { },
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.text) return;
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
var now = Date.now();
if (m && now - Date.now() < 30) return; // if progress update, skip if too soon
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
if (m) {
text = m[1];
progressElement.value = parseInt(m[2])*100;
progressElement.max = parseInt(m[4])*100;
progressElement.hidden = false;
} else {
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
}
statusElement.innerHTML = text;
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ?'Preparing... (' + (this.totalDependencies-left) +
'/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
Module.setStatus('Downloading...');
// ========================================================================
-->
</script>
<script async type="text/javascript" src="js/newlisp-js-lib.js"></script>
Re: Tool: HtmlPreprocessor for SpiderBasic
HPW wrote:Which characters have to be escaped?
in your case: only the double quotes:
Code: Select all
"replace": "<script async type=\"text/javascript\" src=\"js/newlisp-js-lib.js\"></script>"
Code: Select all
"replace": "<script async type='text/javascript' src='js/newlisp-js-lib.js'></script>"
Greetings ... Peter
Re: Tool: HtmlPreprocessor for SpiderBasic
Hello Peter,
Thanks for the hint. Got it working now.
This time I place the code before </body>.
Finally I have the embedded newlisp-interpreter working.
And I learned a lot about mixing sb and JavaScript.
Regards
Thanks for the hint. Got it working now.
This time I place the code before </body>.
Finally I have the embedded newlisp-interpreter working.
And I learned a lot about mixing sb and JavaScript.
Regards
Re: Tool: HtmlPreprocessor for SpiderBasic
Hello Peter,
A related question:
I injected some JavaScript calls ito the Body of the spiderapp.
I want to Access the spide-objects from there like:
But Console repors that they are undefined.
And when examie the html I can not see any DOM structure.
So how do I access objects or commands from main-html?
Regards
A related question:
I injected some JavaScript calls ito the Body of the spiderapp.
I want to Access the spide-objects from there like:
Code: Select all
f_disablegadget(3,0);
f_setgadgettext(5,text);
And when examie the html I can not see any DOM structure.
So how do I access objects or commands from main-html?
Regards
Re: Tool: HtmlPreprocessor for SpiderBasic
Hello,
Also this did not work:
Regards
Also this did not work:
Code: Select all
var statusElement = document.getElementById('widget_dijit_form_Textbox_1');
statusElement.innerHTML = text;