Crunchyroll-Downloader-v3.0/CRD-addon/popup.js
hama3254 8e907e05d0 Funimation dub setting improvements
Funimation dub setting now overrides existing tags in the url
firefox addon post method changed
2021-01-16 14:08:33 +01:00

322 lines
13 KiB
JavaScript

browser.tabs.query({
currentWindow: true,
active: true
}).then((tabs) => {
let tab = tabs[0]; // Safe to assume there will only be one resultconsole.log(tab.url);
console.log(tab.url);
if (tab.url.includes('crunchyroll.com')) {
var crunchyroll = browser.tabs.executeScript({
code: 'document.getElementsByClassName("episode")[0].href;'
});
crunchyroll.then(onExecuted, onError);
} else if (tab.url.includes('funimation.com')) {
var funimation = browser.tabs.executeScript({
code: 'document.getElementsByClassName("trackVideo")[0].href'
});
funimation.then(FunimationSuccess, FunimationError);
} else if (tab.url.includes('anime-on-demand.de/anime/')) {
document.getElementById("btn_add").hidden = true;
document.getElementById("btn_enable_select").hidden = true;
document.getElementById("btn_add_mass").hidden = true;
document.getElementById("btn_select_all").hidden = true;
document.getElementById("btn_select_none").hidden = true;
document.getElementById("btn_enable_funimation_select").hidden = true;
document.getElementById("btn_add_funimation").hidden = true;
document.getElementById("btn_add_AoD").hidden = true; //false if implemented
} else {
document.getElementById("btn_add").hidden = true;
document.getElementById("btn_enable_select").hidden = true;
document.getElementById("btn_add_mass").hidden = true;
document.getElementById("btn_select_all").hidden = true;
document.getElementById("btn_select_none").hidden = true;
document.getElementById("btn_enable_funimation_select").hidden = true;
document.getElementById("btn_add_funimation").hidden = true;
document.getElementById("btn_add_AoD").hidden = true;
}
}, console.error)
document.getElementById('btn_add_AoD').addEventListener('click', () => {
//browser.cookies.getAllCookieStores().then((cookie) => {
// browser.cookies.getAll({
// name: "_aod_session"
// }).then((cookie) => {
//console.log(cookie)
//}, console.error)
var cookies = {};
cookies.all = url => new Promise(resolve => chrome.cookies.getAll({
url
}, resolve));
console.log(cookies)
});
document.getElementById('btn_enable_select').addEventListener('click', () => {
browser.tabs.executeScript({
code: 'var script=document.createElement("script");script.type="text/javascript",script.src="http://127.0.0.1/inject.js",document.head.appendChild(script);'
}); //load script from local CRD Server included in https://github.com/hama3254/Crunchyroll-Downloader-v3.0
document.getElementById("btn_add_mass").hidden = false;
document.getElementById("btn_select_all").hidden = false;
document.getElementById("btn_select_none").hidden = false;
document.getElementById("btn_enable_select").hidden = true;
document.getElementById("btn_add").hidden = true;
document.getElementById("btn_enable_funimation_select").hidden = true;
document.getElementById("btn_add_funimation").hidden = true;
document.getElementById("btn_add_AoD").hidden = true;
});
document.getElementById('btn_select_all').addEventListener('click', () => {
browser.tabs.query({
currentWindow: true,
active: true
}).then((tabs) => {
let tab = tabs[0];
if (tab.url.includes('crunchyroll.com')) {
browser.tabs.executeScript({
code: 'var i,episodeCount=document.getElementsByClassName("episode").length;for(i=0;i<episodeCount;i++)document.getElementsByClassName("episode")[i].style.background="#f78c25",document.getElementsByClassName("episode")[i].classList.add("CRD-Selected");'
});
} else if (tab.url.includes('funimation.com')) {
browser.tabs.executeScript({
code: 'var i,episodeCount=document.getElementsByClassName("fullEpisodeThumbs").length;for(i=0;i<episodeCount;i++)document.getElementsByClassName("fullEpisodeThumbs")[i].style.background="#f78c25",document.getElementsByClassName("fullEpisodeThumbs")[i].classList.add("CRD-Selected");'
});
} else {}
}, console.error)
});
document.getElementById('btn_select_none').addEventListener('click', () => {
browser.tabs.query({
currentWindow: true,
active: true
}).then((tabs) => {
let tab = tabs[0];
if (tab.url.includes('crunchyroll.com')) {
browser.tabs.executeScript({
code: 'var i,episodeCount=document.getElementsByClassName("episode").length;for(i=0;i<episodeCount;i++)document.getElementsByClassName("episode")[i].style.background="#ffffff",document.getElementsByClassName("episode")[i].classList.remove("CRD-Selected");'
});
} else if (tab.url.includes('funimation.com')) {
browser.tabs.executeScript({
code: 'var i,episodeCount=document.getElementsByClassName("fullEpisodeThumbs").length;for(i=0;i<episodeCount;i++)document.getElementsByClassName("fullEpisodeThumbs")[i].style.background="#ffffff",document.getElementsByClassName("fullEpisodeThumbs")[i].classList.remove("CRD-Selected");'
});
} else {}
}, console.error)
});
document.getElementById('btn_add').addEventListener('click', () => {
var add_one = browser.tabs.executeScript({
code: "document.getElementsByClassName('no-js')[0].innerHTML;"
});
add_one.then(add_one_ok, add_one_error);
});
document.getElementById('btn_add_funimation').addEventListener('click', () => {
var add_fun = browser.tabs.executeScript({
code: "javascript:void(0);" //"document.getElementsByClassName('show-details')[0].innerHTML;"
});
add_fun.then(add_fun_ok, add_one_error);
});
document.getElementById('btn_add_mass').addEventListener('click', () => {
var add_mass = browser.tabs.executeScript({
code: 'var i,URLList="";for(i=0;i<document.getElementsByClassName("CRD-Selected").length;i++)URLList+=document.getElementsByClassName("CRD-Selected")[i].getAttribute("href");URLList;'
});
add_mass.then(add_mass_ok, add_mass_error);
});
function onExecuted(result) {
console.log(result[0]);
if (result[0].includes('javascript:')) {
document.getElementById("btn_add").hidden = true;
document.getElementById("btn_add_mass").hidden = false;
document.getElementById("btn_select_all").hidden = false;
document.getElementById("btn_select_none").hidden = false;
document.getElementById("btn_enable_select").hidden = true;
document.getElementById("btn_add_funimation").hidden = true;
document.getElementById("btn_enable_funimation_select").hidden = true;
document.getElementById("btn_add_AoD").hidden = true;
console.log(true);
} else {
document.getElementById("btn_add").hidden = true;
document.getElementById("btn_enable_select").hidden = false;
document.getElementById("btn_add_mass").hidden = true;
document.getElementById("btn_select_all").hidden = true;
document.getElementById("btn_select_none").hidden = true;
document.getElementById("btn_add_funimation").hidden = true;
document.getElementById("btn_enable_funimation_select").hidden = true;
document.getElementById("btn_add_AoD").hidden = true;
console.log(false);
}
}
function onError(error) {
console.log(`Error: ${error}`);
document.getElementById("btn_add").hidden = false;
document.getElementById("btn_add_mass").hidden = true;
document.getElementById("btn_select_all").hidden = true;
document.getElementById("btn_select_none").hidden = true;
document.getElementById("btn_enable_select").hidden = true;
document.getElementById("btn_add_funimation").hidden = true;
document.getElementById("btn_enable_funimation_select").hidden = true;
document.getElementById("btn_add_AoD").hidden = true;
}
function add_fun_ok(result) {
browser.tabs.query({
currentWindow: true,
active: true
}).then((tabs) => {
let tab = tabs[0]; // Safe to assume there will only be one resultconsole.log(tab.url);
console.log(tab.url);
document.getElementById("btn_add_funimation").disabled = true;
document.getElementById("btn_add_funimation").style.background = "#c9c9c9"
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "http://127.0.0.1/post", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("FunimationURL=" + tab.url);
setTimeout(function () {
document.getElementById("btn_add_funimation").style.background = "#ff8000"
}, 10000);
setTimeout(function () {
document.getElementById("btn_add_funimation").disabled = false;
}, 10000);
}, console.error)
}
function add_one_ok(result) {
document.getElementById("btn_add").disabled = true;
document.getElementById("btn_add").style.background = "#c9c9c9"
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "http://127.0.0.1/post", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("HTMLSingle=" + result);
setTimeout(function () {
document.getElementById("btn_add").style.background = "#ff8000"
}, 10000);
setTimeout(function () {
document.getElementById("btn_add").disabled = false;
}, 10000);
}
function add_one_error(error) {
console.log(`Error: ${error}`);
}
function add_mass_ok(result) {
document.getElementById("btn_add_mass").disabled = true;
document.getElementById("btn_add_mass").style.background = "#c9c9c9"
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "http://127.0.0.1/post", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("HTMLMass=" + result);
setTimeout(function () {
document.getElementById("btn_add_mass").style.background = "#ff8000"
}, 10000);
setTimeout(function () {
document.getElementById("btn_add_mass").disabled = false;
}, 10000);
}
function add_mass_error(error) {
console.log(`Error: ${error}`);
}
//funimation
document.getElementById('btn_enable_funimation_select').addEventListener('click', () => {
browser.tabs.executeScript({
code: 'var script=document.createElement("script");script.type="text/javascript",script.src="http://127.0.0.1/inject_funimation.js",document.head.appendChild(script);'
}); //load script from local CRD Server included in https://github.com/hama3254/Crunchyroll-Downloader-v3.0
document.getElementById("btn_add_mass").hidden = false;
document.getElementById("btn_select_all").hidden = false;
document.getElementById("btn_select_none").hidden = false;
document.getElementById("btn_enable_select").hidden = true;
document.getElementById("btn_add").hidden = true;
document.getElementById("btn_add_funimation").hidden = true;
document.getElementById("btn_add_AoD").hidden = true;
});
function FunimationSuccess(result) {
console.log(result[0]);
if (result[0].includes('javascript:')) {
document.getElementById("btn_add").hidden = true;
document.getElementById("btn_add_mass").hidden = false;
document.getElementById("btn_select_all").hidden = false;
document.getElementById("btn_select_none").hidden = false;
document.getElementById("btn_enable_select").hidden = true;
document.getElementById("btn_add_AoD").hidden = true;
document.getElementById("btn_enable_funimation_select").hidden = true;
document.getElementById("btn_add_funimation").hidden = true;
document.getElementById("btn_add_AoD").hidden = true;
console.log(true);
} else {
document.getElementById("btn_add").hidden = true;
document.getElementById("btn_add_funimation").hidden = true;
document.getElementById("btn_enable_select").hidden = true;
document.getElementById("btn_add_mass").hidden = true;
document.getElementById("btn_select_all").hidden = true;
document.getElementById("btn_select_none").hidden = true;
document.getElementById("btn_enable_funimation_select").hidden = false;
document.getElementById("btn_add_AoD").hidden = true;
console.log(false);
}
}
function FunimationError(error) {
console.log(`Error: ${error}`);
document.getElementById("btn_add").hidden = true;
document.getElementById("btn_add_mass").hidden = true;
document.getElementById("btn_select_all").hidden = true;
document.getElementById("btn_select_none").hidden = true;
document.getElementById("btn_enable_select").hidden = true;
document.getElementById("btn_add_funimation").hidden = false;
document.getElementById("btn_enable_funimation_select").hidden = true;
document.getElementById("btn_add_AoD").hidden = true;
}