"; // if (type == "attribute_upsert") { // //todo // } var unique_node = false; if ("unique_node" in matchedAdjusters[i]) { unique_node = document.querySelector(matchedAdjusters[i]["unique_node"]); } if (unique_node) { console.log("SP: Do nothing. Node exists."); }else{ console.log("SP: Run adjuster."); switch (adjuster_type) { case "add_before_css_selector": nodes[j].insertAdjacentHTML('beforebegin', adjuster_content); break; case "prepend_to_css_selector": nodes[j].insertAdjacentHTML('afterbegin', adjuster_content); break; case "append_to_css_selector": nodes[j].insertAdjacentHTML('beforeend', adjuster_content); break; case "add_after_css_selector": nodes[j].insertAdjacentHTML('afterend', adjuster_content); break; case "set_attribute": var attribute = matchedAdjusters[i]["attribute_name"]; nodes[j].setAttribute(attribute, adjuster_content); break; } } } catch (error) { console.log("SP Adjuster skipped due to error:"); console.log(error); } } } }else{ // // This branch is the original MO code and is here for // backwards compatibility. // // Original MO only does a single node ever var node = document.querySelector(matchedAdjusters[i].node); if (!node) continue; var node_content = ""; if (typeof matchedAdjusters[i].content === "function") { node_content = matchedAdjusters[i].content(node); if (!node_content) continue; } else { node_content = matchedAdjusters[i].content; } // This 'outerHtmlOverride' approach is no longer used in the updated MO approach. if ("outerHtmlOverride" in matchedAdjusters[i]) { node.outerHTML = node_content; } else if(matchedAdjusters[i]['insertBefore']) { node.outerHTML = node_content + node.outerHTML; matchedAdjusters[i]['insertBefore'] = false; } else { if ("prefix" in matchedAdjusters[i]) { var delete_node = document.querySelector(matchedAdjusters[i].delete_node); if (delete_node) { delete_node.remove(); } node.innerHTML = node_content + node.innerHTML; } else if ("prepend" in matchedAdjusters[i]) { var delete_node = document.querySelector(matchedAdjusters[i].delete_node); if (delete_node) { delete_node.remove(); } node.insertAdjacentHTML('beforebegin', node_content); } else if ("suffix" in matchedAdjusters[i]) { var delete_node = document.querySelector(matchedAdjusters[i].delete_node); if (delete_node) { delete_node.remove(); } node.insertAdjacentHTML('beforeend', node_content); } else if ("postfix" in matchedAdjusters[i]) { var delete_node = document.querySelector(matchedAdjusters[i].delete_node); if (delete_node) { delete_node.remove(); } node.insertAdjacentHTML('afterend', node_content); } else { node.innerHTML = node_content; } } } } } // Monkey patch pushState so we can // add an event listener to it. var _ps = function(type) { var orig = history[type]; return function() { var rv = orig.apply(this, arguments); var e = new Event(type); e.arguments = arguments; window.dispatchEvent(e); return rv; }; }; history.pushState = _ps('pushState'); // Initialise MutationObserver var observer = new MutationObserver(respondToMutation); observer.observe(targetNode, config); scheduleDetachment(); // Add listener for pushState page updates window.addEventListener('pushState', function(e) { reattachObserver(); scheduleDetachment(); applyChanges(); }); // Add listener for popState page updates window.addEventListener('popstate', function(e) { reattachObserver(); scheduleDetachment(); applyChanges(); });