Tuesday, November 3, 2026

Creating Sub menu in Chrome extension - snippet for selecting 5th value in drop down list

 background.js

// 1. Create the main parent menu item

chrome.runtime.onInstalled.addListener(() => {

  chrome.contextMenus.create({

    id: "parentMenu",

    title: "My Extension Options",

    contexts: ["all"] // Shows up on text selection, links, pages, etc.

  });


  // 2. Create sub-menu items linked to the parent ID

  chrome.contextMenus.create({

    id: "subMenu1",

    parentId: "parentMenu",

    title: "Select 5th Option",

    contexts: ["all"]

  });


  chrome.contextMenus.create({

    id: "subMenu2",

    parentId: "parentMenu",

    title: "Clear Selection",

    contexts: ["all"]

  });

});


// 3. Handle clicks on the sub-menu items

chrome.contextMenus.onClicked.addListener(async (info, tab) => {

  if (info.menuItemId === "subMenu1") {

    // Inject a script into the active page to select the 5th value

const activeTabId = info.tabId || (tab && tab.id);

    debugger;

    if (!activeTabId) {

      console.error("No active tab ID found.");

      return;

    }

    chrome.scripting.executeScript({

      target: { tabId: tab.id },

      func: selectFifthValue

    });

  } else if (info.menuItemId === "subMenu2") {

    console.log("Sub-menu 2 clicked!");

  }

});


// This function runs directly inside the web page's context

function selectFifthValue() {

  const selectElement = document.querySelector('select[formcontrolname="sectionName"]');

  if (selectElement && selectElement.options.length >= 5) {

    selectElement.selectedIndex = 5;

    selectElement.dispatchEvent(new Event('change', { bubbles: true }));

  }

  else {

  console.error("Dropdown not found. Check if your formControlName is correct.");

}

}

Saturday, October 31, 2026

Environment variable in windows

 >Right click on My computer

> Go to advanced system settings

> Click on Environment variable 

> Create a new User variable

> Enter variable name and value (example name yash and value is d:/)

> Press window button + R and then type %yash%

Thursday, October 29, 2026

How to call a function two time in chrome extension - also click on search and view in function snippets - Create Right Click in chrome with chrome extension

 menifest.json

{

  "manifest_version": 3,

  "name": "Run Snippet from Right Click",

  "version": "1.0",

  "permissions": [

    "contextMenus",

    "activeTab",

    "scripting","storage"

  ],

  "background": {

    "service_worker": "background.js"

  }

}

Tuesday, October 27, 2026

How to create extension and load extension in chrome

 

Step 1: Create a Folder

Create a new folder on your computer and name it something like SearchAndViewExtension.

Step 2: Create the Configuration File (manifest.json)

Inside that folder, create a file named manifest.json and paste the following code. This tells Chrome to register a background service worker and requests permission to run scripts:

json

{

  "manifest_version": 3,

  "name": "Run Snippet from Right Click",

  "version": "1.0",

  "permissions": [

    "contextMenus",

    "activeTab",

    "scripting"

  ],

  "background": {

    "service_worker": "background.js"

  }

}

Use code with caution.

Step 3: Create the Background Script (background.js)

Inside the same folder, create a file named background.js. This script creates the actual right-click menu item and injects your click automation automation script into the page when clicked:

javascript

// 1. Create the right-click menu item when the extension installs

chrome.runtime.onInstalled.addListener(() => {

  chrome.contextMenus.create({

    id: "runSearchAndViewAutomation",

    title: "Run Search & View Automation",

    contexts: ["all"] // Makes it appear on any right-click

  });

});

 

// 2. Listen for clicks on your custom menu item

chrome.contextMenus.onClicked.addListener((info, tab) => {

  if (info.menuItemId === "runSearchAndViewAutomation") {

    // Inject and execute your snippet script directly onto the active tab

    chrome.scripting.executeScript({

      target: { tabId: tab.id },

      func: automatedSearchAndView

    });

  }

});

 

// 3. Your core snippet script wrapped in a function

async function automatedSearchAndView() {

  const searchButton = document.querySelector('#search-btn-id'); // <-- Change selector as needed

 

  if (!searchButton) {

    console.error("Automation Stopped: Search button not found.");

    return;

  }

 

  searchButton.click();

  console.log("Search button clicked. Monitoring DOM for the anchor tag...");

 

  const waitForElement = (selector, timeout = 5000) => {

    return new Promise((resolve, reject) => {

      const startTime = Date.now();

      const interval = setInterval(() => {

        const element = document.querySelector(selector);

        if (element) {

          clearInterval(interval);

          resolve(element);

        } else if (Date.now() - startTime > timeout) {

          clearInterval(interval);

          reject(new Error(`Automation Timeout: Link "${selector}" not found.`));

        }

      }, 100);

    });

  };

 

  try {

    const viewAnchor = await waitForElement('a.your-class-name'); // <-- Change selector as needed

   

    if (viewAnchor.href && viewAnchor.href !== '#' && !viewAnchor.href.startsWith('javascript:')) {

      window.location.href = viewAnchor.href;

    } else {

      viewAnchor.click();

    }

  } catch (error) {

    console.error(error.message);

  }

}

Use code with caution.

Step 4: Load it into Google Chrome

1.      Open Chrome and navigate to chrome://extensions/

2.      Turn ON the toggle switch for Developer mode in the top-right corner.

3.      Click the Load unpacked button in the top-left corner.

4.      Select the SearchAndViewExtension folder you created.

 

Wednesday, October 21, 2026

How to slow a computer - How to check computer speed online GPU speed and CPU speed

 In c drive where is windows installed , Make memory to 0 mb

drive free space to 1 mb


2) Open a large excel file with2 gb and copy form one excel file to another


To check gpu speed and slow down computer


 https://mprep.info/gpu/