No estoy seguro de si esto es posible, pero digamos que tengo algunas variables:
var1 "text1'
var2 "2018"
var3 "demo@apple.com"
¿Puedo hacer que Applescript encuentre cada instancia de este texto en Safari (cualquier pestaña) y cambie el color del texto? (
"document.getElementById("foundhtmlhere").style.color = "#ff0000";"
o
document.querySelector("td > a").style.backgroundColor = "red";
--
Estoy seguro de que hay una mejor opción, tal vez usando JavaScript String search()/selector pero todavía tengo que pasar por esto. Supongo que puedo buscar dentro del cuerpo usando esto, ¿entonces tal vez usando el delimitador de texto? estoy un poco perdido
tell application "Safari"
tell document 1
set body to do JavaScript "document.body.innerHTML"
set body to do JavaScript "document.getElementsByTagName('body').item(0).innerHTML"
end tell
end tell
return body
Puede usar el window.find('someString', false or true)
comando para buscar alguna cadena en el texto del documento.
El segundo parámetro del comando, si es verdadero, especifica una búsqueda que distingue entre mayúsculas y minúsculas.
Use el document.execCommand('HiliteColor', false, someColor)
comando para cambiar el color de fondo del texto fundado.
Aquí está el script de muestra, probado en Sierra .
set myList to {"text1", "2018", "demo@apple.com"}
tell application "Safari"
-- to change the color, set the 'document.designMode' to on
-- get the scroll position of the document, because the 'window.find()' command change the scroll position when it select the founded string
set scrollPos to do JavaScript "document.designMode = 'on'; [window.pageXOffset.toString(),window.pageYOffset.toString()]" in document 1
repeat with thisText in myList
do JavaScript "var sel = window.getSelection();
sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text
while (window.find('" & thisText & "', true)) {document.execCommand('HiliteColor', false, '#ff0000');}
sel.collapseToEnd()" in document 1
end repeat
-- restore the scroll position
do JavaScript "document.designMode = 'off'; window.scrollTo(" & (item 1 of scrollPos) & ", " & (item 2 of scrollPos) & ")" in document 1
end tell
Si te refieres a una página normal que visitas, como harías con un find (cmd-f) que resalta el texto, con AppleScript la respuesta es no (el diccionario de AppleScript para Safari no te da esa opción).
Si, por otro lado, quiere encontrar texto en una página html que está editando para luego cargarla, entonces sí, podría cambiar el color automáticamente con su editor html, pero creo que eso no es lo que está describiendo.
Kevin
MBUSTO
MBUSTO
Kevin
Kevin
Kevin