Ich kann nicht herausfinden, wie ich dieses Skript anpassen kann, das Text in Safari hervorhebt, damit es mit Google Chrome funktioniert:
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
Hier ist meine Google Chrome-Version:
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
Antwort :
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
Stellen Sie sicher, dass Sie JavaScript von AppleScript in Google Chrome aktiviert haben
Das Ausführen von JavaScript über AppleScript ist deaktiviert. Um es zu aktivieren, gehen Sie in der Menüleiste zu Ansicht > Entwickler > JavaScript von Apple-Ereignissen zulassen.
Ich habe ein paar Änderungen an Ihrem Skript vorgenommen, damit es funktioniert, wobei die Änderungen fett hervorgehoben sind.
tell window 1
, nicht nur ein Verb. Ich habe to tell window 1
den beigefügten Teil des Antrags ergänzt.setze myList auf {"AppleScript", "2018", "CLOSED"} Sagen Sie der Anwendung "Google Chrome" , dass sie Fenster 1 anweisen soll , das aktive Tab- Javascript "document.designMode = 'on';" auszuführen . -- scrollPos und Seitenversatz entfernt Wiederholen Sie dies mit thisText in myListAktives Tab- Javascript ausführen "var sel = window.getSelection(); sel.collapse(document.body, 0); while (window.find('" & thisText & "', true)) {document.execCommand('HiliteColor', false, '#5cdf64');} sel.collapseToEnd()" Ende wiederholenAktives Tab- Javascript ausführen "document.designMode = 'off';" -- scrollPos und Seitenversatz entfernt Ende erzählen
Um es auf allen Registerkarten auszuführen, umschließen Sie es mit repeat with atab in tabs
:
Sagen Sie der Anwendung "Google Chrome", dass sie Fenster 1 anweisen soll , mit atab in Registerkarten zu wiederholen. führen Sie atab javascript "document.designMode = 'on';" aus. -- scrollPos und Seitenversatz entfernt Wiederholen Sie dies mit thisText in myListatab javascript ausführen "var sel = window.getSelection(); sel.collapse(document.body, 0); while (window.find('" & thisText & "', true)) {document.execCommand('HiliteColor', false, '#5cdf64');} sel.collapseToEnd()" Ende wiederholenatab javascript ausführen "document.designMode = 'off';" -- scrollPos und Seitenversatz entfernt end repeat end tell
repeat with atab in tabs
, siehe Bearbeiten
grg
'window.find()' command
Zeile ein "unbekanntes Token" steht. War diese Zeile als Kommentar gedacht? Woher hast du das Skript?db
Kevin