Skip to content

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil15999 committed Jan 14, 2021
0 parents commit 8194b4d
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
Binary file added assets/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
console.log("hello");
function create_new_tab(url) {
chrome.tabs.create(
{
url: url,
active: false,
},
() => {
console.log("success");
}
);
}
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.url) {
create_new_tab(request.url);
console.log(sender.tab.url);
console.log(request.url);

sendResponse({ farewell: "success" });
}
});
33 changes: 33 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"manifest_version": 2,
"name": "shortcut",
"short_name": "Search",
"description": "Searches for the selected text in the UrbanDictionary",
"version": "0.0.1",


"permissions": [
"contextMenus",
"tabs",
"activeTab"
],
"browser_action": {
"default_popup": "popup.html"
},

"icons": {
"16": "assets/search.png"
},
"content_scripts": [ {
"matches": ["<all_urls>"],

"js": ["popup.js"]
} ],

"background":{
"matches": ["<all_urls>"],
"scripts": ["background.js"],
"persistent":false

}
}
11 changes: 11 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>Shortcut Keys</title>
<h1>Shortcut Keys</h1>
<script src="popup.js"></script>
</head>
<body>
<button id="changeColor">Check this page now!</button>
</body>
</html>
65 changes: 65 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
console.log("starting");
// !send the weblink json file before executing the document event listeners

function printing_values() {
var store = new Array();
let weblinks;
var links = {};
weblinks = document.querySelectorAll(".yuRUbf");
var i;
for (i of weblinks) {
var x = i.querySelector("a").href;
store.push(x);
}
var i;
for (i = 0; i < weblinks.length; i++) {
link_status = {}; // will have the weblink and opened status
link_status["site"] = store[i].href;
link_status["opened"] = false;
links[i + 1] = link_status;
}

return links;
}

var weblinks = printing_values();

document.addEventListener("keydown", (event) => {
var l = [];
var time = [];
console.log(event);
if (event.key == "Control") {
console.log("s");
l.push(event.code);
time.push(event.timeStamp);

document.addEventListener("keydown", (event) => {
if (event.key == "Shift") {
l.push(event.code);
time.push(event.timeStamp);

console.log("h");

document.addEventListener("keydown", (event) => {
var x = event.code;
var y = x.charAt(x.length - 1);
y = parseInt(y);

l.push(event.code);
time.push(event.timeStamp);
//console.log(l);
/* TO DO:
instead of opening and switching tab
the new link be opened in new tab and current tab remains*/
console.log("hello");
chrome.runtime.sendMessage({ url: weblinks[y] }, function (response) {
console.log(response.farewell);
});

//window.open(weblinks[y], "_self");
//window.focus();
});
}
});
}
});

0 comments on commit 8194b4d

Please sign in to comment.