我无法弄清楚如何调整这个突出显示Safari文本的脚本,以使其与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
这是我的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
回复:
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
只是好奇,这个脚本的目的是什么?
—
2015年
很难解释,但基本上我得到变量这样的名称,IP和其他数据,我在不同的标签上寻找这些信息,所以突出它们真的很有助于快速发现它们
—
Kevin
'window.find()' command
线路起点处的“未知令牌”,我无法让Safari工作。这条线是否意味着评论?你从哪里得到那个剧本?