Jump to content

Check if you can find any typos in the batch file


Recommended Posts

Posted

This batch script should create 5 files at "C:\chrome extensions\audio-tab-detector"

Please see if you can quickly identify to  mention the typos found in this batch script 

 

@echo off
SET "EXT_DIR=C:\chrome extensions\audio-tab-detector"

REM Create the directory if it does not exist
if not exist "%EXT_DIR%" (
    mkdir "%EXT_DIR%"
)

REM Create manifest.json
(
echo {
echo   "manifest_version": 3,
echo   "name": "Audio Tab Detector",
echo   "version": "1.0",
echo   "description": "Detects the next tab with playing audio.",
echo   "permissions": [
echo     "tabs",
echo     "activeTab"
echo   ],
echo   "background": {
echo     "service_worker": "background.js"
echo   },
echo   "action": {
echo     "default_popup": "popup.html"
echo   },
echo   "web_accessible_resources": [
echo     {
echo       "resources": ["popup.html"],
echo       "matches": ["<all_urls>"]
echo     }
echo   ]
echo }
) > "%EXT_DIR%\manifest.json"

REM Check if manifest.json was created successfully
if exist "%EXT_DIR%\manifest.json" (
    echo manifest.json created successfully.
) else (
    echo Failed to create manifest.json.
)

REM Create background.js
(
echo chrome.action.onClicked.addListener(async (tab) => {
echo   const tabs = await chrome.tabs.query({});
echo   const audioTabs = tabs.filter(t =>
echo     t.audible || (t.url && t.url.includes("youtube.com/watch"))
echo   );
echo   if (audioTabs.length > 0) {
echo     const nextTab = audioTabs[(audioTabs.indexOf(tab) + 1) %% audioTabs.length];
echo     if (nextTab) {
echo       chrome.tabs.update(nextTab.id, { active: true });
echo     }
echo   } else {
echo     alert('No audio playing tabs found!');
echo   }
echo });
) > "%EXT_DIR%\background.js"

REM Check if background.js was created successfully
if exist "%EXT_DIR%\background.js" (
    echo background.js created successfully.
) else (
    echo Failed to create background.js.
)

REM Create popup.html
(
echo <!DOCTYPE html>
echo <html lang="en">
echo <head>
echo     <meta charset="UTF-8">
echo     <meta name="viewport" content="width=device-width, initial-scale=1.0">
echo     <title>Audio Tab Detector</title>
echo     <style>
echo         body {
echo             width: 200px;
echo             text-align: center;
echo         }
echo         button {
echo             margin-top: 20px;
echo         }
echo     </style>
echo </head>
echo <body>
echo     <h1>Audio Tab Detector</h1>
echo     <button id="next-audio-tab">Next Audio Tab</button>
echo     <script src="popup.js"></script>
echo </body>
echo </html>
) > "%EXT_DIR%\popup.html"

REM Check if popup.html was created successfully
if exist "%EXT_DIR%\popup.html" (
    echo popup.html created successfully.
) else (
    echo Failed to create popup.html.
)

REM Create popup.js
(
echo document.getElementById('next-audio-tab').addEventListener('click', () => {
echo  chrome.tabs.query({}, (tabs) => {
echo      let audioTabs = tabs.filter(tab => tab.audible);
echo      if (audioTabs.length > 0) {
echo          let currentTabId = tabs.filter(tab => tab.active)[0].id;
echo          let currentIndex = audioTabs.findIndex(tab => tab.id === currentTabId);
echo          let nextTabIndex = (currentIndex + 1) %% audioTabs.length;
echo          let nextTab = audioTabs[nextTabIndex];
echo          if (nextTab) {
echo              chrome.tabs.update(nextTab.id, { active: true });
echo          }
echo      } else {
echo          alert('No audio playing tabs found!');
echo      }
echo  });
echo });
) > "%EXT_DIR%\popup.js"

REM Check if popup.js was created successfully
if exist "%EXT_DIR%\popup.js" (
    echo popup.js created successfully.
) else (
    echo Failed to create popup.js.
)

echo All files created in "%EXT_DIR%"
pause

 

Posted (edited)

Hi @Deye 👋 ,

why the heck do you create an Chrome Extension via Batch? i don't see the point at all and I am very interested in your use case 😅 .

2 hours ago, Deye said:

Please see if you can quickly identify to  mention the typos found in this batch script 

Why? Sorry but no. I would copy the html and js files into VSCode and let eslint do the check.

2 hours ago, Deye said:

create 5 files

You mean 4 created files 😆 .

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted (edited)

At least one syntax error in popup.js and at least one in backgroud.js.

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...