From f0e1ef84b90c47fe135f1afe965ac3e8f075e12a Mon Sep 17 00:00:00 2001 From: uniabis Date: Tue, 28 May 2019 18:37:11 +0900 Subject: [PATCH] first commit --- background.js | 38 ++++++++++++++++++++++++++++++++++++++ manifest.json | 18 ++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 background.js create mode 100644 manifest.json diff --git a/background.js b/background.js new file mode 100644 index 0000000..0c5f5e2 --- /dev/null +++ b/background.js @@ -0,0 +1,38 @@ +chrome.contextMenus.create({ + id: "Open_new_tabs_with_selection", + title: "Open new tabs with selection", + contexts: ["selection"], +}); +chrome.contextMenus.onClicked.addListener((info, tab) => { + if (info.menuItemId === "Open_new_tabs_with_selection") { + + var x = info.selectionText.trim(); + + if ( x.startsWith('s://') ) { + x = 'p' + x; + } + if ( x.startsWith('p://') || x.startsWith('ps://') ) { + x = 't' + x; + } + if ( x.startsWith('tp://') || x.startsWith('tps://') ) { + x = 't' + x; + } + if ( x.startsWith('ttp://') || x.startsWith('ttps://') ) { + x = 'h' + x; + } + + if (chrome.extension.getURL("/").startsWith('chrome')) { + x = x.replace(/ /g,'\n'); + } + + var a = x.replace(/\r/g, '\n').replace(/\n\n/g, '\n').split('\n'); + for (var i = 0; i < a.length; i++ ) { + var u = a[i].trim(); + while (i+1 < a.length && !a[i+1].startsWith('http')) { + u = u + a[i+1].trim(); + i++; + } + chrome.tabs.create({url: u }); + } + } +}); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..9d13f25 --- /dev/null +++ b/manifest.json @@ -0,0 +1,18 @@ +{ + "manifest_version": 2, + "name": "Open new tabs with selection", + "description": "Open new tabs with selection.", + "version": "1.0", + "homepage_url": "https://github.com/uniabis/ontws", + + "background": { + "scripts": [ + "background.js" + ] + }, + + "permissions": [ + "tabs", + "contextMenus" + ] +}