Initial commit (before Mozilla)
This commit is contained in:
commit
8b5936d465
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
doc/
|
133
background.js
Normal file
133
background.js
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
var JD2_API_URL = 'http://localhost:9666/flashgot?';
|
||||||
|
var JD2_REFERER = 'localhost';
|
||||||
|
var JD2_MATCH_URL = "*://*/flashgot?*";
|
||||||
|
|
||||||
|
|
||||||
|
function onError(error) {
|
||||||
|
console.log('UrlToJD2_error: ' + error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// On startup, check autostart option stored setting or default value
|
||||||
|
const gettingStoredSettings = browser.storage.local.get();
|
||||||
|
gettingStoredSettings.then((item) => {
|
||||||
|
if (!item.autostart) {
|
||||||
|
browser.storage.local.set({ autostart: true })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError);
|
||||||
|
|
||||||
|
|
||||||
|
function makeRequest(url) {
|
||||||
|
var req = new XMLHttpRequest();
|
||||||
|
req.open('GET', url, true);
|
||||||
|
req.send(null);
|
||||||
|
req.onload = function () {
|
||||||
|
// console.log(req.status);
|
||||||
|
if (req.readyState === 4 && req.status === 200) {
|
||||||
|
// console.log(req.responseText);
|
||||||
|
// notify...
|
||||||
|
} else {
|
||||||
|
onError(req.statusText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function urlConstruct(url, autostart) {
|
||||||
|
return JD2_API_URL + "autostart=" + autostart + "&urls=" + url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function bool_to_int(bool) {
|
||||||
|
return (bool == true) ? 1 : 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
browser.menus.create({
|
||||||
|
id: sendToJD2Id,
|
||||||
|
title: "send to JD2",
|
||||||
|
contexts: ["link"]
|
||||||
|
}, onCreated);
|
||||||
|
|
||||||
|
|
||||||
|
browser.menus.onClicked.addListener((info, tab) => {
|
||||||
|
if (info.menuItemId === sendToJD2Id) {
|
||||||
|
const gettingStoredSettings = browser.storage.local.get();
|
||||||
|
gettingStoredSettings.then((storedSettings) => {
|
||||||
|
url_for_JD2 = urlConstruct(info.linkUrl, bool_to_int(storedSettings.autostart));
|
||||||
|
makeRequest(url_for_JD2);
|
||||||
|
}, onError);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateMenuItem(link) {
|
||||||
|
browser.menus.update(sendToJD2Id, {
|
||||||
|
title: `Send to JD2: "${link}"`
|
||||||
|
});
|
||||||
|
browser.menus.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
browser.menus.onShown.addListener(info => {
|
||||||
|
if (!info.linkUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateMenuItem(info.linkUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// 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/urltojd2-19.png
Normal file
BIN
icons/urltojd2-19.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 973 B |
BIN
icons/urltojd2-38.png
Normal file
BIN
icons/urltojd2-38.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
icons/urltojd2-48.png
Normal file
BIN
icons/urltojd2-48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
BIN
icons/urltojd2-96.png
Normal file
BIN
icons/urltojd2-96.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
51
manifest.json
Normal file
51
manifest.json
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"manifest_version": 2,
|
||||||
|
"name": "UrlToJD2",
|
||||||
|
"version": "1.0",
|
||||||
|
"description": "Push the current url navigator to JDownloader 2",
|
||||||
|
|
||||||
|
"developer": {
|
||||||
|
"name": "GTeam",
|
||||||
|
"url": "https://framagit.org/GTeam/UrlToJD2"
|
||||||
|
},
|
||||||
|
|
||||||
|
"browser_specific_settings": {
|
||||||
|
"gecko": {
|
||||||
|
"id": "urltojd2@gteam.fr",
|
||||||
|
"strict_min_version": "55"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"icons": {
|
||||||
|
"48": "icons/urltojd2-48.png",
|
||||||
|
"96": "icons/urltojd2-96.png"
|
||||||
|
},
|
||||||
|
|
||||||
|
"background": {
|
||||||
|
"scripts": ["background.js"]
|
||||||
|
},
|
||||||
|
|
||||||
|
"page_action": {
|
||||||
|
"default_icon": {
|
||||||
|
"19": "icons/urltojd2-19.png",
|
||||||
|
"38": "icons/urltojd2-38.png"
|
||||||
|
},
|
||||||
|
"show_matches": ["<all_urls>"],
|
||||||
|
"default_title": "Send current url to JD2"
|
||||||
|
},
|
||||||
|
|
||||||
|
"permissions": [
|
||||||
|
"activeTab",
|
||||||
|
"*://*/flashgot?*",
|
||||||
|
"webRequest",
|
||||||
|
"webRequestBlocking",
|
||||||
|
"storage",
|
||||||
|
"menus"
|
||||||
|
],
|
||||||
|
|
||||||
|
"options_ui": {
|
||||||
|
"page": "options/options.html",
|
||||||
|
"browser_style": true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
options/options.html
Normal file
19
options/options.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<!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>
|
29
options/options.js
Normal file
29
options/options.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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);
|
Loading…
x
Reference in New Issue
Block a user