Here I tested the apple-script you mentioned from the GitHub site that you would like to translate into JXA.
It contains 2 important bugs: 1) When the script is run, the front application is one, which executes the script and not the browser. This has been erroneously ignored. 2) If you do not have the Google Chrome application installed, then the script will not even compile.
The following Apple-script fixes these 2 critical bugs. I am not a JXA expert, so I leave my script as is.
property chromium_variants : {"Google Chrome", "Chromium", "Opera", "Vivaldi", "Brave Browser", "Microsoft Edge"}
property webkit_variants : {"Safari", "Webkit"}
property browsersList : chromium_variants & webkit_variants & "firefox"
tell application "System Events"
repeat 10 times
set frontApp to name of first process whose frontmost is true
if browsersList contains frontApp then exit repeat
set visible of process frontApp to false
end repeat
end tell
if (frontApp starts with "Safari") or (frontApp starts with "Webkit") then
set videoURL to run script "tell application " & frontApp & " to return URL of front document"
set videoTitle to run script "tell application " & frontApp & " to return name of front document"
else if frontApp is "Firefox" then
set videoURL to my firefoxCurrentTabURL()
set videoTitle to my firefoxCurrentTabUTitle()
else if (frontApp starts with "Google Chrome") or (frontApp starts with "Chromium") or (frontApp starts with "Opera") or (frontApp starts with "Vivaldi") or (frontApp starts with "Brave Browser") or (frontApp starts with "Microsoft Edge") then
set videoURL to run script "tell application " & frontApp & " to return URL of active tab of first window"
set videoTitle to run script "tell application " & frontApp & " to return title of active tab of first window"
else
return "You need a supported browser as your frontmost app"
end if
return {videoURL:videoURL, videoTitle:videoTitle}
on firefoxCurrentTabURL()
-- Store the current clipboard contents.
set theClipboard to (the clipboard as record)
-- Set the clipboard to a default blank value
set the clipboard to ""
-- Bring Firefox to the front, highlight the URL in the URL field and copy it.
tell application "System Events"
set frontmost of application process "firefox" to true
keystroke "lc" using {command down}
end tell
-- Read the clipboard contents until either they change from "" or a second elapses.
repeat 10 times
delay 0.2
set theURL to the clipboard
if theURL is not "" then exit repeat
end repeat
-- Restore the old clipboard contents.
set the clipboard to theClipboard
return theURL
end firefoxCurrentTabURL
on firefoxCurrentTabUTitle()
tell application "System Events" to tell process "firefox"
set frontmost to true
set the_title to name of windows's item 1
set the_title to (do shell script "echo " & quoted form of the_title & " | tr '[' ' '")
set the_title to (do shell script "echo " & quoted form of the_title & " | tr ']' ' '")
end tell
end firefoxCurrentTabUTitle