Skip to content

Commit

Permalink
Inline CVF monkey patch
Browse files Browse the repository at this point in the history
  • Loading branch information
WombatFromHell committed Apr 8, 2019
1 parent 5afbecc commit 072496b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 686 deletions.
50 changes: 47 additions & 3 deletions background.js
Expand Up @@ -262,10 +262,54 @@ browser.runtime.onMessage.addListener(function(request, sender)
else if (request.name === "allowedIncognitoAccess")
return Promise.resolve(allowedIncognito);
else if (request.name === "chatViewFix") {
// inject CVF monkey patch once upon page load to fix scroll bugs
browser.tabs.executeScript(null, { code: `window.monkeyPatchCVF === undefined` })
.then(res => {
if (res) { browser.tabs.executeScript(null, { file: "ext/chatview-fix.js" }); }
});
.then(res => { if (res) { browser.tabs.executeScript({ code: `
function clickItem(b, f) {
var d = window.frames.dom_iframe;
var e = d.document.getElementById("item_" + f);
if (uncap_thread(b)) {
elem_position = $("#item_" + f).position();
scrollToItem($("li#item_" + f).get(0));
}
sLastClickedItem = f;
sLastClickedRoot = b;
if (d.document.getElementById("items_complete") && e) {
var c = find_element(e, "DIV", "fullpost");
var a = import_node(document, c);
show_item_fullpost(b, f, a);
return false
} else {
path_pieces = document.location.pathname.split("?");
parent_url = path_pieces[0];
navigate_page_no_history(d, "/frame_chatty.x?root=" + b + "&id=" + f + "&parent_url=" + parent_url);
return false
}
}
function show_item_fullpost(f, h, b) {
remove_old_fullpost(f, h, parent.document);
var k = parent.document.getElementById("root_" + f);
var e = parent.document.getElementById("item_" + h);
push_front_element(e, b);
scrollToItem(e);
e.className = add_to_className(e.className, "sel");
var c = find_element(e, "DIV", "oneline");
c.className = add_to_className(c.className, "hidden")
}
function scrollToItem(b) {
if (!elementIsVisible(b)) {
scrollToElement(b);
}
}
var monkeyPatchCVF = \`\$\{clickItem.toString()\}\$\{show_item_fullpost.toString()\}\$\{scrollToItem.toString()\}\$\{scrollToElement.toString()\}\$\{elementIsVisible.toString()\}\`;
var chatViewFixElem = document.createElement("script");
chatViewFixElem.id = "chatviewfix-wjs";
chatViewFixElem.innerHTML = monkeyPatchCVF;
var bodyRef = document.getElementsByTagName("body")[0];
bodyRef.appendChild(chatViewFixElem);
undefined;` }); } });
}
else if (request.name === "lightbox") {
let commonCode = `
Expand Down

0 comments on commit 072496b

Please sign in to comment.