Compare commits

...

10 Commits

Author SHA1 Message Date
a8fcb3ad6d Added options menu to extension page 2023-05-18 01:40:36 +01:00
GTeam
dffc4b3c9b 2.1 fix send url in selection 2021-12-30 18:15:16 +01:00
GTeam
f25d95320f 2.1 fix send url in selection 2021-12-30 18:07:45 +01:00
GTeam
f8841172d3 readme 2021-12-22 10:59:26 +01:00
GTeam
0fb877e929 add screenshots 2021-12-22 10:56:30 +01:00
GTeam
591b3b7182 add screenshots 2021-12-22 10:55:30 +01:00
GTeam
997b090a06 version 2.0 2021-12-20 17:51:08 +01:00
GTeam
6b17d80cde version 2.0 2021-12-20 17:36:51 +01:00
flatgreen
8b7742cb7b add encodeURIComponent in urlConstruct 2019-08-26 14:02:46 +02:00
flatgreen
e32fee050a change manifest, add readme.md 2019-08-16 13:56:41 +02:00
20 changed files with 405 additions and 259 deletions

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
root = true
[*]
indent_style = space
indent_size = 2
[*.json]
indent_style = space
indent_size = 4

4
.gitignore vendored
View File

@ -1,3 +1,3 @@
doc/ doc/
UrlToJD2.zip UrlToJD2.zip
git.sh git.sh

View File

@ -1,133 +1,177 @@
var JD2_API_URL = 'http://localhost:9666/flashgot?'; let JD2_API_URL = window.localStorage.getItem("jd2_api_url") ?? 'http://localhost:9666/flashgot?';
var JD2_REFERER = 'localhost'; let JD2_REFERER = window.localStorage.getItem("jd2_referer") ?? 'localhost';
var JD2_MATCH_URL = "*://*/flashgot?*"; let JD2_MATCH_URL = window.localStorage.getItem("jd2_match_url") ?? "*://*/flashgot?*";
// menu
function onError(error) { const mnDlId = "JD2Dl";
console.log('UrlToJD2_error: ' + error); const mnGrabberId = "JD2Grabber"
}
// On startup, check autostart option stored setting or default value function onError(error) {
const gettingStoredSettings = browser.storage.local.get(); console.log('UrlToJD2 background error: ' + error);
gettingStoredSettings.then((item) => { }
if (!item.autostart) {
browser.storage.local.set({ autostart: true }) function onCreated() {
} if (browser.runtime.lastError) {
}, onError(browser.runtime.lastError);
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.onload = function () { req.onerror = function () {
// console.log(req.status); onError('Is JD2 on and ready ?');
if (req.readyState === 4 && req.status === 200) { }
// console.log(req.responseText); req.onload = function () {
// notify... if (req.readyState === XMLHttpRequest.DONE && req.status === 200) {
} else { // console.log(req.responseText);
onError(req.statusText); // notify...
} } else {
} onError(req.statusText);
} }
}
function urlConstruct(url, autostart) { }
return JD2_API_URL + "autostart=" + autostart + "&urls=" + url;
} function urlConstruct(url, autostart) {
return JD2_API_URL + "autostart=" + autostart + "&urls=" + encodeURIComponent(url);
}
function bool_to_int(bool) {
return (bool == true) ? 1 : 0; // Return an url from a text, good enought :-)
} function linkify(text) {
let urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
// main let url = text.match(urlRegex);
function loadTabUrlToJD2Crawl(storedSettings) { return (url === null) ? '' : url[0];
var gettingActiveTab = browser.tabs.query({ active: true, currentWindow: true }); }
gettingActiveTab.then((tabs) => {
if (tabs[0]) { // MENU
currentTabUrl = tabs[0].url; browser.menus.create({
url_for_JD2 = urlConstruct(currentTabUrl, bool_to_int(storedSettings.autostart)); id: mnGrabberId,
// console.log(url_for_JD2); title: "Linkgrabbler",
makeRequest(url_for_JD2); contexts: ["link", "selection"],
} icons: {
}, onError); "16": "icons/jd2linkgrabber-16.png",
} "32": "icons/jd2linkgrabber-32.png"
}
}, onCreated);
browser.pageAction.onClicked.addListener(() => {
const gettingStoredSettings = browser.storage.local.get(); browser.menus.create({
gettingStoredSettings.then(loadTabUrlToJD2Crawl, onError); id: mnDlId,
}); title: "send to Download",
contexts: ["link", "selection"],
icons: {
// menu "16": "icons/jd2download-16.png",
const sendToJD2Id = "send-to-JD2"; "32": "icons/jd2download-32.png"
function onCreated() { }
if (browser.runtime.lastError) { }, onCreated);
onError(browser.runtime.lastError);
} // Choose from info (object menus.OnClickData)
} // linkUrl over selectionText
// return link or ''
browser.menus.create({ function infoToUrl(info){
id: sendToJD2Id, var url = '';
title: "send to JD2", if (typeof info.linkUrl !== 'undefined'){
contexts: ["link"] url = info.linkUrl;
}, onCreated); } else {
if (typeof info.selectionText !== 'undefined'){
url = linkify(info.selectionText);
browser.menus.onClicked.addListener((info, tab) => { }
if (info.menuItemId === sendToJD2Id) { }
const gettingStoredSettings = browser.storage.local.get(); return url;
gettingStoredSettings.then((storedSettings) => { }
url_for_JD2 = urlConstruct(info.linkUrl, bool_to_int(storedSettings.autostart));
makeRequest(url_for_JD2); browser.menus.onClicked.addListener((info, tab) => {
}, onError); var url = infoToUrl(info);
} if (url !== ''){
}); switch (info.menuItemId){
case mnGrabberId:
function updateMenuItem(link) { url_for_JD2 = urlConstruct(url, 0);
browser.menus.update(sendToJD2Id, { break;
title: `Send to JD2: "${link}"` case mnDlId:
}); url_for_JD2 = urlConstruct(url, 1);
browser.menus.refresh(); break;
} }
// console.log(url);
browser.menus.onShown.addListener(info => { // console.log(url_for_JD2);
if (!info.linkUrl) { makeRequest(url_for_JD2);
return; }
} });
updateMenuItem(info.linkUrl);
}); function updateMenuItem(url) {
browser.menus.update(mnDlId, {
title: 'Download: ' + url
// Some functions for a good referer ! });
browser.menus.update(mnGrabberId, {
// https://stackoverflow.com/a/11602753 title: 'Linkgrabber: ' + url
function mod_headers(header_array, p_name, p_value) { });
var did_set = false; browser.menus.refresh();
for (var i in header_array) { }
var header = header_array[i];
var name = header.name; function allMenusVisible(visible){
// var value = header.value; browser.menus.update(mnGrabberId, {
// If the header is already present, change it: visible: visible
if (name == p_name) { });
header.value = p_value; browser.menus.update(mnDlId, {
did_set = true; visible: visible
} });
} }
// if it is not, add it:
if (!did_set) { header_array.push({ name: p_name, value: p_value }); } browser.menus.onShown.addListener(info => {
} var url = infoToUrl(info);
// console.log(url);
function rewriteHeader(e) { if (url !== ''){
mod_headers(e.requestHeaders, 'Referer', JD2_REFERER); allMenusVisible(true);
// for (var header of e.requestHeaders) { console.log(header.name + '::' + header.value); } updateMenuItem(url);
return { requestHeaders: e.requestHeaders }; return;
} } else {
allMenusVisible(false);
browser.webRequest.onBeforeSendHeaders.addListener( browser.menus.refresh();
rewriteHeader, }
{ urls: [JD2_MATCH_URL] }, });
["blocking", "requestHeaders"]
); // Handle message from 'popup'
function handleMessageFromPopup(request, sender, sendResponse) {
if (request.message == "refresh") {
JD2_API_URL = window.localStorage.getItem("jd2_api_url");
JD2_REFERER = window.localStorage.getItem("jd2_referer");
JD2_MATCH_URL = window.localStorage.getItem("jd2_match_url");
} else {
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 !
// https://stackoverflow.com/a/11602753
function mod_headers(header_array, p_name, p_value) {
var did_set = false;
for (var i in header_array) {
var header = header_array[i];
var name = header.name;
// var value = header.value;
// If the header is already present, change it:
if (name == p_name) {
header.value = p_value;
did_set = true;
}
}
// if it is not, add it:
if (!did_set) { header_array.push({ name: p_name, value: p_value }); }
}
function rewriteHeader(e) {
mod_headers(e.requestHeaders, 'Referer', JD2_REFERER);
// for (var header of e.requestHeaders) { console.log(header.name + '::' + header.value); }
return { requestHeaders: e.requestHeaders };
}
browser.webRequest.onBeforeSendHeaders.addListener(
rewriteHeader,
{ urls: [JD2_MATCH_URL] },
["blocking", "requestHeaders"]
);

BIN
icons/jd2download-16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

BIN
icons/urltojd2-32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

BIN
img/screen-menu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
img/screen-pageAction.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -1,51 +1,54 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "UrlToJD2", "name": "UrlToJD2",
"version": "1.0", "version": "2.1",
"description": "Push the current url navigator to JDownloader 2", "description": "Push an url to JDownloader 2 GrabberLink or Download",
"developer": { "developer": {
"name": "GTeam", "name": "GTeam",
"url": "https://framagit.org/GTeam/UrlToJD2" "url": "https://framagit.org/GTeam/UrlToJD2"
}, },
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
"id": "urltojd2@gteam.fr", "id": "urltojd2@gteam.fr",
"strict_min_version": "55.0" "strict_min_version": "60.0"
} }
}, },
"icons": { "icons": {
"48": "icons/urltojd2-48.png", "16": "icons/urltojd2-16.png",
"96": "icons/urltojd2-96.png" "32": "icons/urltojd2-32.png",
}, "48": "icons/urltojd2-48.png",
"96": "icons/urltojd2-96.png"
"background": { },
"scripts": ["background.js"]
}, "background": {
"scripts": ["background.js"]
"page_action": { },
"default_icon": {
"19": "icons/urltojd2-19.png", "page_action": {
"38": "icons/urltojd2-38.png" "default_icon": {
}, "19": "icons/urltojd2-19.png",
"show_matches": ["<all_urls>"], "38": "icons/urltojd2-38.png"
"default_title": "Send current url to JD2" },
}, "show_matches": ["<all_urls>"],
"default_title": "Send current url to JD2",
"permissions": [ "browser_style": true,
"activeTab", "default_popup": "popup/popup.html"
"*://*/flashgot?*",
"webRequest", },
"webRequestBlocking",
"storage", "permissions": [
"menus" "activeTab",
], "*://*/flashgot?*",
"webRequest",
"options_ui": { "webRequestBlocking",
"page": "options/options.html", "menus"
"browser_style": true ],
}
"options_ui": {
"page": "options.html",
"browser_style": true
}
} }

21
options.html Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script src="options.js"></script>
</head>
<body>
<label for="jd2_api_url">JD2 API URL: </label>
<input type="text" id="jd2_api_url" name="jd2_api_url" />
<br>
<label for="jd2_referer">JD2 Referer: </label>
<input type="text" id="jd2_referer" name="jd2_referer" />
<br>
<label for="jd2_match_url">JD2 API URL: </label>
<input type="text" id="jd2_match_url" name="jd2_match_url" />
<br>
<button id="save">Save</button>
</body>
</html>

15
options.js Normal file
View File

@ -0,0 +1,15 @@
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("save").onclick = save;
document.getElementById("jd2_api_url").value = window.localStorage.getItem("jd2_api_url") ?? 'http://localhost:9666/flashgot?';
document.getElementById("jd2_referer").value = window.localStorage.getItem("jd2_referer") ?? 'localhost';
document.getElementById("jd2_match_url").value = window.localStorage.getItem("jd2_match_url") ?? "*://*/flashgot?*";
})
function save() {
window.localStorage.setItem("jd2_api_url", document.getElementById("jd2_api_url").value);
window.localStorage.setItem("jd2_referer", document.getElementById("jd2_referer").value);
window.localStorage.setItem("jd2_match_url", document.getElementById("jd2_match_url").value);
browser.runtime.sendMessage({message: "refresh"})
}

View File

@ -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>

View File

@ -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
View 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
View 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);
});

View File

@ -1,26 +1,31 @@
# 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 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/). In "advanced parameters" search "RemoteAPI".
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 !
## Usage
## Option This extension add two things:
"autostart" checked by default: pass directly from JD2 Linkgrabbler to download list. - A "pageAction" (a clickable icon inside the browser's address bar).
- An item in the context menu
## Note
If you want a more complete addons with JD2, try [the official one:](https://my.jdownloader.org/apps/) With url or link (or link/url in selection), choose to send to the Linkgrabber or to the Download list.
## Code Source ## Note
[UrlToJD2](https://framagit.org/GTeam/urltojd2) If you want a more complete addons with JD2, try [the official one:](https://my.jdownloader.org/apps/)
# License ## Code Source
This project is licensed under the Mozilla Public License, version 2.0 [UrlToJD2](https://framagit.org/GTeam/urltojd2)
##Acknowledgments ## Acknowledgments
icon: [primofenax](https://www.deviantart.com/primofenax/art/icon-Minimal-JDownloader-Icon-313625363) - 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

15
versions.md Normal file
View File

@ -0,0 +1,15 @@
# 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.
- remove "options" page
## 1.1 (2019-08-26)
- change (be better) the urlConstruct function for URL encode.
## 1.0 (2019-08-16)
- first release