Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
Fixed Flenix bug of downloading. CHanged button style too.
  • Loading branch information
Ephellon authored May 3, 2018
1 parent 682b479 commit f3564c8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function addRadarr(request, sendResponse) {
} else if (res && res.path) {
sendResponse({ success: 'Added to ' + res.path });
} else {
sendResponse({ err: 'unknown error' });
sendResponse({ err: 'Unknown error' });
}
})
.catch(err => {
Expand Down Expand Up @@ -134,7 +134,7 @@ function addSonarr(request, sendResponse) {
} else if (res && res.path) {
sendResponse({ success: 'Added to ' + res.path });
} else {
sendResponse({ err: 'unknown error' });
sendResponse({ err: 'Unknown error' });
}
})
.catch(err => {
Expand Down
1 change: 0 additions & 1 deletion src/flenix.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
padding: 5px 10px;
border-radius: 1000px;
text-decoration: none!important;
text-transform: uppercase;
}

.web-to-plex-button--downloader {
Expand Down
4 changes: 2 additions & 2 deletions src/flenix.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function isMoviePage() {
}

function isMoviePageReady() {
return !!document.querySelector('.share-box');
return !!document.querySelector('iframe[title="Disqus"]');
}

function init() {
Expand Down Expand Up @@ -55,7 +55,7 @@ function initPlexThingy() {
const year = parseInt($date.innerText);
const imdbId = getImdbId(title, year);

findPlexMedia({ title, year, button: $button, imdbId });
findPlexMedia({ title, year, button: $button, imdbId, remote: '/engine/ajax/get.php', locale: 'flenix' });
}

function renderPlexButton() {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Web to Plex+",
"description": "Adds a button on various movie & TV show sites to open it in Plex.",
"manifest_version": 2,
"version": "0.1",
"version": "0.2",
"icons": {
"16": "img/16.png",
"48": "img/48.png",
Expand Down
2 changes: 1 addition & 1 deletion src/manifest_firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Web to Plex+",
"description": "Adds a button on various movie & TV show sites to open it in Plex.",
"manifest_version": 2,
"version": "0.1",
"version": "0.2",
"icons": {
"16": "img/16.png",
"48": "img/48.png",
Expand Down
34 changes: 30 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function _addToRadarrRequest(options) {
},
res => {
if (res && res.err) {
showNotification('warning', 'Could not add to Radarr' + res.err);
showNotification('warning', 'Could not add to Radarr\n' + res.err);
console.error('Error adding to Radarr:', res.err);
return;
} else if (res && res.success) {
Expand Down Expand Up @@ -267,7 +267,7 @@ function _addToSonarrRequest(options) {
},
res => {
if (res && res.err) {
showNotification('warning', 'Could not add to Sonarr' + res.err);
showNotification('warning', 'Could not add to Sonarr\n' + res.err);
console.error('Error adding to Sonarr:', res.err);
return;
} else if (res && res.success) {
Expand All @@ -291,13 +291,39 @@ function modifyPlexButton(el, action, title, options) {
el.textContent = action === 'notfound' ? 'Not on Plex' : 'Plex error';
el.classList.remove('web-to-plex-button--found');
}
if (action === 'downloader') {
if(options.locale === 'flenix' && options.remote) {
el.href = '#';
el.textContent = 'Download (file)';
el.classList.add('web-to-plex-button--downloader');

const $data = document.querySelector('#videoplayer ~ script').innerText;

let data = $data
.replace(/[^]*\{(hash.+?)\}[^]+/, '$1')
.replace(/\s+/g, '')
.replace(/(?:^|,)(\w+)\:/g, '&$1=')
.replace(/^&|["']/g, '');

let xhr = new XMLHttpRequest();
xhr.open('POST', options.remote);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if(xhr.status !== 200) {
return modifyPlexButton(el, action, title, {...options, locale: null, remote: null})
}

el.download = `${options.title} (${options.year})`;
el.href = xhr.responseText.split(',http').slice(0, 1);
}

xhr.send(data);
} else if (action === 'downloader') {
el.href = '#';
el.textContent = 'Download';
el.classList.add('web-to-plex-button--downloader');
el.addEventListener('click', e => {
e.preventDefault();
if (config.radarrUrl) {
if (config.radarrUrl) {
_addToRadarrRequest(options);
} else if (config.sonarrUrl) {
_addToSonarrRequest(options);
Expand Down

0 comments on commit f3564c8

Please sign in to comment.