2.1 fix send url in selection

This commit is contained in:
GTeam 2021-12-30 18:07:45 +01:00
parent f8841172d3
commit f25d95320f
3 changed files with 44 additions and 33 deletions

View File

@ -38,6 +38,7 @@ function urlConstruct(url, autostart) {
return JD2_API_URL + "autostart=" + autostart + "&urls=" + encodeURIComponent(url); return JD2_API_URL + "autostart=" + autostart + "&urls=" + encodeURIComponent(url);
} }
// Return an url from a text, good enought :-)
function linkify(text) { function linkify(text) {
let urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; let urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
let url = text.match(urlRegex); let url = text.match(urlRegex);
@ -65,24 +66,44 @@ browser.menus.create({
} }
}, onCreated); }, onCreated);
// Choose from info (object menus.OnClickData)
// linkUrl over selectionText
// return link or ''
function infoToUrl(info){
var url = '';
if (typeof info.linkUrl !== 'undefined'){
url = info.linkUrl;
} else {
if (typeof info.selectionText !== 'undefined'){
url = linkify(info.selectionText);
}
}
return url;
}
browser.menus.onClicked.addListener((info, tab) => { browser.menus.onClicked.addListener((info, tab) => {
var url = infoToLink(info);
if (url !== ''){
switch (info.menuItemId){ switch (info.menuItemId){
case mnGrabberId: case mnGrabberId:
url_for_JD2 = urlConstruct(info.linkUrl, 0); url_for_JD2 = urlConstruct(url, 0);
break; break;
case mnDlId: case mnDlId:
url_for_JD2 = urlConstruct(info.linkUrl, 1); url_for_JD2 = urlConstruct(url, 1);
break; break;
} }
makeRequest(url_for_JD2); console.log(url);
console.log(url_for_JD2);
// makeRequest(url_for_JD2);
}
}); });
function updateMenuItem(link) { function updateMenuItem(url) {
browser.menus.update(mnDlId, { browser.menus.update(mnDlId, {
title: 'Download: ' + link title: 'Download: ' + url
}); });
browser.menus.update(mnGrabberId, { browser.menus.update(mnGrabberId, {
title: 'Linkgrabber: ' + link title: 'Linkgrabber: ' + url
}); });
browser.menus.refresh(); browser.menus.refresh();
} }
@ -97,28 +118,15 @@ function allMenusVisible(visible){
} }
browser.menus.onShown.addListener(info => { browser.menus.onShown.addListener(info => {
// console.log('jd2 link: ' + info.linkUrl); var url = infoToLink(info);
// console.log('jd2 selection: ' + info.selectionText);
// linkUrl over selectionText
if (typeof info.linkUrl !== 'undefined'){
allMenusVisible(true);
updateMenuItem(info.linkUrl);
return
} else {
if (typeof info.selectionText !== 'undefined'){
var url = linkify(info.selectionText);
// console.log('jd2: url: ' + url);
if (url !== ''){ if (url !== ''){
allMenusVisible(true) allMenusVisible(true);
updateMenuItem(url); updateMenuItem(url);
return return;
} else { } else {
allMenusVisible(false) allMenusVisible(false);
browser.menus.refresh(); browser.menus.refresh();
} }
}
}
}); });
// Handle message from 'popup' // Handle message from 'popup'

View File

@ -1,8 +1,8 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "UrlToJD2", "name": "UrlToJD2",
"version": "2.0", "version": "2.1",
"description": "Push the current url navigator to JDownloader 2 GrabberLink or Download", "description": "Push an url to JDownloader 2 GrabberLink or Download",
"developer": { "developer": {
"name": "GTeam", "name": "GTeam",

View File

@ -1,5 +1,8 @@
# Versions # Versions
## 2.1 (2021-12-30)
- fix the (undefined) url send to JD2 when text selection
## 2.0 (2021-12-20) ## 2.0 (2021-12-20)
- Large Refactoring - Large Refactoring
- context menu and pageAction can send to Linkgrabber or Download JD2 list. - context menu and pageAction can send to Linkgrabber or Download JD2 list.