No consigo averiguar cómo adaptar este script, que resalta texto en Safari, para que funcione con Google Chrome:
set myList to {"AppleScript", "2018", "demo@apple.com"}
tell application "Safari"
'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();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('" & thisText & "', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n 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
Aquí está mi versión de Google Chrome :
set myList to {"AppleScript", "2018", "CLOSED"}
tell application "Google Chrome"
tell tab 3 of window 1 to set scrollPos to execute javascript "document.designMode = 'on'; [window.pageXOffset.toString(),window.pageYOffset.toString()]"
repeat with thisText in myList
execute javascript "var sel = window.getSelection();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('" & thisText & "', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n sel.collapseToEnd()"
end repeat
execute javascript "document.designMode = 'off'; window.scrollTo(" & (item 1 of scrollPos) & ", " & (item 2 of scrollPos) & ")"
end tell
Responder :
tell application "Google Chrome"
execute tab 3 of window 1 javascript "document.designMode = 'on'; [window.pageXOffset.toString(),window.pageYOffset.toString()]"
--> {"0", "0"}
execute current application javascript "var sel = window.getSelection();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('AppleScript', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n sel.collapseToEnd()"
--> missing value
execute current application javascript "var sel = window.getSelection();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('2018', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n sel.collapseToEnd()"
--> missing value
execute current application javascript "var sel = window.getSelection();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('CLOSED', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n sel.collapseToEnd()"
--> missing value
execute current application javascript "document.designMode = 'off'; window.scrollTo(0, 0)"
--> missing value
end tell
Result:
missing value