Last active
July 7, 2023 07:22
-
-
Save LucaSilva-r/7c91bcc106ec2045945d55131919e4ce to your computer and use it in GitHub Desktop.
Golinelli_inject
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Golinelli editor Injection | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description try to take over the world! | |
// @author You | |
// @match https://staging-backoffice.virtual-lab.fondazionegolinelli.it/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=fondazionegolinelli.it | |
// @grant none | |
// ==/UserScript== | |
const inputTypes = [ | |
window.HTMLInputElement, | |
window.HTMLSelectElement, | |
window.HTMLTextAreaElement, | |
]; | |
const triggerInputChange = (node, value = '') => { | |
// only process the change on elements we know have a value setter in their constructor | |
if ( inputTypes.indexOf(node.__proto__.constructor) >-1 ) { | |
const setValue = Object.getOwnPropertyDescriptor(node.__proto__, 'value').set; | |
const event = new Event('input', { bubbles: true }); | |
setValue.call(node, value); | |
node.dispatchEvent(event); | |
} | |
}; | |
var targetNode = null; | |
const config = { attributes: true, childList: true, subtree: true }; | |
var iframe = document.createElement("iframe"); | |
iframe.style = "display: flex;position: relative;height: 75%;width: 75%;z-index: 1002;margin: auto;"; | |
var loading = document.createElement("img"); | |
loading.src = "https://research.silvaserv.it/custom/static/loading.gif"; | |
loading.style = "display:block; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);; height:64px; width: 64px; z-index: 1001;"; | |
var iframeContainer = document.createElement("div"); | |
iframeContainer.id= "configurators"; | |
iframeContainer.style = "display: none; background-color: rgba(0,0,0,0.5); position: absolute; z-index: 1000; height: 100dvh; width: 100dvw; top: 0px;"; | |
iframeContainer.addEventListener("click", function(event){ iframeContainer.style.display = "none";}); | |
iframeContainer.appendChild(loading); | |
iframeContainer.appendChild(iframe); | |
var saveLocation = null; | |
window.addEventListener("message", async function(event) { | |
if(typeof event.data == "number"){ | |
iframe.contentWindow.postMessage(saveLocation.value,"https://research.silvaserv.it"); | |
return; | |
} | |
if (event.origin !== "https://research.silvaserv.it") return; | |
iframeContainer.style.display = "none"; | |
//saveLocation.disabled = false; | |
triggerInputChange(saveLocation, event.data); | |
//saveLocation.disabled = true; | |
}); | |
const callback = (mutationList, observer) => { | |
for (const mutation of mutationList) { | |
if (mutation.type === "childList") { | |
} else if (mutation.type === "attributes") { | |
if(mutation.target.nodeName == "INPUT" ){ | |
if(saveLocation != mutation.target && mutation.target.getAttribute('type')== "text" && mutation.target.value.includes("filename")){ | |
if(!mutation.target.disabled){ | |
mutation.target.disabled = true; | |
} else { | |
var parent = mutation.target.parentNode.parentNode.parentNode.parentNode | |
var td = parent.firstChild | |
if(td.children.length==0){ | |
var a = document.createElement("a"); | |
a.style = "background-color: white; color:black; position: relative; float: right; padding: 5px; border-radius: 5px; border: solid white; font-weight: bold;"; | |
a.innerText = "Configura"; | |
a.addEventListener("click", function(event){ | |
saveLocation = mutation.target; | |
iframeContainer.style.display = "flex"; | |
iframe.src="https://research.silvaserv.it/custom/?external&name=" + Date.now(); | |
}); | |
td.appendChild(a); | |
} | |
} | |
} | |
} | |
} | |
} | |
}; | |
const observer = new MutationObserver(callback); | |
(function() { | |
'use strict'; | |
window.addEventListener('popstate', function (event) { | |
if (window.location.href.indexOf("step/crea") != -1){ | |
setup(); | |
} else { | |
observer.disconnect(); | |
}; | |
}); | |
if (window.location.href.indexOf("step/crea") != -1){ | |
setup(); | |
} else { | |
observer.disconnect(); | |
}; | |
})(); | |
async function setup(){ | |
const targetNode = await waitForElm("/html/body/div[1]/div[2]/div[2]"); | |
observer.observe(targetNode, config); | |
var toolsDiv = null; | |
var intervalId = null; | |
document.body.appendChild(iframeContainer); | |
} | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
function waitForElm(selector) { | |
return new Promise(resolve => { | |
if (getElementByXpath(selector)) { | |
return resolve(getElementByXpath(selector)); | |
} | |
const observer = new MutationObserver(mutations => { | |
if (getElementByXpath(selector)) { | |
resolve(getElementByXpath(selector)); | |
observer.disconnect(); | |
} | |
}); | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true | |
}); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment