diff --git a/assets/search.png b/assets/search.png new file mode 100644 index 0000000..7adbab3 Binary files /dev/null and b/assets/search.png differ diff --git a/background.js b/background.js new file mode 100644 index 0000000..8cc8d53 --- /dev/null +++ b/background.js @@ -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" }); + } +}); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..51d5450 --- /dev/null +++ b/manifest.json @@ -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": [""], + + "js": ["popup.js"] + } ], + + "background":{ + "matches": [""], + "scripts": ["background.js"], + "persistent":false + + } +} \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..c7c43f5 --- /dev/null +++ b/popup.html @@ -0,0 +1,11 @@ + + + + Shortcut Keys +

Shortcut Keys

+ + + + + + diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..88d36ad --- /dev/null +++ b/popup.js @@ -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(); + }); + } + }); + } +});