-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from nomandhoni-cs/add-context-menu-post
Implemented Context menu to directly post in Showwcase and Changed localstorage method
- Loading branch information
Showing
4 changed files
with
113 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
chrome.runtime.onInstalled.addListener(function() { | ||
try { | ||
chrome.contextMenus.create({ | ||
"title": "Post to Showwand", | ||
"contexts": ["selection"], | ||
"id": "showwandSelection" | ||
}, function() { | ||
if (chrome.runtime.lastError) { | ||
console.error(chrome.runtime.lastError); | ||
} else { | ||
console.log("Context menu created successfully"); | ||
} | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}); | ||
|
||
chrome.contextMenus.onClicked.addListener(function(info, tab) { | ||
try { | ||
if (info.menuItemId === "showwandSelection") { | ||
chrome.storage.local.get("showwand-api-key", function(data) { | ||
var apiKey = data["showwand-api-key"]; | ||
console.log(apiKey); | ||
if (!apiKey) { | ||
// chrome.runtime.openOptionsPage(); | ||
return; | ||
} | ||
let selectedText = info.selectionText; | ||
console.log("The selected text is: " + selectedText); | ||
postFetchFunc(selectedText, apiKey, function() { | ||
console.log("Successfully posted to Showwand"); | ||
}); | ||
}); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}); | ||
|
||
|
||
function postFetchFunc(postDescription, apiKey, callback) { | ||
try { | ||
fetch('https://cache.showwcase.com/threads', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'x-api-key': apiKey | ||
}, | ||
body: JSON.stringify({ | ||
message: postDescription | ||
}) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log(data); | ||
callback(); | ||
}) | ||
.catch(error => console.error(error)); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,34 @@ | ||
{ | ||
"name": "Showwand", | ||
"description": "A magical Browser extension, which directly post, delete in your Showwcase thread.", | ||
"version": "1.0", | ||
"manifest_version": 3, | ||
"icons": { | ||
"16": "assets/icon16.png", | ||
"32": "assets/icon32.png", | ||
"48": "assets/icon48.png", | ||
"128": "assets/icon128.png" | ||
}, | ||
"action": { | ||
"default_popup": "popup.html" | ||
}, | ||
"permissions": [ | ||
"activeTab" | ||
], | ||
"options_ui": { | ||
"page": "options.html", | ||
"open_in_tab": true | ||
}, | ||
"content_scripts": [ | ||
{ | ||
"matches": ["http://*/*", "https://*/*"], | ||
"js": ["js/content.js"], | ||
"run_at": "document_end" | ||
} | ||
], | ||
"context_menus": { | ||
"showwand": { | ||
"title": "Post in Showwcase", | ||
"contexts": ["selection"], | ||
"onclick": "handleSelection" | ||
} | ||
"name": "Showwand", | ||
"description": "A magical Browser extension, which directly post, delete in your Showwcase thread.", | ||
"version": "0.5.0", | ||
"manifest_version": 3, | ||
"icons": { | ||
"16": "assets/icon16.png", | ||
"32": "assets/icon32.png", | ||
"48": "assets/icon48.png", | ||
"128": "assets/icon128.png" | ||
}, | ||
"action": { | ||
"default_popup": "popup.html" | ||
}, | ||
"permissions": [ | ||
"activeTab", | ||
"contextMenus", | ||
"storage" | ||
], | ||
"options_ui": { | ||
"page": "options.html", | ||
"open_in_tab": true | ||
}, | ||
"content_scripts": [ | ||
{ | ||
"matches": ["http://*/*", "https://*/*"], | ||
"js": ["js/content.js"], | ||
"run_at": "document_end" | ||
} | ||
], | ||
"background": { | ||
"service_worker": "js/background.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +0,0 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Options Page</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> | ||