
我是 Firefox 用戶,有什麼方法可以透過.batch
檔案取得活動標籤的 url 嗎?
例如,如果 Firefox 中活動標籤的 url 是whatever.com
,我需要whatever.com
使用bat
檔案。
答案1
只有活動選項卡才會有可通過 偵測到的標題tasklist
。所以:
tasklist /v /fi "imagename eq firefox.exe" |findstr /r /v "N/A"
或用以下方法處理FOR
:
for /f "skip=1 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe" ^|findstr /r /v "N/A"') do @echo %%b
儘管標題可能與連結不同。
和sendkeys.bat
你可以欺騙瀏覽器將其標題更改為當前連結:
@echo off
::get the title of the active page
for /f "skip=3 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe" ^|findstr /r /v "N/A nsAppShell:EventWindow"') do set "fftitle=%%b"
::get the first 10 sympols needs to be passed to the sendkeys command
set "fftitle=%fftitle:~0,10%"
::opens the console of the browser
call sendkeys.bat "%fftitle%" "{f12}"
::waits for 2 seconds
w32tm /stripchart /computer:localhost /period:2 /dataonly /samples:2 1>nul
::changing the title with the link location
call sendkeys.bat "%fftitle%" "document.title=window.location.href{ENTER}"
::wait for 3 seconds
w32tm /stripchart /computer:localhost /period:3 /dataonly /samples:2 1>nul
::get the new title
for /f "skip=3 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe" ^|findstr /r /v "N/A nsAppShell:EventWindow"') do set "fftitle=%%b"
echo "%fftitle%"
編輯。直接開啟控制台:
@echo off
::get the title of the active page
for /f "skip=3 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe" ^|findstr /r /v "N/A nsAppShell:EventWindow"') do set "fftitle=%%b"
::get the first 10 sympols needs to be passed to the sendkeys command
set "fftitle=%fftitle:~0,10%"
::opens the console of the browser
call sendkeys.bat "%fftitle%" "^+K"
::waits for 2 seconds
w32tm /stripchart /computer:localhost /period:2 /dataonly /samples:2 1>nul
::changing the title with the link location
call sendkeys.bat "%fftitle%" "document.title=window.location.href{ENTER}"
::wait for 3 seconds
w32tm /stripchart /computer:localhost /period:3 /dataonly /samples:2 1>nul
::get the new title
for /f "skip=3 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe" ^|findstr /r /v "N/A nsAppShell:EventWindow"') do set "fftitle=%%b"
echo "%fftitle%"