-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed (commented out) CouchPotato settings, and added Sonarr settings. Also added Flenix.co as a supported website.
- Loading branch information
Showing
12 changed files
with
547 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.web-to-plex-button { | ||
font-weight: normal; | ||
margin-top: -26px; | ||
margin-left: 10px; | ||
display: inline-block; | ||
background: #727272; | ||
color: #fff!important; | ||
padding: 5px 10px; | ||
border-radius: 1000px; | ||
text-decoration: none!important; | ||
text-transform: uppercase; | ||
} | ||
|
||
.web-to-plex-button--downloader { | ||
color: #acb4bf!important; | ||
} | ||
|
||
.web-to-plex-button--downloader:hover { | ||
background-color: #f67e56!important; | ||
color: #ffffff!important; | ||
} | ||
|
||
.web-to-plex-button--found { | ||
background-color: #ca7c1f!important; | ||
color: #ffffff!important; | ||
} | ||
|
||
.web-to-plex-button--found:hover { | ||
background-color: #f8c022!important; | ||
} | ||
|
||
.web-to-plex-notification { | ||
cursor: pointer; | ||
display: block; | ||
position: fixed; | ||
top: 80px; | ||
left: 50%; | ||
margin-left: -175px; | ||
width: 350px; | ||
background: #21262e; | ||
color: #fff; | ||
font-size: 20px; | ||
padding: 10px; | ||
border-radius: 4px; | ||
z-index: 999000; | ||
} | ||
|
||
.web-to-plex-warning { | ||
background: #fd6a00; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* global parseOptions, modifyPlexButton, findPlexMedia */ | ||
function isMoviePage() { | ||
const path = window.location.pathname; | ||
if (!path.startsWith('/movies/')) { | ||
return false; | ||
} | ||
// An example movie page: /movies/juno-hpsgt (can also have trailing slash!) | ||
// Example non-movie page: /movies/watchlist/gbdx | ||
// So if there is one slash extra (trailing slash not included), it's not a movie page. | ||
const jup = path.replace('/movies/', '').slice(0, -1); | ||
return !jup.includes('/'); | ||
} | ||
|
||
function isMoviePageReady() { | ||
return !!document.querySelector('.share-box'); | ||
} | ||
|
||
function init() { | ||
if (isMoviePage()) { | ||
if (isMoviePageReady()) { | ||
initPlexThingy(); | ||
} else { | ||
// This almost never happens, but sometimes the page is too slow so we need to wait a bit. | ||
// I could reproduce this by clicking on a movie in the movie watchlist, | ||
// going back in history and then going forward in history. | ||
setTimeout(() => { | ||
initPlexThingy(); | ||
}, 1000); | ||
} | ||
} | ||
} | ||
|
||
parseOptions().then(() => { | ||
window.addEventListener('popstate', init); | ||
window.addEventListener('pushstate-changed', init); | ||
init(); | ||
}); | ||
|
||
function initPlexThingy() { | ||
const $button = renderPlexButton(); | ||
if (!$button) { | ||
return; | ||
} | ||
const $title = document.querySelector('#dle-content .about > h1'); | ||
const $date = document.querySelector('.features > .reset:nth-child(2) a'); | ||
if (!$title || !$date) { | ||
modifyPlexButton( | ||
$button, | ||
'error', | ||
'Could not extract title or year from Flenix' | ||
); | ||
return; | ||
} | ||
const title = $title.innerText.trim(); | ||
const year = parseInt($date.innerText); | ||
const imdbId = getImdbId(title, year); | ||
|
||
findPlexMedia({ title, year, button: $button, imdbId }); | ||
} | ||
|
||
function renderPlexButton() { | ||
// The "download" button, which doesn't actually work | ||
const $downloadButton = document.querySelector( | ||
'#dle-content .about > .buttons > a[target="_blank"]' | ||
); | ||
if ($downloadButton) { | ||
$downloadButton.remove(); | ||
} | ||
|
||
const $actions = document.querySelector('.about > .buttons'); | ||
if (!$actions) { | ||
console.log('Could not add Plex button.'); | ||
return null; | ||
} | ||
const $existingEl = document.querySelector('a.web-to-plex-button'); | ||
if ($existingEl) { | ||
$existingEl.remove(); | ||
} | ||
const el = document.createElement('a'); | ||
el.classList.add('roundButton', 'web-to-plex-button'); | ||
$actions.appendChild(el); | ||
return el; | ||
} | ||
|
||
async function getImdbId(_title, _year) { | ||
let title = null, | ||
year = null; | ||
|
||
if(!_title || !_year){ | ||
const $title = document.querySelector('#dle-content .about > h1'); | ||
const $date = document.querySelector('.features > .reset:nth-child(2) a'); | ||
if(!$title || !$date) { | ||
return null; | ||
} | ||
title = $title.innerText.trim(); | ||
year = parseInt($date.innerText); | ||
} else { | ||
title = _title; | ||
year = _year; | ||
} | ||
|
||
let json = {}; | ||
|
||
await fetch(`https://www.theimdbapi.org/api/find/movie?title=${ title }&year=${ year }`) | ||
.then(function(response) { | ||
return response.json(); | ||
}) | ||
.catch(function(error) { | ||
throw error; | ||
}) | ||
.then(function(data) { | ||
return json = data[0]; | ||
}); | ||
|
||
return json.imdb_id || null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.