-
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.
Ref #6
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 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,38 @@ | ||
.web-to-plex-button--couchpotato { | ||
border-color: #f45a26!important; | ||
background: #f45a26!important; | ||
color: #fff!important; | ||
} | ||
|
||
.web-to-plex-button--couchpotato:hover { | ||
background: #f67e56!important; | ||
} | ||
|
||
.web-to-plex-button--found { | ||
background: #e5a00d!important; | ||
border-color: #e5a00d!important; | ||
color: #fff!important; | ||
} | ||
|
||
.web-to-plex-button--found:hover { | ||
background: #f9be03!important; | ||
} | ||
|
||
.web-to-plex-notification { | ||
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,69 @@ | ||
function isMoviePage() { | ||
const path = window.location.pathname; | ||
if (!path.startsWith('/movies/')) { | ||
return false; | ||
} | ||
// TODO: e.g. /movies/trending is not really a movie page... | ||
return true; | ||
} | ||
|
||
function isMoviePageReady() { | ||
return true; | ||
} | ||
|
||
function getImdbId() { | ||
const $link = document.querySelector('ul.external [href^="http://www.imdb.com/title/tt"]'); | ||
if ($link) { | ||
return $link.href.replace('http://www.imdb.com/title/', ''); | ||
} | ||
return null; | ||
} | ||
|
||
function init() { | ||
if(isMoviePage()) { | ||
wait(() => document.querySelector('#info-wrapper ul.external'), () => { | ||
initPlexThingy(); | ||
}); | ||
} | ||
} | ||
|
||
function renderPlexButton() { | ||
const $actions = document.querySelector('ul.external li:first-child'); | ||
if (!$actions) { | ||
console.log('Could not add Plex button.'); | ||
return; | ||
} | ||
const el = document.createElement('a'); | ||
el.classList.add('web-to-plex-button'); | ||
$actions.insertBefore(el, $actions.childNodes[0]); | ||
return el; | ||
} | ||
|
||
function initPlexThingy() { | ||
const $button = renderPlexButton(); | ||
if (!$button) { | ||
return; | ||
} | ||
const $title = document.querySelector('.btn-checkin'); | ||
const $year = document.querySelector('.summary .mobile-title .year'); | ||
if (!$title || !$year) { | ||
modifyPlexButton($button, 'error', 'Could not extract title or year'); | ||
return; | ||
} | ||
const title = $title.dataset.topTitle; | ||
const year = parseInt($year.textContent.trim()); | ||
const imdbId = getImdbId(); | ||
|
||
handlePlex(config, { title, year, button: $button, imdbId }); | ||
} | ||
|
||
let config; | ||
getOptions().then((options) => { | ||
config = options; | ||
window.addEventListener('popstate', init); | ||
window.addEventListener('pushstate-changed', init); | ||
init(); | ||
}, () => { | ||
showNotification('warning', 'Not all options for the Movieo to Plex extension are filled in.'); | ||
}); | ||
|
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