Skip to content
Abhijeet Phirke edited this page Apr 18, 2018 · 1 revision

// background.js

// Called when the user clicks on the browser action. chrome.browserAction.onClicked.addListener(function (tab) { // Send a message to the active tab chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { var activeTab = tabs[0]; chrome.tabs.sendMessage(activeTab.id, { "message": "clicked_browser_action" }); }); });

// receive url and work it out chrome.runtime.onMessage.addListener( function (request, sender, sendResponse) { if (request.message === "open_new_tab") { chrome.tabs.create({ "url": request.url, "active": false }, function (tab) { chrome.tabs.executeScript(tab.id, { code: request.url.includes("idlebrain") ? "window.location.href=document.querySelector("div[align=center] > img[src$='.jpg']").src;" : "window.location.href=document.querySelector("#_pagecontent_photoimg1").src;", allFrames: true }) }); } } );

Clone this wiki locally