Skip to content

Commit

Permalink
Extension added
Browse files Browse the repository at this point in the history
  • Loading branch information
P-lavanya16 committed Aug 10, 2024
1 parent 4748ad5 commit 895d8b7
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
40 changes: 40 additions & 0 deletions blend and run/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "blendAndRun",
title: "Blend and Run",
contexts: ["selection", "page"]
});

chrome.contextMenus.create({
id: "copyText",
title: "Copy Selected Text",
parentId: "blendAndRun",
contexts: ["selection"]
});

chrome.contextMenus.create({
id: "runScript",
title: "Run Custom Script",
parentId: "blendAndRun",
contexts: ["page"]
});
});

chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "copyText" && info.selectionText) {
copyToClipboard(info.selectionText);
} else if (info.menuItemId === "runScript") {
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ['customScript.js']
});
}
});

function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
alert('Text copied to clipboard!');
}, (err) => {
console.error('Failed to copy text: ', err);
});
}
2 changes: 2 additions & 0 deletions blend and run/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Example custom script
alert('Custom Script Executed!');
Binary file added blend and run/images/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blend and run/images/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blend and run/images/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions blend and run/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"manifest_version": 3,
"name": "Blend and Run Extension",
"version": "1.0",
"description": "An extension that blends multiple utilities and allows running custom scripts.",
"permissions": [
"activeTab",
"scripting",
"storage",
"contextMenus"
],
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
}
},
"icons": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
}
}
18 changes: 18 additions & 0 deletions blend and run/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Blend and Run</title>
<style>
button {
font-size: 14px;
padding: 10px;
margin: 5px;
}
</style>
</head>
<body>
<button id="copy-btn">Copy Selected Text</button>
<button id="run-script-btn">Run Custom Script</button>
<script src="popup.js"></script>
</body>
</html>

0 comments on commit 895d8b7

Please sign in to comment.