mirror of
https://github.com/tcsenpai/Zundler.git
synced 2025-06-06 11:35:40 +00:00
Use camel case in JS
This commit is contained in:
parent
ac664c27a1
commit
2e8a3ee989
6
zundler/assets/bootstrap.js
vendored
6
zundler/assets/bootstrap.js
vendored
@ -11,10 +11,10 @@ var _base64ToArrayBuffer = function (base64) {
|
|||||||
|
|
||||||
|
|
||||||
// Set up the virtual file tree
|
// Set up the virtual file tree
|
||||||
var GC = window.global_context;
|
var GC = window.globalContext;
|
||||||
GC = _base64ToArrayBuffer(GC);
|
GC = _base64ToArrayBuffer(GC);
|
||||||
GC = pako.inflate(GC);
|
GC = pako.inflate(GC);
|
||||||
GC = new TextDecoder("utf-8").decode(GC);
|
GC = new TextDecoder("utf-8").decode(GC);
|
||||||
GC = JSON.parse(GC);
|
GC = JSON.parse(GC);
|
||||||
window.global_context = GC;
|
window.globalContext = GC;
|
||||||
eval(window.global_context.main);
|
eval(window.globalContext.main);
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
var split_url = function(url) {
|
var splitUrl = function(url) {
|
||||||
// Return a list of three elements: path, GET parameters, anchor
|
// Return a list of three elements: path, GET parameters, anchor
|
||||||
var anchor = url.split('#')[1] || "";
|
var anchor = url.split('#')[1] || "";
|
||||||
var get_parameters = url.split('#')[0].split('?')[1] || "";
|
var getParameters = url.split('#')[0].split('?')[1] || "";
|
||||||
var path = url.split('#')[0];
|
var path = url.split('#')[0];
|
||||||
path = path.split('?')[0];
|
path = path.split('?')[0];
|
||||||
let result = [path, get_parameters, anchor];
|
let result = [path, getParameters, anchor];
|
||||||
// console.log("Split URL", url, result);
|
// console.log("Split URL", url, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var virtual_click = function(evnt) {
|
var virtualClick = function(evnt) {
|
||||||
// Handle GET parameters and anchors
|
// Handle GET parameters and anchors
|
||||||
// console.log("Virtual click", evnt);
|
// console.log("Virtual click", evnt);
|
||||||
|
|
||||||
@ -18,22 +18,22 @@ var virtual_click = function(evnt) {
|
|||||||
var name = el.tagName.toLowerCase();
|
var name = el.tagName.toLowerCase();
|
||||||
|
|
||||||
if (name == 'a') {
|
if (name == 'a') {
|
||||||
var [path, get_parameters, anchor] = split_url(el.getAttribute('href'));
|
var [path, getParameters, anchor] = splitUrl(el.getAttribute('href'));
|
||||||
} else if (name == 'form') {
|
} else if (name == 'form') {
|
||||||
var [path, get_parameters, anchor] = split_url(el.getAttribute('action'));
|
var [path, getParameters, anchor] = splitUrl(el.getAttribute('action'));
|
||||||
const formData = new FormData(el);
|
const formData = new FormData(el);
|
||||||
get_parameters = new URLSearchParams(formData).toString();
|
getParameters = new URLSearchParams(formData).toString();
|
||||||
} else {
|
} else {
|
||||||
console.error("Invalid element", el);
|
console.error("Invalid element", el);
|
||||||
}
|
}
|
||||||
|
|
||||||
path = normalize_path(path);
|
path = normalizePath(path);
|
||||||
|
|
||||||
window.parent.postMessage({
|
window.parent.postMessage({
|
||||||
action: "virtual_click",
|
action: "virtualClick",
|
||||||
argument: {
|
argument: {
|
||||||
path: path,
|
path: path,
|
||||||
get_parameters: get_parameters,
|
getParameters: getParameters,
|
||||||
anchor: anchor,
|
anchor: anchor,
|
||||||
}
|
}
|
||||||
}, '*');
|
}, '*');
|
||||||
@ -42,7 +42,7 @@ var virtual_click = function(evnt) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
var is_virtual = function(url) {
|
var isVirtual = function(url) {
|
||||||
// Return true if the url should be retrieved from the virtual file tree
|
// Return true if the url should be retrieved from the virtual file tree
|
||||||
var _url = url.toString().toLowerCase();
|
var _url = url.toString().toLowerCase();
|
||||||
return (! (
|
return (! (
|
||||||
@ -56,10 +56,10 @@ var is_virtual = function(url) {
|
|||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
var retrieve_file = function(path) {
|
var retrieveFile = function(path) {
|
||||||
// console.log("Retrieving file: " + path);
|
// console.log("Retrieving file: " + path);
|
||||||
var file_tree = window.global_context.file_tree;
|
var fileTree = window.globalContext.fileTree;
|
||||||
var file = file_tree[path];
|
var file = fileTree[path];
|
||||||
if (!file) {
|
if (!file) {
|
||||||
console.warn("File not found: " + path);
|
console.warn("File not found: " + path);
|
||||||
return "";
|
return "";
|
||||||
@ -68,14 +68,14 @@ var retrieve_file = function(path) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var normalize_path = function(path) {
|
var normalizePath = function(path) {
|
||||||
// make relative paths absolute in context of our virtual file tree
|
// make relative paths absolute in context of our virtual file tree
|
||||||
|
|
||||||
while (path && path[0] == '/') {
|
while (path && path[0] == '/') {
|
||||||
path = path.substr(1);
|
path = path.substr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = window.global_context.current_path;
|
var result = window.globalContext.current_path;
|
||||||
result = result.split('/');
|
result = result.split('/');
|
||||||
result.pop();
|
result.pop();
|
||||||
result = result.concat(path.split('/'));
|
result = result.concat(path.split('/'));
|
||||||
@ -94,14 +94,14 @@ var normalize_path = function(path) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
result = array.join('/');
|
result = array.join('/');
|
||||||
// console.log(`Normalized path: ${path} -> ${result} (@${window.global_context.current_path})`);
|
// console.log(`Normalized path: ${path} -> ${result} (@${window.globalContext.current_path})`);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var on_set_data = function(argument) {
|
var onSetData = function(argument) {
|
||||||
// window.global_context = argument;
|
// window.globalContext = argument;
|
||||||
console.debug("Received data from parent", window.global_context);
|
console.debug("Received data from parent", window.globalContext);
|
||||||
try {
|
try {
|
||||||
// window.document.dispatchEvent(new Event("DOMContentLoaded", { bubbles: true, cancelable: true }));
|
// window.document.dispatchEvent(new Event("DOMContentLoaded", { bubbles: true, cancelable: true }));
|
||||||
} finally {
|
} finally {
|
||||||
@ -128,10 +128,10 @@ var on_set_data = function(argument) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var fix_link = function(a) {
|
var fixLink = function(a) {
|
||||||
if (is_virtual(a.getAttribute('href'))) {
|
if (isVirtual(a.getAttribute('href'))) {
|
||||||
// a.addEventListener('click', virtual_click);
|
// a.addEventListener('click', virtualClick);
|
||||||
a.setAttribute("onclick", "virtual_click(event)");
|
a.setAttribute("onclick", "virtualClick(event)");
|
||||||
} else if (a.getAttribute('href').startsWith('#')) {
|
} else if (a.getAttribute('href').startsWith('#')) {
|
||||||
a.setAttribute('href', "about:srcdoc" + a.getAttribute('href'))
|
a.setAttribute('href', "about:srcdoc" + a.getAttribute('href'))
|
||||||
} else if (!a.getAttribute('href').startsWith('about:srcdoc')) {
|
} else if (!a.getAttribute('href').startsWith('about:srcdoc')) {
|
||||||
@ -142,22 +142,22 @@ var fix_link = function(a) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var fix_form = function(form) {
|
var fixForm = function(form) {
|
||||||
var href = form.getAttribute('action');
|
var href = form.getAttribute('action');
|
||||||
if (is_virtual(href) && form.getAttribute('method').toLowerCase() == 'get') {
|
if (isVirtual(href) && form.getAttribute('method').toLowerCase() == 'get') {
|
||||||
// form.addEventListener('submit', virtual_click);
|
// form.addEventListener('submit', virtualClick);
|
||||||
form.setAttribute("onsubmit", "virtual_click(event)");
|
form.setAttribute("onsubmit", "virtualClick(event)");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var embed_img = function(img) {
|
var embedImg = function(img) {
|
||||||
if (img.hasAttribute('src')) {
|
if (img.hasAttribute('src')) {
|
||||||
const src = img.getAttribute('src');
|
const src = img.getAttribute('src');
|
||||||
if (is_virtual(src)) {
|
if (isVirtual(src)) {
|
||||||
var path = normalize_path(src);
|
var path = normalizePath(src);
|
||||||
const file = retrieve_file(path);
|
const file = retrieveFile(path);
|
||||||
const mime_type = window.global_context.file_tree[path].mime_type;
|
const mime_type = window.globalContext.fileTree[path].mime_type;
|
||||||
if (mime_type == 'image/svg+xml') {
|
if (mime_type == 'image/svg+xml') {
|
||||||
img.setAttribute('src', "data:image/svg+xml;charset=utf-8;base64, " + btoa(file));
|
img.setAttribute('src', "data:image/svg+xml;charset=utf-8;base64, " + btoa(file));
|
||||||
} else {
|
} else {
|
||||||
@ -168,9 +168,9 @@ var embed_img = function(img) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var on_scroll_to_anchor = function(argument) {
|
var onScrollToAnchor = function(argument) {
|
||||||
if (window.global_context.anchor) {
|
if (window.globalContext.anchor) {
|
||||||
document.location.replace("about:srcdoc#" + window.global_context.anchor);
|
document.location.replace("about:srcdoc#" + window.globalContext.anchor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,20 +180,20 @@ const observer = new MutationObserver((mutationList) => {
|
|||||||
mutationList.forEach((mutation) => {
|
mutationList.forEach((mutation) => {
|
||||||
if (mutation.type == 'childList') {
|
if (mutation.type == 'childList') {
|
||||||
Array.from(mutation.target.querySelectorAll("a")).forEach( a => {
|
Array.from(mutation.target.querySelectorAll("a")).forEach( a => {
|
||||||
fix_link(a);
|
fixLink(a);
|
||||||
});
|
});
|
||||||
Array.from(mutation.target.querySelectorAll("img")).forEach( img => {
|
Array.from(mutation.target.querySelectorAll("img")).forEach( img => {
|
||||||
embed_img(img);
|
embedImg(img);
|
||||||
});
|
});
|
||||||
Array.from(mutation.target.querySelectorAll("form")).forEach( form => {
|
Array.from(mutation.target.querySelectorAll("form")).forEach( form => {
|
||||||
fix_form(form);
|
fixForm(form);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var monkey_patch = function() {
|
var monkeyPatch = function() {
|
||||||
if (typeof jQuery === 'undefined') {return;} // Only for jQuery at the moment
|
if (typeof jQuery === 'undefined') {return;} // Only for jQuery at the moment
|
||||||
/**
|
/**
|
||||||
* Monkey patch getQueryParameters
|
* Monkey patch getQueryParameters
|
||||||
@ -205,7 +205,7 @@ var monkey_patch = function() {
|
|||||||
jQuery._getQueryParameters = jQuery.getQueryParameters;
|
jQuery._getQueryParameters = jQuery.getQueryParameters;
|
||||||
jQuery.getQueryParameters = function(s) {
|
jQuery.getQueryParameters = function(s) {
|
||||||
if (typeof s === 'undefined')
|
if (typeof s === 'undefined')
|
||||||
s = '?' + window.global_context.get_parameters;
|
s = '?' + window.globalContext.getParameters;
|
||||||
return jQuery._getQueryParameters(s);
|
return jQuery._getQueryParameters(s);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -216,11 +216,11 @@ var monkey_patch = function() {
|
|||||||
*/
|
*/
|
||||||
jQuery._ajax = jQuery.ajax;
|
jQuery._ajax = jQuery.ajax;
|
||||||
jQuery.ajax = function(settings) {
|
jQuery.ajax = function(settings) {
|
||||||
url = normalize_path(settings.url);
|
url = normalizePath(settings.url);
|
||||||
if (is_virtual(url)) {
|
if (isVirtual(url)) {
|
||||||
var result;
|
var result;
|
||||||
var data;
|
var data;
|
||||||
data = retrieve_file(url);
|
data = retrieveFile(url);
|
||||||
result = settings.complete({responseText: data}, "");
|
result = settings.complete({responseText: data}, "");
|
||||||
return; // Return value not actually needed in searchtools.js
|
return; // Return value not actually needed in searchtools.js
|
||||||
} else {
|
} else {
|
||||||
@ -229,15 +229,15 @@ var monkey_patch = function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
monkey_patch();
|
monkeyPatch();
|
||||||
|
|
||||||
// Set up message listener
|
// Set up message listener
|
||||||
window.addEventListener("message", (evnt) => {
|
window.addEventListener("message", (evnt) => {
|
||||||
console.log("Received message in iframe", evnt);
|
console.log("Received message in iframe", evnt);
|
||||||
if (evnt.data.action == 'set_data') {
|
if (evnt.data.action == 'set_data') {
|
||||||
on_set_data(evnt.data.argument);
|
onSetData(evnt.data.argument);
|
||||||
} else if (evnt.data.action == 'scroll_to_anchor') {
|
} else if (evnt.data.action == 'scroll_to_anchor') {
|
||||||
on_scroll_to_anchor(evnt.data.argument);
|
onScrollToAnchor(evnt.data.argument);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* creative.
|
* creative.
|
||||||
*
|
*
|
||||||
* Here, we patch the `URLSearchParams` class so it returns the information
|
* Here, we patch the `URLSearchParams` class so it returns the information
|
||||||
* stored in `window.global_context.get_parameters`.
|
* stored in `window.globalContext.getParameters`.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -16,12 +16,12 @@ const originalGet = URLSearchParams.prototype.get;
|
|||||||
var myGet = function (arg) {
|
var myGet = function (arg) {
|
||||||
// If searchtools.js of sphinx is used
|
// If searchtools.js of sphinx is used
|
||||||
if (
|
if (
|
||||||
window.global_context &&
|
window.globalContext &&
|
||||||
window.global_context.get_parameters &&
|
window.globalContext.getParameters &&
|
||||||
(window.location.search === "") &&
|
(window.location.search === "") &&
|
||||||
(Array.from(this.entries()).length == 0)
|
(Array.from(this.entries()).length == 0)
|
||||||
) {
|
) {
|
||||||
const params = new URLSearchParams('?' + window.global_context.get_parameters);
|
const params = new URLSearchParams('?' + window.globalContext.getParameters);
|
||||||
const result = params.get(arg);
|
const result = params.get(arg);
|
||||||
// console.log("Return virtual get parameter:", arg, result);
|
// console.log("Return virtual get parameter:", arg, result);
|
||||||
return result;
|
return result;
|
||||||
@ -80,18 +80,18 @@ var _base64ToArrayBuffer = function (base64) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
window.fetch = async (...args) => {
|
window.fetch = async (...args) => {
|
||||||
// wait until global_context is ready
|
// wait until globalContext is ready
|
||||||
try {
|
try {
|
||||||
await waitFor(() => window.hasOwnProperty("global_context"), 10000);
|
await waitFor(() => window.hasOwnProperty("globalContext"), 10000);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
let [resource, config ] = args;
|
let [resource, config ] = args;
|
||||||
var path = normalize_path(resource);
|
var path = normalizePath(resource);
|
||||||
var response;
|
var response;
|
||||||
if (is_virtual(path)) {
|
if (isVirtual(path)) {
|
||||||
var file = retrieve_file(path);
|
var file = retrieveFile(path);
|
||||||
var data = file.data;
|
var data = file.data;
|
||||||
if (file.base64encoded) {
|
if (file.base64encoded) {
|
||||||
data = _base64ToArrayBuffer(data);
|
data = _base64ToArrayBuffer(data);
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
const iFrameId = 'zundler-iframe';
|
const iFrameId = 'zundler-iframe';
|
||||||
|
|
||||||
var set_favicon = function(href) {
|
var setFavicon = function(href) {
|
||||||
if (!href) {return;}
|
if (!href) {return;}
|
||||||
var favicon = document.createElement("link");
|
var favicon = document.createElement("link");
|
||||||
favicon.setAttribute('rel', 'shortcut icon');
|
favicon.setAttribute('rel', 'shortcut icon');
|
||||||
href = normalize_path(href);
|
href = normalizePath(href);
|
||||||
const file = window.global_context.file_tree[href];
|
const file = window.globalContext.fileTree[href];
|
||||||
if (!file) {return;}
|
if (!file) {return;}
|
||||||
if (file.mime_type == 'image/svg+xml') {
|
if (file.mime_type == 'image/svg+xml') {
|
||||||
favicon.setAttribute('href', 'data:' + file.mime_type + ';charset=utf-8;base64,' + btoa(file.data));
|
favicon.setAttribute('href', 'data:' + file.mime_type + ';charset=utf-8;base64,' + btoa(file.data));
|
||||||
@ -31,10 +31,10 @@ var createIframe = function() {
|
|||||||
return iframe;
|
return iframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
var retrieve_file = function(path) {
|
var retrieveFile = function(path) {
|
||||||
// console.log("Retrieving file: " + path);
|
// console.log("Retrieving file: " + path);
|
||||||
var file_tree = window.global_context.file_tree;
|
var fileTree = window.globalContext.fileTree;
|
||||||
var file = file_tree[path];
|
var file = fileTree[path];
|
||||||
if (!file) {
|
if (!file) {
|
||||||
console.warn("File not found: " + path);
|
console.warn("File not found: " + path);
|
||||||
return "";
|
return "";
|
||||||
@ -43,7 +43,7 @@ var retrieve_file = function(path) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var is_virtual = function(url) {
|
var isVirtual = function(url) {
|
||||||
// Return true if the url should be retrieved from the virtual file tree
|
// Return true if the url should be retrieved from the virtual file tree
|
||||||
var _url = url.toString().toLowerCase();
|
var _url = url.toString().toLowerCase();
|
||||||
return (! (
|
return (! (
|
||||||
@ -57,13 +57,13 @@ var is_virtual = function(url) {
|
|||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
var split_url = function(url) {
|
var splitUrl = function(url) {
|
||||||
// Return a list of three elements: path, GET parameters, anchor
|
// Return a list of three elements: path, GET parameters, anchor
|
||||||
var anchor = url.split('#')[1] || "";
|
var anchor = url.split('#')[1] || "";
|
||||||
var get_parameters = url.split('#')[0].split('?')[1] || "";
|
var getParameters = url.split('#')[0].split('?')[1] || "";
|
||||||
var path = url.split('#')[0];
|
var path = url.split('#')[0];
|
||||||
path = path.split('?')[0];
|
path = path.split('?')[0];
|
||||||
let result = [path, get_parameters, anchor];
|
let result = [path, getParameters, anchor];
|
||||||
// console.log("Split URL", url, result);
|
// console.log("Split URL", url, result);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@ -83,7 +83,7 @@ var prepare = function(html) {
|
|||||||
// problematic characters: `, ", ', &, </script>, ...
|
// problematic characters: `, ", ', &, </script>, ...
|
||||||
// atob is insufficient, because it only deals with ASCII - we have
|
// atob is insufficient, because it only deals with ASCII - we have
|
||||||
// unicode
|
// unicode
|
||||||
var serializedGC = unicodeToBase64(JSON.stringify(window.global_context));
|
var serializedGC = unicodeToBase64(JSON.stringify(window.globalContext));
|
||||||
|
|
||||||
scriptTag.textContent = `
|
scriptTag.textContent = `
|
||||||
function base64ToUnicode(base64String) {
|
function base64ToUnicode(base64String) {
|
||||||
@ -91,34 +91,34 @@ var prepare = function(html) {
|
|||||||
return decodeURIComponent(escape(utf8EncodedString));
|
return decodeURIComponent(escape(utf8EncodedString));
|
||||||
}
|
}
|
||||||
|
|
||||||
window.global_context = JSON.parse(base64ToUnicode("${serializedGC}"));
|
window.globalContext = JSON.parse(base64ToUnicode("${serializedGC}"));
|
||||||
`;
|
`;
|
||||||
|
|
||||||
doc.head.prepend(scriptTag);
|
doc.head.prepend(scriptTag);
|
||||||
|
|
||||||
embed_js(doc);
|
embedJs(doc);
|
||||||
embed_css(doc);
|
embedCss(doc);
|
||||||
embed_imgs(doc);
|
embedImgs(doc);
|
||||||
|
|
||||||
fix_links(doc);
|
fixLinks(doc);
|
||||||
fix_forms(doc);
|
fixForms(doc);
|
||||||
|
|
||||||
return doc.documentElement.outerHTML;
|
return doc.documentElement.outerHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
var embed_js = function(doc) {
|
var embedJs = function(doc) {
|
||||||
Array.from(doc.querySelectorAll("script")).forEach( oldScript => {
|
Array.from(doc.querySelectorAll("script")).forEach( oldScript => {
|
||||||
const newScript = doc.createElement("script");
|
const newScript = doc.createElement("script");
|
||||||
Array.from(oldScript.attributes).forEach( attr => {
|
Array.from(oldScript.attributes).forEach( attr => {
|
||||||
newScript.setAttribute(attr.name, attr.value);
|
newScript.setAttribute(attr.name, attr.value);
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
if (newScript.hasAttribute('src') && is_virtual(newScript.getAttribute('src'))) {
|
if (newScript.hasAttribute('src') && isVirtual(newScript.getAttribute('src'))) {
|
||||||
var src = newScript.getAttribute('src');
|
var src = newScript.getAttribute('src');
|
||||||
let [path, get_parameters, anchor] = split_url(src);
|
let [path, getParameters, anchor] = splitUrl(src);
|
||||||
path = normalize_path(path);
|
path = normalizePath(path);
|
||||||
console.debug("Embed script: " + path);
|
console.debug("Embed script: " + path);
|
||||||
var src = retrieve_file(path).data + ' \n//# sourceURL=' + path;
|
var src = retrieveFile(path).data + ' \n//# sourceURL=' + path;
|
||||||
newScript.appendChild(doc.createTextNode(src));
|
newScript.appendChild(doc.createTextNode(src));
|
||||||
newScript.removeAttribute('src');
|
newScript.removeAttribute('src');
|
||||||
oldScript.parentNode.replaceChild(newScript, oldScript);
|
oldScript.parentNode.replaceChild(newScript, oldScript);
|
||||||
@ -131,31 +131,31 @@ var embed_js = function(doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var embed_css = function(doc) {
|
var embedCss = function(doc) {
|
||||||
Array.from(doc.querySelectorAll("link")).forEach( link => {
|
Array.from(doc.querySelectorAll("link")).forEach( link => {
|
||||||
if (link.getAttribute('rel') == 'stylesheet' && link.getAttribute("href")) {
|
if (link.getAttribute('rel') == 'stylesheet' && link.getAttribute("href")) {
|
||||||
const style = doc.createElement("style");
|
const style = doc.createElement("style");
|
||||||
var href = link.getAttribute('href');
|
var href = link.getAttribute('href');
|
||||||
let [path, get_parameters, anchor] = split_url(href);
|
let [path, getParameters, anchor] = splitUrl(href);
|
||||||
path = normalize_path(path);
|
path = normalizePath(path);
|
||||||
style.textContent = retrieve_file(path).data;
|
style.textContent = retrieveFile(path).data;
|
||||||
link.replaceWith(style);
|
link.replaceWith(style);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var fix_links = function(doc) {
|
var fixLinks = function(doc) {
|
||||||
Array.from(doc.querySelectorAll("a")).forEach( a => {
|
Array.from(doc.querySelectorAll("a")).forEach( a => {
|
||||||
fix_link(a);
|
fixLink(a);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var fix_link = function(a) {
|
var fixLink = function(a) {
|
||||||
if (is_virtual(a.getAttribute('href'))) {
|
if (isVirtual(a.getAttribute('href'))) {
|
||||||
// a.addEventListener('click', virtual_click);
|
// a.addEventListener('click', virtualClick);
|
||||||
a.setAttribute("onclick", "virtual_click(event)");
|
a.setAttribute("onclick", "virtualClick(event)");
|
||||||
} else if (a.getAttribute('href').startsWith('#')) {
|
} else if (a.getAttribute('href').startsWith('#')) {
|
||||||
a.setAttribute('href', "about:srcdoc" + a.getAttribute('href'))
|
a.setAttribute('href', "about:srcdoc" + a.getAttribute('href'))
|
||||||
} else if (!a.getAttribute('href').startsWith('about:srcdoc')) {
|
} else if (!a.getAttribute('href').startsWith('about:srcdoc')) {
|
||||||
@ -166,28 +166,28 @@ var fix_link = function(a) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var fix_form = function(form) {
|
var fixForm = function(form) {
|
||||||
var href = form.getAttribute('action');
|
var href = form.getAttribute('action');
|
||||||
if (is_virtual(href) && form.getAttribute('method').toLowerCase() == 'get') {
|
if (isVirtual(href) && form.getAttribute('method').toLowerCase() == 'get') {
|
||||||
// form.addEventListener('submit', virtual_click);
|
// form.addEventListener('submit', virtualClick);
|
||||||
form.setAttribute("onsubmit", "virtual_click(event)");
|
form.setAttribute("onsubmit", "virtualClick(event)");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var fix_forms = function(doc) {
|
var fixForms = function(doc) {
|
||||||
Array.from(doc.querySelectorAll("form")).forEach( form => {
|
Array.from(doc.querySelectorAll("form")).forEach( form => {
|
||||||
fix_form(form);
|
fixForm(form);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var embed_img = function(img) {
|
var embedImg = function(img) {
|
||||||
if (img.hasAttribute('src')) {
|
if (img.hasAttribute('src')) {
|
||||||
const src = img.getAttribute('src');
|
const src = img.getAttribute('src');
|
||||||
if (is_virtual(src)) {
|
if (isVirtual(src)) {
|
||||||
var path = normalize_path(src);
|
var path = normalizePath(src);
|
||||||
const file = retrieve_file(path);
|
const file = retrieveFile(path);
|
||||||
const mime_type = file.mime_type;
|
const mime_type = file.mime_type;
|
||||||
if (mime_type == 'image/svg+xml') {
|
if (mime_type == 'image/svg+xml') {
|
||||||
img.setAttribute('src', "data:image/svg+xml;charset=utf-8;base64, " + btoa(file.data));
|
img.setAttribute('src', "data:image/svg+xml;charset=utf-8;base64, " + btoa(file.data));
|
||||||
@ -199,18 +199,18 @@ var embed_img = function(img) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var embed_imgs = function(doc) {
|
var embedImgs = function(doc) {
|
||||||
Array.from(doc.querySelectorAll("img")).forEach( img => {
|
Array.from(doc.querySelectorAll("img")).forEach( img => {
|
||||||
embed_img(img);
|
embedImg(img);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var load_virtual_page = (function (path, get_params, anchor) {
|
var loadVirtualPage = (function (path, get_params, anchor) {
|
||||||
// fill the iframe with the new page
|
// fill the iframe with the new page
|
||||||
// return True if it worked
|
// return True if it worked
|
||||||
// return False if loading indicator should be removed right away
|
// return False if loading indicator should be removed right away
|
||||||
const file = window.global_context.file_tree[path];
|
const file = window.globalContext.fileTree[path];
|
||||||
var iframe = createIframe();
|
var iframe = createIframe();
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@ -219,11 +219,11 @@ var load_virtual_page = (function (path, get_params, anchor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = file.data;
|
const data = file.data;
|
||||||
window.global_context.get_parameters = get_params;
|
window.globalContext.getParameters = get_params;
|
||||||
|
|
||||||
if (file.mime_type == 'text/html') {
|
if (file.mime_type == 'text/html') {
|
||||||
window.global_context.current_path = path;
|
window.globalContext.current_path = path;
|
||||||
window.global_context.anchor = anchor;
|
window.globalContext.anchor = anchor;
|
||||||
const html = prepare(data);
|
const html = prepare(data);
|
||||||
iframe.setAttribute("srcdoc", html);
|
iframe.setAttribute("srcdoc", html);
|
||||||
window.history.pushState({path, get_params, anchor}, '', '#');
|
window.history.pushState({path, get_params, anchor}, '', '#');
|
||||||
@ -237,10 +237,10 @@ var load_virtual_page = (function (path, get_params, anchor) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var normalize_path = function(path) {
|
var normalizePath = function(path) {
|
||||||
// TODO remove redundant definition of this function (in inject.js)
|
// TODO remove redundant definition of this function (in inject.js)
|
||||||
// make relative paths absolute
|
// make relative paths absolute
|
||||||
var result = window.global_context.current_path;
|
var result = window.globalContext.current_path;
|
||||||
result = result.split('/');
|
result = result.split('/');
|
||||||
result.pop();
|
result.pop();
|
||||||
result = result.concat(path.split('/'));
|
result = result.concat(path.split('/'));
|
||||||
@ -259,7 +259,7 @@ var normalize_path = function(path) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
result = array.join('/');
|
result = array.join('/');
|
||||||
// console.log(`Normalized path: ${path} -> ${result} (@${window.global_context.current_path})`);
|
// console.log(`Normalized path: ${path} -> ${result} (@${window.globalContext.current_path})`);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -271,33 +271,33 @@ window.onload = function() {
|
|||||||
var iframe = document.getElementById(iFrameId);
|
var iframe = document.getElementById(iFrameId);
|
||||||
|
|
||||||
if (evnt.data.action == 'ready') {
|
if (evnt.data.action == 'ready') {
|
||||||
// iframe is ready to receive the global_context
|
// iframe is ready to receive the globalContext
|
||||||
iframe.contentWindow.postMessage({
|
iframe.contentWindow.postMessage({
|
||||||
action: "set_data",
|
action: "set_data",
|
||||||
argument: window.global_context,
|
argument: window.globalContext,
|
||||||
}, "*");
|
}, "*");
|
||||||
|
|
||||||
} else if (evnt.data.action == 'set_title') {
|
} else if (evnt.data.action == 'set_title') {
|
||||||
// iframe has finished loading and sent us its title
|
// iframe has finished loading and sent us its title
|
||||||
// parent sets the title and responds with the global_context object
|
// parent sets the title and responds with the globalContext object
|
||||||
window.document.title = evnt.data.argument.title;
|
window.document.title = evnt.data.argument.title;
|
||||||
set_favicon(evnt.data.argument.favicon);
|
setFavicon(evnt.data.argument.favicon);
|
||||||
|
|
||||||
} else if (evnt.data.action == 'virtual_click') {
|
} else if (evnt.data.action == 'virtualClick') {
|
||||||
// user has clicked on a link in the iframe
|
// user has clicked on a link in the iframe
|
||||||
show_loading_indictator();
|
showLoadingIndicator();
|
||||||
var loaded = load_virtual_page(
|
var loaded = loadVirtualPage(
|
||||||
evnt.data.argument.path,
|
evnt.data.argument.path,
|
||||||
evnt.data.argument.get_parameters,
|
evnt.data.argument.getParameters,
|
||||||
evnt.data.argument.anchor,
|
evnt.data.argument.anchor,
|
||||||
);
|
);
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
hide_loading_indictator();
|
hideLoadingIndicator();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (evnt.data.action == 'show_iframe') {
|
} else if (evnt.data.action == 'show_iframe') {
|
||||||
// iframe finished fixing the document and is ready to be shown;
|
// iframe finished fixing the document and is ready to be shown;
|
||||||
hide_loading_indictator();
|
hideLoadingIndicator();
|
||||||
iframe.contentWindow.postMessage({
|
iframe.contentWindow.postMessage({
|
||||||
action: "scroll_to_anchor",
|
action: "scroll_to_anchor",
|
||||||
}, "*");
|
}, "*");
|
||||||
@ -306,15 +306,15 @@ window.onload = function() {
|
|||||||
|
|
||||||
// Set up history event listener
|
// Set up history event listener
|
||||||
window.addEventListener("popstate", (evnt) => {
|
window.addEventListener("popstate", (evnt) => {
|
||||||
load_virtual_page(evnt.state.path, evnt.state.get_params, evnt.state.anchor);
|
loadVirtualPage(evnt.state.path, evnt.state.get_params, evnt.state.anchor);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load first page
|
// Load first page
|
||||||
load_virtual_page(window.global_context.current_path, "", "");
|
loadVirtualPage(window.globalContext.current_path, "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var show_loading_indictator = function() {
|
var showLoadingIndicator = function() {
|
||||||
var iframe = document.getElementById(iFrameId);
|
var iframe = document.getElementById(iFrameId);
|
||||||
iframe.remove()
|
iframe.remove()
|
||||||
var loading = document.getElementById('loading-indicator');
|
var loading = document.getElementById('loading-indicator');
|
||||||
@ -322,7 +322,7 @@ var show_loading_indictator = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var hide_loading_indictator = function() {
|
var hideLoadingIndicator = function() {
|
||||||
var iframe = document.getElementById(iFrameId);
|
var iframe = document.getElementById(iFrameId);
|
||||||
iframe.style.display = '';
|
iframe.style.display = '';
|
||||||
var loading = document.getElementById('loading-indicator');
|
var loading = document.getElementById('loading-indicator');
|
||||||
|
@ -98,7 +98,7 @@ https://github.com/AdrianVollmer/Zundler
|
|||||||
<html>
|
<html>
|
||||||
<head><style>{style}</style></head>
|
<head><style>{style}</style></head>
|
||||||
<body>{body}
|
<body>{body}
|
||||||
<script>window.global_context = "{global_context}"</script>
|
<script>window.globalContext = "{global_context}"</script>
|
||||||
<script>{pako} \n//# sourceURL=pako.js</script>
|
<script>{pako} \n//# sourceURL=pako.js</script>
|
||||||
<script>{bootstrap} \n//# sourceURL=boostrap.js</script>
|
<script>{bootstrap} \n//# sourceURL=boostrap.js</script>
|
||||||
</body><!-- {license} --></html>
|
</body><!-- {license} --></html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user