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);
browser.menus.onClicked.addListener((info, tab) => { // Choose from info (object menus.OnClickData)
switch (info.menuItemId){ // linkUrl over selectionText
case mnGrabberId: // return link or ''
url_for_JD2 = urlConstruct(info.linkUrl, 0); function infoToUrl(info){
break; var url = '';
case mnDlId: if (typeof info.linkUrl !== 'undefined'){
url_for_JD2 = urlConstruct(info.linkUrl, 1); url = info.linkUrl;
break; } else {
if (typeof info.selectionText !== 'undefined'){
url = linkify(info.selectionText);
}
}
return url;
}
browser.menus.onClicked.addListener((info, tab) => {
var url = infoToLink(info);
if (url !== ''){
switch (info.menuItemId){
case mnGrabberId:
url_for_JD2 = urlConstruct(url, 0);
break;
case mnDlId:
url_for_JD2 = urlConstruct(url, 1);
break;
}
console.log(url);
console.log(url_for_JD2);
// makeRequest(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,27 +118,14 @@ 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); if (url !== ''){
// linkUrl over selectionText
if (typeof info.linkUrl !== 'undefined'){
allMenusVisible(true); allMenusVisible(true);
updateMenuItem(info.linkUrl); updateMenuItem(url);
return return;
} else { } else {
if (typeof info.selectionText !== 'undefined'){ allMenusVisible(false);
var url = linkify(info.selectionText); browser.menus.refresh();
// console.log('jd2: url: ' + url);
if (url !== ''){
allMenusVisible(true)
updateMenuItem(url);
return
} else {
allMenusVisible(false)
browser.menus.refresh();
}
}
} }
}); });

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.