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 an url from a text, good enought :-)
function linkify(text) {
let urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
let url = text.match(urlRegex);
@ -65,24 +66,44 @@ browser.menus.create({
}
}, onCreated);
browser.menus.onClicked.addListener((info, tab) => {
switch (info.menuItemId){
case mnGrabberId:
url_for_JD2 = urlConstruct(info.linkUrl, 0);
break;
case mnDlId:
url_for_JD2 = urlConstruct(info.linkUrl, 1);
break;
// 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) => {
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, {
title: 'Download: ' + link
title: 'Download: ' + url
});
browser.menus.update(mnGrabberId, {
title: 'Linkgrabber: ' + link
title: 'Linkgrabber: ' + url
});
browser.menus.refresh();
}
@ -97,27 +118,14 @@ function allMenusVisible(visible){
}
browser.menus.onShown.addListener(info => {
// console.log('jd2 link: ' + info.linkUrl);
// console.log('jd2 selection: ' + info.selectionText);
// linkUrl over selectionText
if (typeof info.linkUrl !== 'undefined'){
var url = infoToLink(info);
if (url !== ''){
allMenusVisible(true);
updateMenuItem(info.linkUrl);
return
updateMenuItem(url);
return;
} else {
if (typeof info.selectionText !== 'undefined'){
var url = linkify(info.selectionText);
// console.log('jd2: url: ' + url);
if (url !== ''){
allMenusVisible(true)
updateMenuItem(url);
return
} else {
allMenusVisible(false)
browser.menus.refresh();
}
}
allMenusVisible(false);
browser.menus.refresh();
}
});

View File

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

View File

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