Skip to content

Commit

Permalink
Added tv shows support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Rigal committed Oct 21, 2021
1 parent a4d91d1 commit cd69966
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Features:
- One-click requests directly from TMDB and IMDb websites
- One-click access to available media on Plex
- Monitor requests status
- Support for both movies and TV shows

## Install

Expand Down
10 changes: 5 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
importScripts('js/storage.js');

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.contentScriptQuery === 'queryMovie') {
console.log(`Querying movie ${request.tmdbId}`);
if (request.contentScriptQuery === 'queryMedia') {
console.log(`Querying ${request.mediaType} '${request.tmdbId}'`);
pullStoredData(function() {
fetch(`${origin}/api/v1/movie/${encodeURIComponent(request.tmdbId)}`)
fetch(`${origin}/api/v1/${request.mediaType}/${encodeURIComponent(request.tmdbId)}`)
.then(response => response.json())
.then(json => sendResponse(json))
.catch(error => console.error(error))
});
return true;
}

else if (request.contentScriptQuery === 'requestMovie') {
console.log(`Requesting movie ${request.tmdbId}`);
else if (request.contentScriptQuery === 'requestMedia') {
console.log(`Requesting media '${request.tmdbId}'`);
pullStoredData(function() {
fetch(`${origin}/api/v1/request`, {
method: 'POST',
Expand Down
16 changes: 6 additions & 10 deletions js/content-scripts/imdb.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
let overseerrContainer, imdbId, tmdbId;
let overseerrContainer, imdbId, tmdbId, mediaType;

// const anchorElement = 'ul.ipc-inline-list.ReviewContent__StyledInlineList-vlmc3o-0.hyrmRe';
const anchorElement = 'div.WatchlistButton__ButtonParent-sc-1fmni0g-0.hbeiyJ';
// ipc-split-button ipc-btn--theme-baseAlt ipc-split-button--ellide-false ipc-btn--type-secondary ipc-btn--on-textPrimary ipc-split-button--width-full WatchlistButton__ButtonParent-sc-1fmni0g-0 hbeiyJ
const textClass = 'text-sm';
const containerClass = 'mt-2 py-2';
const requestCountBackground = '#313131';
Expand All @@ -11,7 +9,7 @@ const imdbRegex = /\/title\/(tt\d+)(?:\/|$).*/;
let matches = document.location.pathname.match(imdbRegex);
if (matches !== null && matches.length > 1) {
imdbId = matches[1];
console.log(`IMDB id: ${imdbId}`);
console.log(`IMDb id: ${imdbId}`);

let title = $('h1.TitleHeader__TitleText-sc-1wu6n3d-0.dxSWFG').text();

Expand All @@ -20,17 +18,15 @@ if (matches !== null && matches.length > 1) {

pullStoredData(function () {
chrome.runtime.sendMessage({contentScriptQuery: 'search', title: title}, json => {
console.log(json);
if (json.results.length === 0) {
removeSpinner();
insertStatusButton('Not found', 0);
return;
}

chrome.runtime.sendMessage({contentScriptQuery: 'queryMovie', tmdbId: json.results[0].id}, json => {
console.log(json);

if (imdbId === json.imdbId) {
const firstResult = json.results[0];
mediaType = firstResult.mediaType;
chrome.runtime.sendMessage({contentScriptQuery: 'queryMedia', tmdbId: firstResult.id, mediaType: mediaType}, json => {
if (imdbId === json.externalIds.imdbId) {
tmdbId = json.id;
console.log(`TMDB id: ${tmdbId}`);
removeSpinner();
Expand Down
8 changes: 5 additions & 3 deletions js/content-scripts/tmdb.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
let overseerrContainer, tmdbId;
let overseerrContainer, tmdbId, mediaType;

const anchorElement = 'ul.auto.actions';
const textClass = '';
const containerClass = 'py-2';
const requestCountBackground = '#032541';

const tmdbRegex = /\/movie\/(\d+)(?:\w|-)*/;
mediaType = document.location.pathname.startsWith('/movie') ? 'movie' : 'tv';

const tmdbRegex = /\/(?:movie|tv)\/(\d+)(?:\w|-)*/;
let matches = document.location.pathname.match(tmdbRegex);
if (matches !== null && matches.length > 1) {
tmdbId = parseInt(matches[1]);
Expand All @@ -15,7 +17,7 @@ if (matches !== null && matches.length > 1) {
insertSpinner();

pullStoredData(function() {
chrome.runtime.sendMessage({contentScriptQuery: 'queryMovie', tmdbId: tmdbId}, json => {
chrome.runtime.sendMessage({contentScriptQuery: 'queryMedia', tmdbId: tmdbId, mediaType: mediaType}, json => {
removeSpinner();
fillContainer(json.mediaInfo);
});
Expand Down
8 changes: 4 additions & 4 deletions js/overseerr-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function insertRequestButton() {
$('#overseerrRequest').on('click', function() {
removeRequestButton();
insertSpinner();
chrome.runtime.sendMessage({contentScriptQuery: 'requestMovie', tmdbId: tmdbId}, json => {
chrome.runtime.sendMessage({contentScriptQuery: 'requestMedia', tmdbId: tmdbId, mediaType: mediaType}, json => {
console.log(json);
initializeContainer();
if (!json.media.hasOwnProperty('requests')) {
Expand All @@ -86,7 +86,7 @@ function removeRequestButton() {
function insertRequestedButton() {
overseerrContainer.append(`
<div id="overseerrRequest" class="relative inline-flex h-full ${textClass} items-center px-4 py-2 leading-5 font-medium z-10 hover:z-20 focus:z-20 focus:outline-none transition
ease-in-out duration-150 button-md overseerr-text-white border bg-indigo-600 border-indigo-600 rounded-md ml-2" href="${origin}/movie/${tmdbId}">
ease-in-out duration-150 button-md overseerr-text-white border bg-indigo-600 border-indigo-600 rounded-md ml-2" href="${origin}/${mediaType}/${tmdbId}">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-3 h-3 sm:w-4 sm:h-4">
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"></path>
</svg>
Expand All @@ -98,14 +98,14 @@ function insertRequestedButton() {
function insertStatusButton(statusText, requestCount) {
overseerrContainer.append(`
<a class="flex group items-center px-4 py-2 ${textClass} leading-6 font-medium rounded${requestCount > 0 ? '-l' : ''}-md overseerr-text-white focus:outline-none transition ease-in-out duration-150
bg-gradient-to-br from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500" href="${origin}/movie/${tmdbId}" target="_blank">
bg-gradient-to-br from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500" href="${origin}/${mediaType}/${tmdbId}" target="_blank">
${statusText}
</a>
`);
if (requestCount > 0) {
overseerrContainer.append(`
<a class="flex group items-center px-4 py-2 ${textClass} leading-6 font-medium rounded-r-md overseerr-text-white focus:outline-none transition ease-in-out duration-150
bg-gradient-to-br from-gray-800 to-gray-900 hover:from-indigo-500 hover:to-purple-500" style="background: ${requestCountBackground}" href="${origin}/movie/${tmdbId}" target="_blank">
bg-gradient-to-br from-gray-800 to-gray-900 hover:from-indigo-500 hover:to-purple-500" style="background: ${requestCountBackground}" href="${origin}/${mediaType}/${tmdbId}" target="_blank">
${requestCount} request${requestCount > 1 ? 's' : ''}
</a>
`);
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Overseerr Extension",
"version": "0.0.2",
"version": "0.0.3",
"description": "Browser extension for Overseerr",
"permissions": ["activeTab", "storage"],
"host_permissions": ["http://*/", "https://*/"],
Expand All @@ -20,7 +20,7 @@
"128": "images/icon.png"
},
"content_scripts": [{
"matches": ["https://www.themoviedb.org/movie/*"],
"matches": ["https://www.themoviedb.org/movie/*", "https://www.themoviedb.org/tv/*"],
"css": ["css/overseerr.min.css", "css/style.css"],
"js": ["js/lib/jquery-3.5.1.min.js", "js/storage.js", "js/overseerr-container.js", "js/content-scripts/tmdb.js"]
}, {
Expand Down

0 comments on commit cd69966

Please sign in to comment.