mirror of
https://github.com/tcsenpai/Zundler.git
synced 2025-06-07 12:05:41 +00:00
Some refactoring; also fix anchor links
This commit is contained in:
parent
2bdf43629d
commit
d4978d55de
@ -137,12 +137,15 @@ window.onload = function() {
|
|||||||
evnt.data.argument.anchor,
|
evnt.data.argument.anchor,
|
||||||
);
|
);
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
console.log(loaded);
|
|
||||||
hide_loading_indictator();
|
hide_loading_indictator();
|
||||||
}
|
}
|
||||||
} 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();
|
hide_loading_indictator();
|
||||||
|
var iframe = document.getElementById(iFrameId);
|
||||||
|
iframe.contentWindow.postMessage({
|
||||||
|
action: "scroll_to_anchor",
|
||||||
|
}, "*");
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
@ -192,33 +192,33 @@ var fix_document = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Set up message listener
|
var on_set_data = function(argument) {
|
||||||
window.addEventListener("message", (evnt) => {
|
window.global_context = argument;
|
||||||
console.log("Received message in iframe", evnt);
|
console.log("Received data from parent", window.global_context);
|
||||||
if (evnt.data.action == 'set_data') {
|
// dynamically fix elements on this page
|
||||||
window.global_context = evnt.data.argument;
|
try {
|
||||||
console.log("Received data from parent", window.global_context);
|
fix_document();
|
||||||
// dynamically fix elements on this page
|
// Trigger DOMContentLoaded again, some scripts that have just
|
||||||
try {
|
// been executed expect it.
|
||||||
fix_document();
|
window.document.dispatchEvent(new Event("DOMContentLoaded", {
|
||||||
// Trigger DOMContentLoaded again, some scripts that have just
|
bubbles: true,
|
||||||
// been executed expect it.
|
cancelable: true
|
||||||
window.document.dispatchEvent(new Event("DOMContentLoaded", {
|
}));
|
||||||
bubbles: true,
|
} finally {
|
||||||
cancelable: true
|
observer.observe(window.document.body, {subtree: true, childList: true});
|
||||||
}));
|
window.parent.postMessage({
|
||||||
} finally {
|
action: "show_iframe",
|
||||||
observer.observe(window.document.body, {subtree: true, childList: true});
|
argument: "",
|
||||||
window.parent.postMessage({
|
}, '*');
|
||||||
action: "show_iframe",
|
|
||||||
argument: "",
|
|
||||||
}, '*');
|
|
||||||
}
|
|
||||||
if (window.global_context.anchor) {
|
|
||||||
document.location.href = "about:srcdoc#" + window.global_context.anchor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, false);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var on_scroll_to_anchor = function(argument) {
|
||||||
|
if (window.global_context.anchor) {
|
||||||
|
document.location.href = "about:srcdoc#" + window.global_context.anchor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const observer = new MutationObserver((mutationList) => {
|
const observer = new MutationObserver((mutationList) => {
|
||||||
@ -239,25 +239,6 @@ const observer = new MutationObserver((mutationList) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var main = function() {
|
|
||||||
// Set parent window title and trigger data transmission
|
|
||||||
var favicon = window.document.querySelector("link[rel*='icon']");
|
|
||||||
if (favicon) { favicon = favicon.getAttribute('href'); }
|
|
||||||
var title = window.document.querySelector('head>title');
|
|
||||||
if (title) { title = title.innerText; }
|
|
||||||
|
|
||||||
window.parent.postMessage({
|
|
||||||
action: "set_title",
|
|
||||||
argument: {
|
|
||||||
title: title,
|
|
||||||
favicon: favicon
|
|
||||||
}
|
|
||||||
}, '*');
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener('load', main);
|
|
||||||
|
|
||||||
var monkey_patch = function() {
|
var monkey_patch = function() {
|
||||||
if (typeof jQuery === 'undefined') {return;} // Only for jQuery at the moment
|
if (typeof jQuery === 'undefined') {return;} // Only for jQuery at the moment
|
||||||
/**
|
/**
|
||||||
@ -295,4 +276,35 @@ var monkey_patch = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var on_load = function() {
|
||||||
|
// Set up message listener
|
||||||
|
window.addEventListener("message", (evnt) => {
|
||||||
|
console.log("Received message in iframe", evnt);
|
||||||
|
if (evnt.data.action == 'set_data') {
|
||||||
|
on_set_data(evnt.data.argument);
|
||||||
|
} else if (evnt.data.action == 'scroll_to_anchor') {
|
||||||
|
on_scroll_to_anchor(evnt.data.argument);
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
// Set parent window title and trigger data transmission
|
||||||
|
var favicon = window.document.querySelector("link[rel*='icon']");
|
||||||
|
if (favicon) { favicon = favicon.getAttribute('href'); }
|
||||||
|
var title = window.document.querySelector('head>title');
|
||||||
|
if (title) { title = title.innerText; }
|
||||||
|
|
||||||
|
window.parent.postMessage({
|
||||||
|
action: "set_title",
|
||||||
|
argument: {
|
||||||
|
title: title,
|
||||||
|
favicon: favicon
|
||||||
|
}
|
||||||
|
}, '*');
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
window.addEventListener('load', on_load);
|
||||||
|
|
||||||
|
|
||||||
//# inject.js
|
//# inject.js
|
||||||
|
Loading…
x
Reference in New Issue
Block a user