version 2.0
This commit is contained in:
parent
8b7742cb7b
commit
6b17d80cde
147
background.js
147
background.js
@ -1,29 +1,31 @@
|
|||||||
var JD2_API_URL = 'http://localhost:9666/flashgot?';
|
const JD2_API_URL = 'http://localhost:9666/flashgot?';
|
||||||
var JD2_REFERER = 'localhost';
|
const JD2_REFERER = 'localhost';
|
||||||
var JD2_MATCH_URL = "*://*/flashgot?*";
|
const JD2_MATCH_URL = "*://*/flashgot?*";
|
||||||
|
|
||||||
|
// menu
|
||||||
|
const mnDlId = "JD2Dl";
|
||||||
|
const mnGrabberId = "JD2Grabber"
|
||||||
|
|
||||||
|
|
||||||
function onError(error) {
|
function onError(error) {
|
||||||
console.log('UrlToJD2_error: ' + error);
|
console.log('UrlToJD2 background error: ' + error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// On startup, check autostart option stored setting or default value
|
function onCreated() {
|
||||||
const gettingStoredSettings = browser.storage.local.get();
|
if (browser.runtime.lastError) {
|
||||||
gettingStoredSettings.then((item) => {
|
onError(browser.runtime.lastError);
|
||||||
if (!item.autostart) {
|
|
||||||
browser.storage.local.set({ autostart: true })
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
onError);
|
|
||||||
|
|
||||||
|
|
||||||
function makeRequest(url) {
|
function makeRequest(url) {
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.open('GET', url, true);
|
req.open('GET', url, true);
|
||||||
req.send(null);
|
req.send(null);
|
||||||
|
req.onerror = function () {
|
||||||
|
onError('Is JD2 on and ready ?');
|
||||||
|
}
|
||||||
req.onload = function () {
|
req.onload = function () {
|
||||||
// console.log(req.status);
|
if (req.readyState === XMLHttpRequest.DONE && req.status === 200) {
|
||||||
if (req.readyState === 4 && req.status === 200) {
|
|
||||||
// console.log(req.responseText);
|
// console.log(req.responseText);
|
||||||
// notify...
|
// notify...
|
||||||
} else {
|
} else {
|
||||||
@ -36,70 +38,97 @@ function urlConstruct(url, autostart) {
|
|||||||
return JD2_API_URL + "autostart=" + autostart + "&urls=" + encodeURIComponent(url);
|
return JD2_API_URL + "autostart=" + autostart + "&urls=" + encodeURIComponent(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function linkify(text) {
|
||||||
function bool_to_int(bool) {
|
let urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||||
return (bool == true) ? 1 : 0;
|
let url = text.match(urlRegex);
|
||||||
}
|
return (url === null) ? '' : url[0];
|
||||||
|
|
||||||
// main
|
|
||||||
function loadTabUrlToJD2Crawl(storedSettings) {
|
|
||||||
var gettingActiveTab = browser.tabs.query({ active: true, currentWindow: true });
|
|
||||||
gettingActiveTab.then((tabs) => {
|
|
||||||
if (tabs[0]) {
|
|
||||||
currentTabUrl = tabs[0].url;
|
|
||||||
url_for_JD2 = urlConstruct(currentTabUrl, bool_to_int(storedSettings.autostart));
|
|
||||||
// console.log(url_for_JD2);
|
|
||||||
makeRequest(url_for_JD2);
|
|
||||||
}
|
|
||||||
}, onError);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
browser.pageAction.onClicked.addListener(() => {
|
|
||||||
const gettingStoredSettings = browser.storage.local.get();
|
|
||||||
gettingStoredSettings.then(loadTabUrlToJD2Crawl, onError);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// menu
|
|
||||||
const sendToJD2Id = "send-to-JD2";
|
|
||||||
function onCreated() {
|
|
||||||
if (browser.runtime.lastError) {
|
|
||||||
onError(browser.runtime.lastError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MENU
|
||||||
browser.menus.create({
|
browser.menus.create({
|
||||||
id: sendToJD2Id,
|
id: mnGrabberId,
|
||||||
title: "send to JD2",
|
title: "Linkgrabbler",
|
||||||
contexts: ["link"]
|
contexts: ["link", "selection"],
|
||||||
|
icons: {
|
||||||
|
"16": "icons/jd2linkgrabber-16.png",
|
||||||
|
"32": "icons/jd2linkgrabber-32.png"
|
||||||
|
}
|
||||||
}, onCreated);
|
}, onCreated);
|
||||||
|
|
||||||
|
browser.menus.create({
|
||||||
|
id: mnDlId,
|
||||||
|
title: "send to Download",
|
||||||
|
contexts: ["link", "selection"],
|
||||||
|
icons: {
|
||||||
|
"16": "icons/jd2download-16.png",
|
||||||
|
"32": "icons/jd2download-32.png"
|
||||||
|
}
|
||||||
|
}, onCreated);
|
||||||
|
|
||||||
browser.menus.onClicked.addListener((info, tab) => {
|
browser.menus.onClicked.addListener((info, tab) => {
|
||||||
if (info.menuItemId === sendToJD2Id) {
|
switch (info.menuItemId){
|
||||||
const gettingStoredSettings = browser.storage.local.get();
|
case mnGrabberId:
|
||||||
gettingStoredSettings.then((storedSettings) => {
|
url_for_JD2 = urlConstruct(info.linkUrl, 0);
|
||||||
url_for_JD2 = urlConstruct(info.linkUrl, bool_to_int(storedSettings.autostart));
|
break;
|
||||||
makeRequest(url_for_JD2);
|
case mnDlId:
|
||||||
}, onError);
|
url_for_JD2 = urlConstruct(info.linkUrl, 1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
makeRequest(url_for_JD2);
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateMenuItem(link) {
|
function updateMenuItem(link) {
|
||||||
browser.menus.update(sendToJD2Id, {
|
browser.menus.update(mnDlId, {
|
||||||
title: `Send to JD2: "${link}"`
|
title: 'Download: ' + link
|
||||||
|
});
|
||||||
|
browser.menus.update(mnGrabberId, {
|
||||||
|
title: 'Linkgrabber: ' + link
|
||||||
});
|
});
|
||||||
browser.menus.refresh();
|
browser.menus.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function allMenusVisible(visible){
|
||||||
|
browser.menus.update(mnGrabberId, {
|
||||||
|
visible: visible
|
||||||
|
});
|
||||||
|
browser.menus.update(mnDlId, {
|
||||||
|
visible: visible
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
browser.menus.onShown.addListener(info => {
|
browser.menus.onShown.addListener(info => {
|
||||||
if (!info.linkUrl) {
|
// console.log('jd2 link: ' + info.linkUrl);
|
||||||
return;
|
// console.log('jd2 selection: ' + info.selectionText);
|
||||||
}
|
|
||||||
|
// linkUrl over selectionText
|
||||||
|
if (typeof info.linkUrl !== 'undefined'){
|
||||||
|
allMenusVisible(true);
|
||||||
updateMenuItem(info.linkUrl);
|
updateMenuItem(info.linkUrl);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle message from 'popup'
|
||||||
|
function handleMessageFromPopup(request, sender, sendResponse) {
|
||||||
|
let forJD2link = urlConstruct(request.jd2url, request.jd2action);
|
||||||
|
makeRequest(forJD2link);
|
||||||
|
return Promise.resolve({response: "done"});
|
||||||
|
}
|
||||||
|
browser.runtime.onMessage.addListener(handleMessageFromPopup);
|
||||||
|
|
||||||
|
|
||||||
// Some functions for a good referer !
|
// Some functions for a good referer !
|
||||||
|
|
||||||
|
BIN
icons/jd2download-16.png
Normal file
BIN
icons/jd2download-16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 573 B |
BIN
icons/jd2download-32.png
Normal file
BIN
icons/jd2download-32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
icons/jd2linkgrabber-16.png
Normal file
BIN
icons/jd2linkgrabber-16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 790 B |
BIN
icons/jd2linkgrabber-32.png
Normal file
BIN
icons/jd2linkgrabber-32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
BIN
icons/urltojd2-16.png
Normal file
BIN
icons/urltojd2-16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 483 B |
BIN
icons/urltojd2-32.png
Normal file
BIN
icons/urltojd2-32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 898 B |
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "UrlToJD2",
|
"name": "UrlToJD2",
|
||||||
"version": "1.1",
|
"version": "2.0",
|
||||||
"description": "Push the current url navigator to JDownloader 2",
|
"description": "Push the current url navigator to JDownloader 2 GrabberLink or Download",
|
||||||
|
|
||||||
"developer": {
|
"developer": {
|
||||||
"name": "GTeam",
|
"name": "GTeam",
|
||||||
@ -17,6 +17,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"icons": {
|
"icons": {
|
||||||
|
"16": "icons/urltojd2-16.png",
|
||||||
|
"32": "icons/urltojd2-32.png",
|
||||||
"48": "icons/urltojd2-48.png",
|
"48": "icons/urltojd2-48.png",
|
||||||
"96": "icons/urltojd2-96.png"
|
"96": "icons/urltojd2-96.png"
|
||||||
},
|
},
|
||||||
@ -31,7 +33,10 @@
|
|||||||
"38": "icons/urltojd2-38.png"
|
"38": "icons/urltojd2-38.png"
|
||||||
},
|
},
|
||||||
"show_matches": ["<all_urls>"],
|
"show_matches": ["<all_urls>"],
|
||||||
"default_title": "Send current url to JD2"
|
"default_title": "Send current url to JD2",
|
||||||
|
"browser_style": true,
|
||||||
|
"default_popup": "popup/popup.html"
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"permissions": [
|
"permissions": [
|
||||||
@ -39,13 +44,7 @@
|
|||||||
"*://*/flashgot?*",
|
"*://*/flashgot?*",
|
||||||
"webRequest",
|
"webRequest",
|
||||||
"webRequestBlocking",
|
"webRequestBlocking",
|
||||||
"storage",
|
|
||||||
"menus"
|
"menus"
|
||||||
],
|
]
|
||||||
|
|
||||||
"options_ui": {
|
|
||||||
"page": "options/options.html",
|
|
||||||
"browser_style": true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,19 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="browser-style">
|
|
||||||
<h2>Autostart</h2>
|
|
||||||
<input type="checkbox" id="autostart" checked name="autostart">
|
|
||||||
<label for="autostart">pass directly from JD2 Linkgrabbler to download list</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="options.js"></script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
@ -1,29 +0,0 @@
|
|||||||
function onError(error) {
|
|
||||||
console.log('UrlToJD2_options_error: ' + error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// autostart
|
|
||||||
var chck_autostart = document.getElementById("autostart");
|
|
||||||
|
|
||||||
|
|
||||||
chck_autostart.onchange = function () {
|
|
||||||
if (chck_autostart.checked) {
|
|
||||||
browser.storage.local.set({ autostart: true });
|
|
||||||
} else {
|
|
||||||
browser.storage.local.set({ autostart: false });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Update the options UI or default setting
|
|
||||||
function updateUI(restoredSettings) {
|
|
||||||
if (restoredSettings.autostart == undefined) {
|
|
||||||
chck_autostart.checked = true; //default
|
|
||||||
} else {
|
|
||||||
chck_autostart.checked = restoredSettings.autostart;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// On opening the options page
|
|
||||||
const gettingStoredSettings = browser.storage.local.get();
|
|
||||||
gettingStoredSettings.then(updateUI, onError);
|
|
21
popup/popup.html
Normal file
21
popup/popup.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<style>
|
||||||
|
img {
|
||||||
|
margin: 0px 4px 0px 0px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-section panel-section-list" id="jd2urlList">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="popup.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
61
popup/popup.js
Normal file
61
popup/popup.js
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
document.addEventListener("DOMContentLoaded", function(event) {
|
||||||
|
|
||||||
|
function onError(error) {
|
||||||
|
console.log(`jd2 popup error: ${error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const jd2UrlList = document.getElementById('jd2urlList');
|
||||||
|
|
||||||
|
var gettingActiveTab = browser.tabs.query({ active: true, currentWindow: true });
|
||||||
|
gettingActiveTab.then((tabs) => {
|
||||||
|
if (tabs[0]) {
|
||||||
|
var currentTabUrl = tabs[0].url;
|
||||||
|
|
||||||
|
let li = document.createElement("div");
|
||||||
|
li.classList.add("panel-list-item");
|
||||||
|
li.setAttribute("data-href", currentTabUrl);
|
||||||
|
li.setAttribute("jd2", "0");
|
||||||
|
let img = document.createElement("img");
|
||||||
|
img.src = "../icons/jd2linkgrabber-16.png";
|
||||||
|
li.appendChild(img);
|
||||||
|
let txt = document.createElement("div");
|
||||||
|
txt.innerText = 'GrabberLink';
|
||||||
|
li.appendChild(txt);
|
||||||
|
jd2UrlList.appendChild(li);
|
||||||
|
|
||||||
|
let li2 = document.createElement("div");
|
||||||
|
li2.classList.add("panel-list-item");
|
||||||
|
li2.setAttribute("data-href", currentTabUrl);
|
||||||
|
li2.setAttribute("jd2", "1");
|
||||||
|
let img2 = document.createElement("img");
|
||||||
|
img2.src = "../icons/jd2download-16.png";
|
||||||
|
li2.appendChild(img2);
|
||||||
|
let txt2 = document.createElement("div");
|
||||||
|
txt2.innerText = 'Download';
|
||||||
|
li2.appendChild(txt2);
|
||||||
|
jd2UrlList.appendChild(li2);
|
||||||
|
}
|
||||||
|
|
||||||
|
var jd2SelectedAction;
|
||||||
|
document.querySelectorAll(".panel-list-item").forEach( (elem) => {
|
||||||
|
elem.addEventListener('click', (event) => {
|
||||||
|
jd2SelectedAction = elem.getAttribute("jd2");
|
||||||
|
notifyBackgroundPage(event);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleResponse(message) {
|
||||||
|
// console.log(`Message from the background script: ${message.response}`);
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function notifyBackgroundPage(e) {
|
||||||
|
var sending = browser.runtime.sendMessage({
|
||||||
|
jd2url: currentTabUrl,
|
||||||
|
jd2action : jd2SelectedAction
|
||||||
|
});
|
||||||
|
sending.then(handleResponse, onError);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, onError);
|
||||||
|
});
|
23
readme.md
23
readme.md
@ -1,8 +1,7 @@
|
|||||||
# UrlToJD2
|
# UrlToJD2 - A Firefox extension
|
||||||
Push the current url navigator or an url in a link (right-click) to the download manager JDownloader 2.
|
Push an url from the browser or in a link (right-click) to the download manager JDownloader 2.
|
||||||
|
|
||||||
# Getting Started
|
This addons use the remote control API (externInterface: Flashgot) from JDownloader2.
|
||||||
This addons use the remote control API (externInterface: Flashgot) to send the url to JDownloader2.
|
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
Install [JDownloader2](http://beta.jdownloader.org/).
|
Install [JDownloader2](http://beta.jdownloader.org/).
|
||||||
@ -10,8 +9,12 @@ In "advanced parameters" search "RemoteAPI".
|
|||||||
The value of "Authorized Website" must look like: ["127.0.0.1", "localhost"]
|
The value of "Authorized Website" must look like: ["127.0.0.1", "localhost"]
|
||||||
JD2 is now ready to listen !
|
JD2 is now ready to listen !
|
||||||
|
|
||||||
## Option
|
## Usage
|
||||||
"autostart" checked by default: pass directly from JD2 Linkgrabbler to download list.
|
This extension add two things:
|
||||||
|
- A "pageAction" (a clickable icon inside the browser's address bar).
|
||||||
|
- An item in the context menu
|
||||||
|
|
||||||
|
With url or link (or link in selection), choose to send to the Linkgrabber ou to the Download list.
|
||||||
|
|
||||||
## Note
|
## Note
|
||||||
If you want a more complete addons with JD2, try [the official one:](https://my.jdownloader.org/apps/)
|
If you want a more complete addons with JD2, try [the official one:](https://my.jdownloader.org/apps/)
|
||||||
@ -19,8 +22,10 @@ If you want a more complete addons with JD2, try [the official one:](https://my.
|
|||||||
## Code Source
|
## Code Source
|
||||||
[UrlToJD2](https://framagit.org/GTeam/urltojd2)
|
[UrlToJD2](https://framagit.org/GTeam/urltojd2)
|
||||||
|
|
||||||
# License
|
## Acknowledgments
|
||||||
|
- Extension icon: [primofenax](https://www.deviantart.com/primofenax/art/icon-Minimal-JDownloader-Icon-313625363)
|
||||||
|
- Context icons from JDownloader2
|
||||||
|
|
||||||
|
## Licence
|
||||||
This project is licensed under the Mozilla Public License, version 2.0
|
This project is licensed under the Mozilla Public License, version 2.0
|
||||||
|
|
||||||
## Acknowledgments
|
|
||||||
icon: [primofenax](https://www.deviantart.com/primofenax/art/icon-Minimal-JDownloader-Icon-313625363)
|
|
||||||
|
12
versions.md
Normal file
12
versions.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Versions
|
||||||
|
|
||||||
|
## 2.0 2021-12-20
|
||||||
|
- Large Refactoring
|
||||||
|
- menu and pageAction can send to Linkgrabber or Download JD2 list.
|
||||||
|
- remove "options" page
|
||||||
|
|
||||||
|
## 1.1 2019-08-26
|
||||||
|
- change (be better) the urlConstruct function for URL encode.
|
||||||
|
|
||||||
|
## 1.0 2019-08-16
|
||||||
|
- first release
|
Loading…
x
Reference in New Issue
Block a user