2017-06-29 05:53:25 +00:00
var basePath = '' ;
2022-01-26 20:05:26 +00:00
var baseUrl = '' ;
2017-06-29 05:53:25 +00:00
var indexers = [ ] ;
var configuredIndexers = [ ] ;
var unconfiguredIndexers = [ ] ;
2021-05-08 20:24:18 +00:00
var configuredTags = [ ] ;
var availableFilters = [ ] ;
2021-05-13 21:41:11 +00:00
var currentFilter = null ;
2017-06-29 05:53:25 +00:00
2021-04-25 01:19:13 +00:00
$ . fn . inView = function ( ) {
if ( ! this . length ) return false ;
2017-06-29 05:53:25 +00:00
var rect = this . get ( 0 ) . getBoundingClientRect ( ) ;
return (
rect . top >= 0 &&
rect . left >= 0 &&
rect . bottom <= ( window . innerHeight || document . documentElement . clientHeight ) &&
rect . right <= ( window . innerWidth || document . documentElement . clientWidth )
) ;
} ;
$ . fn . focusWithoutScrolling = function ( ) {
if ( this . inView ( ) )
this . focus ( ) ;
return this ;
} ;
$ ( document ) . ready ( function ( ) {
2021-04-25 01:19:13 +00:00
$ . ajaxSetup ( {
cache : false
} ) ;
2017-06-29 05:53:25 +00:00
2021-04-25 01:19:13 +00:00
Handlebars . registerHelper ( 'if_eq' , function ( a , b , opts ) {
if ( a == b )
return opts . fn ( this ) ;
else
return opts . inverse ( this ) ;
2020-02-19 20:23:55 +00:00
} ) ;
2021-04-25 01:19:13 +00:00
Handlebars . registerHelper ( 'if_in' , function ( elem , list , opts ) {
if ( list . indexOf ( elem ) > - 1 ) {
2020-02-19 20:23:55 +00:00
return opts . fn ( this ) ;
}
return opts . inverse ( this ) ;
} ) ;
2017-08-08 15:02:16 +00:00
2017-08-12 18:12:30 +00:00
var index = window . location . pathname . indexOf ( "/UI" ) ;
var pathPrefix = window . location . pathname . substr ( 0 , index ) ;
api . root = pathPrefix + api . root ;
2021-05-13 21:41:11 +00:00
const hashArgs = getHashArgs ( ) ;
if ( "indexers" in hashArgs )
currentFilter = hashArgs . filter
2017-06-29 05:53:25 +00:00
bindUIButtons ( ) ;
loadJackettSettings ( ) ;
} ) ;
2017-07-23 00:08:19 +00:00
function openSearchIfNecessary ( ) {
2021-05-13 21:41:11 +00:00
const hashArgs = getHashArgs ( ) ;
2017-08-28 16:54:57 +00:00
if ( "search" in hashArgs ) {
2021-05-08 20:24:18 +00:00
showSearch ( hashArgs . filter , hashArgs . tracker , hashArgs . search , hashArgs . category ) ;
2017-07-23 00:08:19 +00:00
}
}
2021-05-13 21:41:11 +00:00
function getHashArgs ( ) {
return location . hash . substring ( 1 ) . split ( '&' ) . reduce ( ( prev , item ) => Object . assign ( {
[ item . split ( '=' ) [ 0 ] ] : ( item . split ( '=' ) . length < 2 ?
undefined :
decodeURIComponent ( item . split ( '=' ) [ 1 ] . replace ( /\+/g , '%20' ) ) )
} , prev ) , { } ) ;
}
2021-05-08 20:24:18 +00:00
function type _filter ( indexer ) {
return indexer . type == this . value ;
}
function tag _filter ( indexer ) {
return indexer . tags . map ( t => t . toLowerCase ( ) ) . indexOf ( this . value . toLowerCase ( ) ) > - 1 ;
}
2021-05-15 21:52:12 +00:00
function state _filter ( indexer ) {
return indexer . state == this . value ;
}
2017-06-29 05:53:25 +00:00
function getJackettConfig ( callback ) {
2017-08-08 15:02:16 +00:00
api . getServerConfig ( callback ) . fail ( function ( ) {
2017-08-20 12:54:34 +00:00
doNotify ( "Error loading Jackett settings, request to Jackett server failed, is server running ?" , "danger" , "glyphicon glyphicon-alert" ) ;
2017-06-29 05:53:25 +00:00
} ) ;
}
function loadJackettSettings ( ) {
getJackettConfig ( function ( data ) {
2017-08-08 15:02:16 +00:00
$ ( "#api-key-input" ) . val ( data . api _key ) ;
$ ( ".api-key-text" ) . text ( data . api _key ) ;
2017-06-29 05:53:25 +00:00
$ ( "#app-version" ) . html ( data . app _version ) ;
2017-08-08 15:02:16 +00:00
$ ( "#jackett-port" ) . val ( data . port ) ;
2017-10-31 09:45:30 +00:00
2017-11-06 10:51:26 +00:00
$ ( "#jackett-proxy-type" ) . val ( data . proxy _type ) ;
2017-10-31 09:45:30 +00:00
$ ( "#jackett-proxy-url" ) . val ( data . proxy _url ) ;
$ ( "#jackett-proxy-port" ) . val ( data . proxy _port ) ;
$ ( "#jackett-proxy-username" ) . val ( data . proxy _username ) ;
$ ( "#jackett-proxy-password" ) . val ( data . proxy _password ) ;
2020-09-26 20:28:29 +00:00
proxyWarning ( data . proxy _type ) ;
2017-10-31 09:45:30 +00:00
2017-08-08 15:02:16 +00:00
$ ( "#jackett-basepathoverride" ) . val ( data . basepathoverride ) ;
basePath = data . basepathoverride ;
2017-06-29 05:53:25 +00:00
if ( basePath === null || basePath === undefined ) {
basePath = '' ;
}
2017-08-08 15:02:16 +00:00
2022-01-26 20:05:26 +00:00
$ ( "#jackett-baseurloverride" ) . val ( data . baseurloverride ) ;
baseUrl = data . baseurloverride ;
if ( baseUrl === null || baseUrl === undefined ) {
baseUrl = '' ;
}
2017-08-11 23:04:30 +00:00
api . key = data . api _key ;
2017-08-08 15:02:16 +00:00
$ ( "#jackett-savedir" ) . val ( data . blackholedir ) ;
$ ( "#jackett-allowext" ) . attr ( 'checked' , data . external ) ;
2023-07-14 03:37:15 +00:00
$ ( "#jackett-local-bind-address" ) . val ( data . local _bind _address ) ;
2022-04-24 22:17:35 +00:00
$ ( "#jackett-allowcors" ) . attr ( 'checked' , data . cors ) ;
2017-08-08 15:02:16 +00:00
$ ( "#jackett-allowupdate" ) . attr ( 'checked' , data . updatedisabled ) ;
$ ( "#jackett-prerelease" ) . attr ( 'checked' , data . prerelease ) ;
$ ( "#jackett-logging" ) . attr ( 'checked' , data . logging ) ;
2020-12-11 22:14:21 +00:00
$ ( "#jackett-cache-enabled" ) . attr ( 'checked' , data . cache _enabled ) ;
$ ( "#jackett-cache-ttl" ) . val ( data . cache _ttl ) ;
$ ( "#jackett-cache-max-results-per-indexer" ) . val ( data . cache _max _results _per _indexer ) ;
if ( ! data . cache _enabled ) {
$ ( "#jackett-show-releases" ) . attr ( "disabled" , true ) ;
}
2020-12-13 20:42:10 +00:00
$ ( "#jackett-flaresolverrurl" ) . val ( data . flaresolverrurl ) ;
2022-01-09 18:38:14 +00:00
$ ( "#jackett-flaresolverr-maxtimeout" ) . val ( data . flaresolverr _maxtimeout ) ;
2017-08-08 15:02:16 +00:00
$ ( "#jackett-omdbkey" ) . val ( data . omdbkey ) ;
2018-07-09 10:37:24 +00:00
$ ( "#jackett-omdburl" ) . val ( data . omdburl ) ;
2017-08-08 15:02:16 +00:00
var password = data . password ;
2017-06-29 05:53:25 +00:00
$ ( "#jackett-adminpwd" ) . val ( password ) ;
if ( password != null && password != '' ) {
$ ( "#logoutBtn" ) . show ( ) ;
}
2019-04-27 10:59:33 +00:00
if ( data . can _run _netcore != null && data . can _run _netcore === true ) {
$ ( "#can-upgrade-from-mono" ) . show ( ) ;
}
2024-01-26 06:55:13 +00:00
if ( data . external != null && data . external === true && data . password === '' ) {
$ ( "#warning-external-access" ) . show ( ) ;
}
2017-08-08 15:02:16 +00:00
$ . each ( data . notices , function ( index , value ) {
2017-06-29 05:53:25 +00:00
console . log ( value ) ;
doNotify ( value , "danger" , "glyphicon glyphicon-alert" , false ) ;
2020-09-26 20:28:29 +00:00
} ) ;
2017-06-29 05:53:25 +00:00
reloadIndexers ( ) ;
} ) ;
}
function reloadIndexers ( ) {
2021-05-08 20:24:18 +00:00
$ ( '#filters' ) . hide ( ) ;
2017-06-29 05:53:25 +00:00
$ ( '#indexers' ) . hide ( ) ;
2017-08-08 15:02:16 +00:00
api . getAllIndexers ( function ( data ) {
2017-06-29 05:53:25 +00:00
indexers = data ;
configuredIndexers = [ ] ;
unconfiguredIndexers = [ ] ;
2021-05-08 20:24:18 +00:00
configuredTags = [ ] ;
availableFilters = [ ] ;
2017-08-08 15:02:16 +00:00
for ( var i = 0 ; i < data . length ; i ++ ) {
var item = data [ i ] ;
2022-01-26 20:05:26 +00:00
item . rss _host = resolveUrl ( baseUrl , basePath + "/api/v2.0/indexers/" + item . id + "/results/torznab/api?apikey=" + api . key + "&t=search&cat=&q=" ) ;
item . torznab _host = resolveUrl ( baseUrl , basePath + "/api/v2.0/indexers/" + item . id + "/results/torznab/" ) ;
item . potato _host = resolveUrl ( baseUrl , basePath + "/api/v2.0/indexers/" + item . id + "/results/potato/" ) ;
2017-08-08 15:02:16 +00:00
2017-06-29 05:53:25 +00:00
if ( item . last _error )
item . state = "error" ;
else
item . state = "success" ;
if ( item . type == "public" ) {
2017-09-08 07:06:06 +00:00
item . type _label = "success" ;
2021-04-25 01:19:13 +00:00
} else if ( item . type == "private" ) {
2017-09-08 07:06:06 +00:00
item . type _label = "danger" ;
2021-04-25 01:19:13 +00:00
} else if ( item . type == "semi-private" ) {
2017-09-08 07:06:06 +00:00
item . type _label = "warning" ;
2021-04-25 01:19:13 +00:00
} else {
2017-09-08 07:06:06 +00:00
item . type _label = "default" ;
2017-06-29 05:53:25 +00:00
}
2021-04-25 01:19:13 +00:00
var main _cats _list = item . caps . filter ( function ( c ) {
2017-08-08 15:02:16 +00:00
return c . ID < 100000 ;
2021-04-25 01:19:13 +00:00
} ) . map ( function ( c ) {
2017-08-08 15:02:16 +00:00
return c . Name . split ( "/" ) [ 0 ] ;
} ) ;
2017-06-29 05:53:25 +00:00
item . mains _cats = $ . unique ( main _cats _list ) . join ( ", " ) ;
2017-08-08 15:02:16 +00:00
2017-06-29 05:53:25 +00:00
if ( item . configured )
configuredIndexers . push ( item ) ;
else
unconfiguredIndexers . push ( item ) ;
}
2021-05-08 20:24:18 +00:00
configuredTags = configuredIndexers . map ( i => i . tags ) . reduce ( ( a , g ) => a . concat ( g ) , [ ] ) . filter ( ( v , i , a ) => a . indexOf ( v ) === i ) ;
configureFilters ( configuredIndexers ) ;
2021-10-20 11:16:18 +00:00
2021-05-13 21:41:11 +00:00
displayFilteredIndexersList ( configuredIndexers , currentFilter ) ;
2021-05-08 20:24:18 +00:00
2017-06-29 05:53:25 +00:00
$ ( '#indexers div.dataTables_filter input' ) . focusWithoutScrolling ( ) ;
2017-08-11 23:04:07 +00:00
openSearchIfNecessary ( ) ;
2017-06-29 05:53:25 +00:00
} ) . fail ( function ( ) {
2017-08-20 11:11:46 +00:00
doNotify ( "Error loading indexers, request to Jackett server failed, is server running ?" , "danger" , "glyphicon glyphicon-alert" ) ;
2017-06-29 05:53:25 +00:00
} ) ;
}
2021-05-08 20:24:18 +00:00
function configureFilters ( indexers ) {
function add ( f ) {
if ( availableFilters . find ( x => x . id == f . id ) )
return ;
if ( ! indexers . every ( f . apply , f ) && indexers . some ( f . apply , f ) )
availableFilters . push ( f ) ;
}
2021-05-15 21:52:12 +00:00
availableFilters . push ( { id : "test:passed" , apply : state _filter , value : "success" } ) ;
availableFilters . push ( { id : "test:failed" , apply : state _filter , value : "error" } ) ;
2021-05-08 20:24:18 +00:00
[ "public" , "private" , "semi-private" ]
. map ( t => { return { id : "type:" + t , apply : type _filter , value : t } } )
. forEach ( add ) ;
configuredTags . sort ( )
. map ( t => { return { id : "tag:" + t . toLowerCase ( ) , apply : tag _filter , value : t } } )
. forEach ( add ) ;
}
2021-05-13 21:41:11 +00:00
function displayFilteredIndexersList ( indexers , filter ) {
var active = availableFilters . find ( x => x . id == filter ) ;
if ( availableFilters . length > 0 ) {
var filtersTemplate = Handlebars . compile ( $ ( "#jackett-filters" ) . html ( ) ) ;
var filters = $ ( filtersTemplate ( {
filters : availableFilters ,
active : active ? active . id : null
} ) ) ;
$ ( "li a" , filters ) . on ( 'click' , function ( ) {
displayFilteredIndexersList ( configuredIndexers , $ ( this ) . data ( "id" ) ) ;
} ) ;
$ ( '#filters' ) . empty ( ) ;
$ ( '#filters' ) . append ( filters ) ;
$ ( '#filters' ) . fadeIn ( ) ;
}
if ( active ) {
indexers = indexers . filter ( active . apply , active ) ;
currentFilter = active . id ;
}
else {
currentFilter = null ;
}
displayConfiguredIndexersList ( indexers )
}
2017-06-29 05:53:25 +00:00
function displayConfiguredIndexersList ( indexers ) {
var indexersTemplate = Handlebars . compile ( $ ( "#configured-indexer-table" ) . html ( ) ) ;
2021-04-25 01:19:13 +00:00
var indexersTable = $ ( indexersTemplate ( {
indexers : indexers ,
total _configured _indexers : indexers . length
} ) ) ;
2017-06-29 05:53:25 +00:00
prepareTestButtons ( indexersTable ) ;
prepareSearchButtons ( indexersTable ) ;
prepareSetupButtons ( indexersTable ) ;
prepareDeleteButtons ( indexersTable ) ;
prepareCopyButtons ( indexersTable ) ;
2021-04-25 01:19:13 +00:00
indexersTable . find ( "table" ) . dataTable ( {
"stateSave" : true ,
"stateDuration" : 0 ,
"pageLength" : - 1 ,
"lengthMenu" : [
[ 10 , 20 , 50 , 100 , 250 , 500 , - 1 ] ,
[ 10 , 20 , 50 , 100 , 250 , 500 , "All" ]
] ,
"order" : [
[ 0 , "asc" ]
] ,
"columnDefs" : [ {
"targets" : 0 ,
"visible" : true ,
"searchable" : true ,
"orderable" : true
} ,
{
"targets" : 1 ,
"visible" : true ,
"searchable" : true ,
"orderable" : true
2022-01-16 15:32:47 +00:00
} ,
{
"targets" : 2 ,
"visible" : false ,
"searchable" : true ,
"orderable" : false
2021-04-25 01:19:13 +00:00
}
]
} ) ;
2017-06-29 05:53:25 +00:00
$ ( '#indexers' ) . empty ( ) ;
$ ( '#indexers' ) . append ( indexersTable ) ;
$ ( '#indexers' ) . fadeIn ( ) ;
}
function displayUnconfiguredIndexersList ( ) {
var UnconfiguredIndexersDialog = $ ( $ ( "#select-indexer" ) . html ( ) ) ;
2017-08-08 15:02:16 +00:00
2017-06-29 05:53:25 +00:00
var indexersTemplate = Handlebars . compile ( $ ( "#unconfigured-indexer-table" ) . html ( ) ) ;
2021-04-25 01:19:13 +00:00
var indexersTable = $ ( indexersTemplate ( {
indexers : unconfiguredIndexers ,
total _unconfigured _indexers : unconfiguredIndexers . length
} ) ) ;
2017-06-29 05:53:25 +00:00
indexersTable . find ( '.indexer-setup' ) . each ( function ( i , btn ) {
2017-08-08 15:02:16 +00:00
var indexer = unconfiguredIndexers [ i ] ;
$ ( btn ) . click ( function ( ) {
2023-03-10 11:55:24 +00:00
$ ( '#select-indexer-modal' ) . modal ( 'hide' ) . on ( 'hidden.bs.modal' , function ( ) {
displayIndexerSetup ( indexer . id , indexer . name , indexer . caps , indexer . site _link , indexer . alternativesitelinks , indexer . description ) ;
2017-08-08 15:02:16 +00:00
} ) ;
} ) ;
} ) ;
indexersTable . find ( '.indexer-add' ) . each ( function ( i , btn ) {
$ ( btn ) . click ( function ( ) {
2017-06-29 05:53:25 +00:00
$ ( '#select-indexer-modal' ) . modal ( 'hide' ) . on ( 'hidden.bs.modal' , function ( e ) {
2017-08-08 15:02:16 +00:00
var indexerId = $ ( btn ) . attr ( "data-id" ) ;
2021-05-17 01:13:35 +00:00
addIndexer ( indexerId , true ) ;
2017-06-29 05:53:25 +00:00
} ) ;
} ) ;
} ) ;
2021-04-25 01:19:13 +00:00
indexersTable . find ( "table" ) . DataTable ( {
initComplete : function ( ) {
var currentTable = this ;
this . api ( ) . columns ( ) . every ( function ( index , i , j ) {
var column = this ;
var headerText = column . header ( ) . innerText ;
if ( headerText == 'Type' ) {
var select = createDropDownHtml ( column , true ) ;
var columnData = currentTable . api ( ) . columns ( index + 1 ) . data ( ) ;
var distinctValues = [ ... new Set ( columnData [ 0 ] ) ] ;
distinctValues . forEach ( function ( distinctVal ) {
select . append ( '<option value="' + distinctVal + '">' + distinctVal . replace ( /^\w/ , ( c ) => c . toUpperCase ( ) ) + '</option>' )
} ) ;
} else if ( headerText == 'Categories' ) {
var select = createDropDownHtml ( column , false ) ;
2021-04-24 06:45:33 +00:00
2021-04-25 01:19:13 +00:00
var columnData = [ ] ;
column . data ( ) . unique ( ) . each ( function ( d , j ) {
d . split ( ',' ) . forEach ( function ( val ) {
columnData . push ( val . trim ( ) ) ;
2021-04-24 06:45:33 +00:00
} ) ;
2021-04-25 01:19:13 +00:00
} ) ;
var distinctValues = [ ... new Set ( columnData ) ] ;
distinctValues . sort ( ) . forEach ( function ( distinctVal ) {
select . append ( '<option value="' + distinctVal + '">' + distinctVal + '</option>' )
} ) ;
} else if ( headerText == 'Language' ) {
var select = createDropDownHtml ( column , true ) ;
column . data ( ) . unique ( ) . sort ( ) . each ( function ( d , j ) {
select . append ( '<option value="' + d + '">' + d + '</option>' )
} ) ;
} else {
$ ( column . footer ( ) ) . empty ( ) ;
}
} ) ;
} ,
2021-05-17 01:13:35 +00:00
"drawCallback" : function ( settings ) {
addCheckOnCellClick ( ) ;
} ,
2021-04-25 01:19:13 +00:00
"stateSave" : true ,
"stateDuration" : 0 ,
"fnStateSaveParams" : function ( oSettings , sValue ) {
sValue . search . search = "" ; // don't save the search filter content
return sValue ;
} ,
"bAutoWidth" : false ,
"pageLength" : - 1 ,
"lengthMenu" : [
[ 10 , 20 , 50 , 100 , 250 , 500 , - 1 ] ,
[ 10 , 20 , 50 , 100 , 250 , 500 , "All" ]
] ,
2021-05-17 01:13:35 +00:00
"select" : {
style : 'os' ,
selector : 'td:first-child'
} ,
2021-04-25 01:19:13 +00:00
"order" : [
2021-05-17 01:13:35 +00:00
[ 1 , "asc" ]
2021-04-25 01:19:13 +00:00
] ,
"columnDefs" : [ {
2021-05-17 01:13:35 +00:00
"name" : "select" ,
2021-04-25 01:19:13 +00:00
"targets" : 0 ,
"visible" : true ,
2021-05-17 01:13:35 +00:00
"searchable" : false ,
"orderable" : false
} ,
{
"name" : "name" ,
"targets" : 1 ,
"visible" : true ,
2021-04-25 01:19:13 +00:00
"searchable" : true ,
"orderable" : true
2021-04-24 06:45:33 +00:00
} ,
2021-04-25 01:19:13 +00:00
{
"name" : "description" ,
2021-05-17 01:13:35 +00:00
"targets" : 2 ,
2021-04-25 01:19:13 +00:00
"visible" : true ,
"searchable" : true ,
"orderable" : true
2017-06-29 05:53:25 +00:00
} ,
2021-04-25 01:19:13 +00:00
{
"name" : "type" ,
2021-05-17 01:13:35 +00:00
"targets" : 3 ,
2021-04-25 01:19:13 +00:00
"visible" : true ,
"searchable" : true ,
"orderable" : true
} ,
{
"name" : "type_string" ,
2021-05-17 01:13:35 +00:00
"targets" : 4 ,
2021-04-25 01:19:13 +00:00
"visible" : false ,
2021-05-17 01:13:35 +00:00
"searchable" : false ,
"orderable" : false ,
2021-04-25 01:19:13 +00:00
} ,
{
"name" : "language" ,
2021-05-17 01:13:35 +00:00
"targets" : 5 ,
2021-04-25 01:19:13 +00:00
"visible" : true ,
"searchable" : true ,
"orderable" : true
} ,
{
"name" : "buttons" ,
2021-05-17 01:13:35 +00:00
"targets" : 6 ,
2021-04-25 01:19:13 +00:00
"visible" : true ,
"searchable" : false ,
"orderable" : false
2022-01-16 15:32:47 +00:00
} ,
{
"name" : "url" ,
"targets" : 7 ,
"visible" : false ,
"searchable" : true ,
"orderable" : false
2021-04-25 01:19:13 +00:00
}
]
} ) ;
2017-06-29 05:53:25 +00:00
var undefindexers = UnconfiguredIndexersDialog . find ( '#unconfigured-indexers' ) ;
undefindexers . append ( indexersTable ) ;
2017-08-08 15:02:16 +00:00
2021-04-25 01:19:13 +00:00
UnconfiguredIndexersDialog . on ( 'shown.bs.modal' , function ( ) {
2017-06-29 05:53:25 +00:00
$ ( this ) . find ( 'div.dataTables_filter input' ) . focusWithoutScrolling ( ) ;
} ) ;
UnconfiguredIndexersDialog . on ( 'hidden.bs.modal' , function ( e ) {
$ ( '#indexers div.dataTables_filter input' ) . focusWithoutScrolling ( ) ;
} ) ;
2023-05-27 16:41:35 +00:00
$ ( "#modals" ) . html ( UnconfiguredIndexersDialog ) ;
2017-08-08 15:02:16 +00:00
2021-05-17 01:13:35 +00:00
$ ( '#add-selected-indexers' ) . click ( function ( ) {
var selectedIndexers = $ ( '#unconfigured-indexer-datatable' ) . DataTable ( ) . $ ( 'input[type="checkbox"]' ) ;
var hasSelectedIndexers = selectedIndexers . is ( ':checked' ) ;
if ( hasSelectedIndexers ) {
doNotify ( "Adding selected Indexers, please wait..." , "info" , "glyphicon glyphicon-transfer" , false ) ;
$ ( '#select-indexer-modal button' ) . attr ( 'disabled' , true ) ;
addIndexers ( selectedIndexers ,
addSelectedIndexersSuccess ,
addSelectedIndexersError ) ;
} else {
doNotify ( "Error: You must select more than one indexer" , "danger" , "glyphicon glyphicon-alert" ) ;
}
} ) ;
2017-06-29 05:53:25 +00:00
UnconfiguredIndexersDialog . modal ( "show" ) ;
}
2021-05-17 01:13:35 +00:00
function addSelectedIndexersSuccess ( ) {
$ . notifyClose ( ) ;
$ ( '#select-indexer-modal' ) . modal ( 'hide' ) ;
doNotify ( "Selected indexers successfully added." , "success" , "glyphicon glyphicon-ok" ) ;
$ ( '#select-indexer-modal button' ) . attr ( 'disabled' , false ) ;
}
function addSelectedIndexersError ( e , xhr , options , err ) {
doNotify ( "Configuration failed" , "danger" , "glyphicon glyphicon-alert" ) ;
}
function addCheckOnCellClick ( ) {
$ ( 'td.checkboxColumn' )
. off ( 'click' )
. on ( 'click' , ( function ( event ) {
if ( ! $ ( event . target ) . is ( 'input' ) ) {
$ ( 'input:checkbox' , this ) . prop ( 'checked' , function ( i , value ) {
return ! value ;
} ) ;
}
} ) ) ;
}
function addIndexers ( selectedIndexerList , successCallback , errorCallback ) {
$ ( document ) . ajaxStop ( function ( ) {
if ( successCallback == addSelectedIndexersSuccess ) {
$ ( document ) . ajaxStop ( ) . unbind ( ) ; // Keep future AJAX events from effecting this
successCallback ( ) ;
}
} ) . ajaxError ( function ( e , xhr , options , err ) {
errorCallback ( e , xhr , options , err ) ;
} ) ;
selectedIndexerList . each ( function ( ) {
if ( this . checked ) {
addIndexer ( $ ( this ) . data ( 'id' ) , false ) ;
}
} )
}
2021-04-25 01:19:13 +00:00
function createDropDownHtml ( column , exactMatch ) {
var select = $ ( '<select><option value="">Show all</option></select>' )
. appendTo ( $ ( column . footer ( ) ) . empty ( ) )
. on ( 'change' , function ( ) {
var val = $ . fn . dataTable . util . escapeRegex (
$ ( this ) . val ( )
) ;
if ( exactMatch ) {
column
. search ( val ? '^' + val + '$' : '' , true , false )
. draw ( ) ;
} else {
column
. search ( val ? val : '' , true , false )
. draw ( ) ;
}
} ) ;
return select ;
}
2021-05-17 01:13:35 +00:00
function addIndexer ( indexerId , displayNotification ) {
api . getIndexerConfig ( indexerId , function ( data ) {
if ( data . result !== undefined && data . result == "error" ) {
doNotify ( "Error: " + data . error , "danger" , "glyphicon glyphicon-alert" ) ;
return ;
}
api . updateIndexerConfig ( indexerId , data , function ( data ) {
if ( data == undefined ) {
reloadIndexers ( ) ;
if ( displayNotification ) {
doNotify ( "Successfully configured " + indexerId , "success" , "glyphicon glyphicon-ok" ) ;
}
} else if ( data . result == "error" ) {
if ( data . config ) {
populateConfigItems ( configForm , data . config ) ;
}
doNotify ( "Configuration failed: " + data . error , "danger" , "glyphicon glyphicon-alert" ) ;
}
} ) . fail ( function ( data ) {
2022-04-17 10:26:27 +00:00
doErrorNotify ( indexerId , data . responseJSON . error , "configuring" ) ;
2021-05-17 01:13:35 +00:00
} ) ;
} ) ;
}
2017-06-29 05:53:25 +00:00
function copyToClipboard ( text ) {
// create hidden text element, if it doesn't already exist
var targetId = "_hiddenCopyText_" ;
// must use a temporary form element for the selection and copy
target = document . getElementById ( targetId ) ;
if ( ! target ) {
var target = document . createElement ( "textarea" ) ;
target . style . position = "fixed" ;
target . style . left = "-9999px" ;
target . style . top = "0" ;
target . id = targetId ;
document . body . appendChild ( target ) ;
}
target . textContent = text ;
// select the content
var currentFocus = document . activeElement ;
target . focus ( ) ;
target . setSelectionRange ( 0 , target . value . length ) ;
// copy the selection
var succeed ;
try {
succeed = document . execCommand ( "copy" ) ;
2020-02-01 18:35:20 +00:00
doNotify ( "Copied to clipboard!" , "success" , "glyphicon glyphicon-ok" ) ;
2017-06-29 05:53:25 +00:00
} catch ( e ) {
succeed = false ;
}
// restore original focus
if ( currentFocus && typeof currentFocus . focus === "function" ) {
$ ( currentFocus ) . focusWithoutScrolling ( ) ;
}
target . textContent = "" ;
return succeed ;
}
function prepareCopyButtons ( element ) {
element . find ( ".indexer-button-copy" ) . each ( function ( i , btn ) {
var $btn = $ ( btn ) ;
var title = $btn [ 0 ] . title ;
$btn . click ( function ( ) {
copyToClipboard ( title ) ;
return false ;
} ) ;
} ) ;
}
function prepareDeleteButtons ( element ) {
element . find ( ".indexer-button-delete" ) . each ( function ( i , btn ) {
var $btn = $ ( btn ) ;
var id = $btn . data ( "id" ) ;
$btn . click ( function ( ) {
2017-08-08 15:02:16 +00:00
api . deleteIndexer ( id , function ( data ) {
if ( data == undefined ) {
2017-06-29 05:53:25 +00:00
doNotify ( "Deleted " + id , "success" , "glyphicon glyphicon-ok" ) ;
2017-08-08 15:02:16 +00:00
} else if ( data . result == "error" ) {
doNotify ( "Delete error for " + id + "\n" + data . error , "danger" , "glyphicon glyphicon-alert" ) ;
2017-06-29 05:53:25 +00:00
}
} ) . fail ( function ( ) {
doNotify ( "Error deleting indexer, request to Jackett server error" , "danger" , "glyphicon glyphicon-alert" ) ;
} ) . always ( function ( ) {
reloadIndexers ( ) ;
} ) ;
} ) ;
} ) ;
}
function prepareSearchButtons ( element ) {
element . find ( '.indexer-button-search' ) . each ( function ( i , btn ) {
var $btn = $ ( btn ) ;
var id = $btn . data ( "id" ) ;
2021-04-25 01:19:13 +00:00
$btn . click ( function ( ) {
2021-05-13 21:41:11 +00:00
window . location . hash = "search&tracker=" + id + ( currentFilter ? "&filter=" + currentFilter : "" ) ;
showSearch ( currentFilter , id ) ;
2017-06-29 05:53:25 +00:00
} ) ;
} ) ;
}
function prepareSetupButtons ( element ) {
element . find ( '.indexer-setup' ) . each ( function ( i , btn ) {
2021-05-08 20:24:18 +00:00
var $btn = $ ( btn ) ;
var id = $btn . data ( "id" ) ;
var indexer = configuredIndexers . find ( i => i . id === id ) ;
if ( indexer )
$btn . click ( function ( ) {
2023-03-10 11:55:24 +00:00
displayIndexerSetup ( indexer . id , indexer . name , indexer . caps , indexer . site _link , indexer . alternativesitelinks , indexer . description ) ;
2021-05-08 20:24:18 +00:00
} ) ;
2017-06-29 05:53:25 +00:00
} ) ;
}
2021-04-25 01:19:13 +00:00
function updateTestState ( id , state , message , parent ) {
var btn = parent . find ( ".indexer-button-test[data-id=" + id + "]" ) ;
2017-06-29 05:53:25 +00:00
var sortmsg = message ;
if ( ! sortmsg || state == "success" )
sortmsg = "" ;
var td = btn . closest ( "td" ) ;
td . attr ( "data-sort" , sortmsg ) ;
td . attr ( "data-filter" , sortmsg ) ;
if ( message ) {
btn . tooltip ( "hide" ) ;
btn . attr ( "title" , message ) ;
2021-04-25 01:19:13 +00:00
btn . data ( 'bs.tooltip' , false ) . tooltip ( {
title : message
} ) ;
2017-06-29 05:53:25 +00:00
}
var icon = btn . find ( "span" ) ;
icon . removeClass ( "glyphicon-ok test-success glyphicon-alert test-error glyphicon-refresh spinner test-inprogres" ) ;
if ( state == "success" ) {
icon . addClass ( "glyphicon-ok test-success" ) ;
} else if ( state == "error" ) {
icon . addClass ( "glyphicon-alert test-error" ) ;
} else if ( state == "inprogres" ) {
icon . addClass ( "glyphicon-refresh test-inprogres spinner" ) ;
}
2021-04-25 01:19:13 +00:00
var dt = $ . fn . dataTable . tables ( {
visible : true ,
api : true
} ) . rows ( ) . invalidate ( 'dom' ) ;
2017-06-29 05:53:25 +00:00
if ( state != "inprogres" )
dt . draw ( ) ;
2021-05-15 21:52:12 +00:00
var indexer = configuredIndexers . find ( x => x . id == id ) ;
if ( indexer )
indexer . state = state ;
2017-06-29 05:53:25 +00:00
}
function testIndexer ( id , notifyResult ) {
var indexers = $ ( '#indexers' ) ;
updateTestState ( id , "inprogres" , null , indexers ) ;
2017-08-08 15:02:16 +00:00
2017-06-29 05:53:25 +00:00
if ( notifyResult )
doNotify ( "Test started for " + id , "info" , "glyphicon glyphicon-transfer" ) ;
2017-08-08 15:02:16 +00:00
api . testIndexer ( id , function ( data ) {
if ( data == undefined ) {
2017-06-29 05:53:25 +00:00
updateTestState ( id , "success" , "Test successful" , indexers ) ;
if ( notifyResult )
doNotify ( "Test successful for " + id , "success" , "glyphicon glyphicon-ok" ) ;
2017-08-08 15:02:16 +00:00
} else if ( data . result == "error" ) {
updateTestState ( id , "error" , data . error , indexers ) ;
if ( notifyResult )
doNotify ( "Test failed for " + id + ": \n" + data . error , "danger" , "glyphicon glyphicon-alert" ) ;
2017-06-29 05:53:25 +00:00
}
2017-08-20 12:54:34 +00:00
} ) . fail ( function ( data ) {
2021-04-25 01:19:13 +00:00
updateTestState ( id , "error" , data . error , indexers ) ;
2022-04-17 10:26:27 +00:00
doErrorNotify ( id , data . responseJSON . error , "testing" ) ;
2017-06-29 05:53:25 +00:00
} ) ;
}
function prepareTestButtons ( element ) {
element . find ( ".indexer-button-test" ) . each ( function ( i , btn ) {
var $btn = $ ( btn ) ;
var id = $btn . data ( "id" ) ;
var state = $btn . data ( "state" ) ;
var title = $btn . attr ( "title" ) ;
$btn . tooltip ( ) ;
updateTestState ( id , state , title , element ) ;
$btn . click ( function ( ) {
testIndexer ( id , true ) ;
} ) ;
} ) ;
}
2017-10-01 09:28:10 +00:00
function displayIndexerSetup ( id , name , caps , link , alternativesitelinks , description ) {
2017-08-08 15:02:16 +00:00
api . getIndexerConfig ( id , function ( data ) {
if ( data . result !== undefined && data . result == "error" ) {
2017-06-29 05:53:25 +00:00
doNotify ( "Error: " + data . error , "danger" , "glyphicon glyphicon-alert" ) ;
return ;
}
2017-10-01 09:28:10 +00:00
populateSetupForm ( id , name , data , caps , link , alternativesitelinks , description ) ;
2017-06-29 05:53:25 +00:00
} ) . fail ( function ( ) {
doNotify ( "Request to Jackett server failed" , "danger" , "glyphicon glyphicon-alert" ) ;
} ) ;
$ ( "#select-indexer-modal" ) . modal ( "hide" ) ;
}
function populateConfigItems ( configForm , config ) {
// Set flag so we show fields named password as a password input
for ( var i = 0 ; i < config . length ; i ++ ) {
config [ i ] . ispassword = config [ i ] . id . toLowerCase ( ) === 'password' ;
}
var $formItemContainer = configForm . find ( ".config-setup-form" ) ;
$formItemContainer . empty ( ) ;
var setupItemTemplate = Handlebars . compile ( $ ( "#setup-item" ) . html ( ) ) ;
2020-11-05 02:19:09 +00:00
for ( var i = 0 ; i < config . length ; i ++ ) {
var item = config [ i ] ;
var setupValueTemplate = Handlebars . compile ( $ ( "#setup-item-" + item . type ) . html ( ) ) ;
item . value _element = setupValueTemplate ( item ) ;
2021-05-08 20:24:18 +00:00
var template = $ ( setupItemTemplate ( item ) ) ;
2017-06-29 05:53:25 +00:00
$formItemContainer . append ( template ) ;
2021-05-08 20:24:18 +00:00
setupConfigItem ( template , item ) ;
2017-06-29 05:53:25 +00:00
}
}
2021-05-08 20:24:18 +00:00
function setupConfigItem ( configItem , item ) {
switch ( item . type ) {
case "inputtags" : {
configItem . find ( "input" ) . tagify ( {
dropdown : {
enabled : 0 ,
position : "text"
} ,
separator : item . separator || "," ,
whitelist : item . whitelist || [ ] ,
blacklist : item . blacklist || [ ] ,
pattern : item . pattern || null ,
delimiters : item . delimiters || item . separator || "," ,
originalInputValueFormat : function ( values ) { return values . map ( item => item . value . toLowerCase ( ) ) . join ( this . separator ) ; }
} ) ;
}
break ;
}
}
2017-10-01 09:28:10 +00:00
function newConfigModal ( title , config , caps , link , alternativesitelinks , description ) {
2017-06-29 05:53:25 +00:00
var configTemplate = Handlebars . compile ( $ ( "#jackett-config-setup-modal" ) . html ( ) ) ;
2021-04-25 01:19:13 +00:00
var configForm = $ ( configTemplate ( {
title : title ,
caps : caps ,
link : link ,
description : description
} ) ) ;
2023-05-27 16:41:35 +00:00
$ ( "#modals" ) . html ( configForm ) ;
2017-06-29 05:53:25 +00:00
populateConfigItems ( configForm , config ) ;
if ( alternativesitelinks . length >= 1 ) {
var AlternativeSiteLinksTemplate = Handlebars . compile ( $ ( "#setup-item-alternativesitelinks" ) . html ( ) ) ;
2021-04-25 01:19:13 +00:00
var template = $ ( AlternativeSiteLinksTemplate ( {
"alternativesitelinks" : alternativesitelinks
} ) ) ;
2017-06-29 05:53:25 +00:00
configForm . find ( "div[data-id='sitelink']" ) . after ( template ) ;
2017-08-31 09:12:50 +00:00
template . find ( "a.alternativesitelink" ) . click ( function ( a ) {
$ ( "div[data-id='sitelink'] input" ) . val ( this . href ) ;
return false ;
} ) ;
2017-06-29 05:53:25 +00:00
}
2021-05-08 20:24:18 +00:00
$ ( "div[data-id='tags'] input" , configForm ) . data ( "tagify" ) . settings . whitelist = configuredTags ;
2017-06-29 05:53:25 +00:00
return configForm ;
}
function getConfigModalJson ( configForm ) {
var configJson = [ ] ;
configForm . find ( ".config-setup-form" ) . children ( ) . each ( function ( i , el ) {
$el = $ ( el ) ;
var type = $el . data ( "type" ) ;
var id = $el . data ( "id" ) ;
2021-04-25 01:19:13 +00:00
var itemEntry = {
id : id
} ;
2017-06-29 05:53:25 +00:00
switch ( type ) {
case "hiddendata" :
itemEntry . value = $el . find ( ".setup-item-hiddendata input" ) . val ( ) ;
break ;
case "inputstring" :
itemEntry . value = $el . find ( ".setup-item-inputstring input" ) . val ( ) ;
break ;
2021-03-16 23:29:26 +00:00
case "password" :
itemEntry . value = $el . find ( ".setup-item-password input" ) . val ( ) ;
break ;
2017-06-29 05:53:25 +00:00
case "inputbool" :
itemEntry . value = $el . find ( ".setup-item-inputbool input" ) . is ( ":checked" ) ;
break ;
2020-02-19 20:23:55 +00:00
case "inputcheckbox" :
itemEntry . values = [ ] ;
$el . find ( ".setup-item-inputcheckbox input:checked" ) . each ( function ( ) {
2021-04-25 01:19:13 +00:00
itemEntry . values . push ( $ ( this ) . val ( ) ) ;
2020-02-19 20:23:55 +00:00
} ) ;
2021-05-08 20:24:18 +00:00
break ;
2017-06-29 05:53:25 +00:00
case "inputselect" :
itemEntry . value = $el . find ( ".setup-item-inputselect select" ) . val ( ) ;
break ;
2021-05-08 20:24:18 +00:00
case "inputtags" :
itemEntry . value = $el . find ( ".setup-item-inputtags input" ) . val ( ) ;
break ;
2017-06-29 05:53:25 +00:00
}
configJson . push ( itemEntry )
} ) ;
return configJson ;
}
2017-10-01 09:28:10 +00:00
function populateSetupForm ( indexerId , name , config , caps , link , alternativesitelinks , description ) {
var configForm = newConfigModal ( name , config , caps , link , alternativesitelinks , description ) ;
2017-06-29 05:53:25 +00:00
var $goButton = configForm . find ( ".setup-indexer-go" ) ;
$goButton . click ( function ( ) {
2017-08-08 15:02:16 +00:00
var data = getConfigModalJson ( configForm ) ;
2017-06-29 05:53:25 +00:00
var originalBtnText = $goButton . html ( ) ;
$goButton . prop ( 'disabled' , true ) ;
$goButton . html ( $ ( '#spinner' ) . html ( ) ) ;
2017-08-08 15:02:16 +00:00
api . updateIndexerConfig ( indexerId , data , function ( data ) {
if ( data == undefined ) {
configForm . modal ( "hide" ) ;
reloadIndexers ( ) ;
doNotify ( "Successfully configured " + name , "success" , "glyphicon glyphicon-ok" ) ;
} else if ( data . result == "error" ) {
2017-06-29 05:53:25 +00:00
if ( data . config ) {
populateConfigItems ( configForm , data . config ) ;
}
doNotify ( "Configuration failed: " + data . error , "danger" , "glyphicon glyphicon-alert" ) ;
}
2017-08-20 11:11:46 +00:00
} ) . fail ( function ( data ) {
2022-04-17 10:26:27 +00:00
doErrorNotify ( indexerId , data . responseJSON . error , "updating" ) ;
2017-06-29 05:53:25 +00:00
} ) . always ( function ( ) {
$goButton . html ( originalBtnText ) ;
$goButton . prop ( 'disabled' , false ) ;
} ) ;
} ) ;
configForm . on ( 'hidden.bs.modal' , function ( e ) {
$ ( '#indexers div.dataTables_filter input' ) . focusWithoutScrolling ( ) ;
2021-04-25 01:19:13 +00:00
} ) ;
2017-06-29 05:53:25 +00:00
configForm . modal ( "show" ) ;
}
2022-01-26 20:05:26 +00:00
function resolveUrl ( baseUrl , url ) {
if ( baseUrl != '' ) {
url = baseUrl + url ;
} else {
var a = document . createElement ( 'a' ) ;
a . href = url ;
url = a . href ;
}
2017-06-29 05:53:25 +00:00
return url ;
}
2022-04-17 10:26:27 +00:00
function doErrorNotify ( indexerId , errorMessage , errorEvent ) {
if ( errorMessage !== undefined ) {
var githubRepo = "Jackett/Jackett" ;
var githubText = "this indexer" ;
var githubTemplate = "?template=bug_report.yml&"
if ( errorMessage . includes ( "FlareSolverr" ) ) {
githubRepo = "FlareSolverr/FlareSolverr" ;
2022-12-21 02:19:52 +00:00
githubText = "FlareSolverr"
2022-04-17 10:26:27 +00:00
}
var githubUrl = "https://github.com/" + githubRepo + "/issues/new" + githubTemplate + "title=[" + indexerId + "] (" + errorEvent + ")" ;
var indexEnd = 2000 - githubUrl . length ; // keep url <= 2k #5104
var htmlEscapedError = $ ( "<div>" ) . text ( errorMessage . substring ( 0 , indexEnd ) ) . html ( ) ;
var urlEscapedError = encodeURIComponent ( errorMessage . substring ( 0 , indexEnd ) ) ;
2022-04-24 18:58:51 +00:00
var link = "<i><a href=\"" + githubUrl + " " + urlEscapedError + "\" target=\"_blank\">Click here to open an issue on GitHub for " + githubText + ".</a><i>" ;
if ( errorMessage . includes ( "FlareSolverr is not configured" ) ) {
link = "<i><a href=\"https://github.com/Jackett/Jackett#configuring-flaresolverr\" target=\"_blank\">Instructions to install and configure FlareSolverr.</a><i><br />" +
2022-06-06 00:09:51 +00:00
"<i><a href=\"https://github.com/Jackett/Jackett/wiki/Troubleshooting#error-connecting-to-flaresolverr-server\" target=\"_blank\">Troubleshooting frequent errors with FlareSolverr.</a><i>" ;
2022-04-24 18:58:51 +00:00
}
doNotify ( "An error occurred while " + errorEvent + " this indexer<br /><b>" + htmlEscapedError + "</b><br />" + link ,
2022-04-17 10:26:27 +00:00
"danger" , "glyphicon glyphicon-alert" , false ) ;
} else {
doNotify ( "An error occurred while " + errorEvent + " indexers, please take a look at indexers with failed test for more information." ,
"danger" , "glyphicon glyphicon-alert" ) ;
}
}
2017-06-29 05:53:25 +00:00
function doNotify ( message , type , icon , autoHide ) {
if ( typeof autoHide === "undefined" || autoHide === null )
autoHide = true ;
var delay = 5000 ;
if ( ! autoHide )
delay = - 1 ;
$ . notify ( {
message : message ,
icon : icon
} , {
element : 'body' ,
autoHide : autoHide ,
delay : delay ,
type : type ,
allow _dismiss : true ,
z _index : 9000 ,
mouse _over : 'pause' ,
placement : {
from : "bottom" ,
align : "center"
}
} ) ;
}
function clearNotifications ( ) {
$ ( '[data-notify="container"]' ) . remove ( ) ;
}
2021-04-25 01:19:13 +00:00
function updateReleasesRow ( row ) {
2017-06-29 05:53:25 +00:00
var labels = $ ( row ) . find ( "span.release-labels" ) ;
var TitleLink = $ ( row ) . find ( "td.Title > a" ) ;
var IMDBId = $ ( row ) . data ( "imdb" ) ;
2022-04-24 19:28:25 +00:00
var TMDBId = $ ( row ) . data ( "tmdb" ) ;
2022-04-25 02:23:36 +00:00
var TVDBId = $ ( row ) . data ( "tvdb" ) ;
2022-07-21 16:43:56 +00:00
var TVMazeId = $ ( row ) . data ( "tvmaze" ) ;
2022-07-21 05:34:54 +00:00
var TraktId = $ ( row ) . data ( "trakt" ) ;
2022-05-11 22:58:40 +00:00
var DoubanId = $ ( row ) . data ( "douban" ) ;
2020-11-07 23:43:33 +00:00
var Poster = $ ( row ) . data ( "poster" ) ;
2017-06-29 05:53:25 +00:00
var Description = $ ( row ) . data ( "description" ) ;
var DownloadVolumeFactor = parseFloat ( $ ( row ) . find ( "td.DownloadVolumeFactor" ) . html ( ) ) ;
var UploadVolumeFactor = parseFloat ( $ ( row ) . find ( "td.UploadVolumeFactor" ) . html ( ) ) ;
2022-04-26 05:55:23 +00:00
var Cat = $ ( row ) . find ( "td.Cat" ) . html ( ) ;
2017-06-29 05:53:25 +00:00
var TitleTooltip = "" ;
2020-11-07 23:43:33 +00:00
if ( Poster )
TitleTooltip += "<img src='" + Poster + "' /><br />" ;
2017-06-29 05:53:25 +00:00
if ( Description )
TitleTooltip += Description ;
if ( TitleTooltip ) {
TitleLink . data ( "toggle" , "tooltip" ) ;
TitleLink . tooltip ( {
title : TitleTooltip ,
2022-01-23 21:25:16 +00:00
html : true ,
placement : "auto"
2017-06-29 05:53:25 +00:00
} ) ;
}
labels . empty ( ) ;
2022-04-24 19:28:25 +00:00
if ( IMDBId ) {
var imdbLen = ( IMDBId . toString ( ) . length > 7 ) ? 8 : 7 ;
2021-10-31 11:49:24 +00:00
labels . append ( '\n<a href="https://www.imdb.com/title/tt' + ( "00000000" + IMDBId ) . slice ( - imdbLen ) + '/" target="_blank" class="label label-imdb" alt="IMDB" title="IMDB">IMDB</a>' ) ;
2017-06-29 05:53:25 +00:00
}
2022-04-24 19:28:25 +00:00
if ( TMDBId && TMDBId > 0 ) {
2022-04-26 05:55:23 +00:00
var TMdbType = ( Cat . includes ( "Movies" ) ) ? "movie" : "tv" ;
labels . append ( '\n<a href="https://www.themoviedb.org/' + TMdbType + '/' + TMDBId + '" target="_blank" class="label label-tmdb" alt="TMDB" title="TMDB">TMDB</a>' ) ;
2022-04-24 19:28:25 +00:00
}
2022-04-25 02:23:36 +00:00
if ( TVDBId && TVDBId > 0 ) {
labels . append ( '\n<a href="https://thetvdb.com/?tab=series&id=' + TVDBId + '" target="_blank" class="label label-tvdb" alt="TVDB" title="TVDB">TVDB</a>' ) ;
}
2022-07-21 16:43:56 +00:00
if ( TVMazeId && TVMazeId > 0 ) {
labels . append ( '\n<a href="https://tvmaze.com/shows/' + TVMazeId + '" target="_blank" class="label label-tvmaze" alt="TVMaze" title="TVMaze">TVMaze</a>' ) ;
}
2022-07-21 05:34:54 +00:00
if ( TraktId && TraktId > 0 ) {
var TraktType = ( Cat . includes ( "Movies" ) ) ? "movies" : "shows" ;
labels . append ( '\n<a href="https://www.trakt.tv/' + TraktType + '/' + TraktId + '" target="_blank" class="label label-trakt" alt="Trakt" title="Trakt">Trakt</a>' ) ;
}
2022-05-11 22:58:40 +00:00
if ( DoubanId && DoubanId > 0 ) {
labels . append ( '\n<a href="https://movie.douban.com/subject/' + DoubanId + '" target="_blank" class="label label-douban" alt="Douban" title="Douban">Douban</a>' ) ;
}
2017-06-29 05:53:25 +00:00
if ( ! isNaN ( DownloadVolumeFactor ) ) {
if ( DownloadVolumeFactor == 0 ) {
labels . append ( '\n<span class="label label-success">FREELEECH</span>' ) ;
} else if ( DownloadVolumeFactor < 1 ) {
2018-07-30 11:02:09 +00:00
labels . append ( '\n<span class="label label-primary">' + ( DownloadVolumeFactor * 100 ) . toFixed ( 0 ) + '%DL</span>' ) ;
2017-06-29 05:53:25 +00:00
} else if ( DownloadVolumeFactor > 1 ) {
2018-07-30 11:02:09 +00:00
labels . append ( '\n<span class="label label-danger">' + ( DownloadVolumeFactor * 100 ) . toFixed ( 0 ) + '%DL</span>' ) ;
2017-06-29 05:53:25 +00:00
}
}
if ( ! isNaN ( UploadVolumeFactor ) ) {
if ( UploadVolumeFactor == 0 ) {
labels . append ( '\n<span class="label label-warning">NO UPLOAD</span>' ) ;
} else if ( UploadVolumeFactor != 1 ) {
2018-07-30 11:02:09 +00:00
labels . append ( '\n<span class="label label-info">' + ( UploadVolumeFactor * 100 ) . toFixed ( 0 ) + '%UL</span>' ) ;
2017-06-29 05:53:25 +00:00
}
}
}
2021-05-08 20:24:18 +00:00
function showSearch ( selectedFilter , selectedIndexer , query , category ) {
2020-02-23 03:30:57 +00:00
var selectedIndexers = [ ] ;
2017-08-30 15:40:32 +00:00
if ( selectedIndexer )
2021-05-08 20:24:18 +00:00
selectedIndexers = selectedIndexer . split ( "," ) ;
2017-06-29 05:53:25 +00:00
var releaseTemplate = Handlebars . compile ( $ ( "#jackett-search" ) . html ( ) ) ;
var releaseDialog = $ ( releaseTemplate ( {
2021-05-08 20:24:18 +00:00
filters : availableFilters ,
active : selectedFilter
2017-06-29 05:53:25 +00:00
} ) ) ;
2023-05-27 16:41:35 +00:00
$ ( "#modals" ) . html ( releaseDialog ) ;
2017-06-29 05:53:25 +00:00
releaseDialog . on ( 'shown.bs.modal' , function ( ) {
releaseDialog . find ( '#searchquery' ) . focusWithoutScrolling ( ) ;
} ) ;
releaseDialog . on ( 'hidden.bs.modal' , function ( e ) {
$ ( '#indexers div.dataTables_filter input' ) . focusWithoutScrolling ( ) ;
2021-05-13 21:41:11 +00:00
window . location . hash = currentFilter ? "indexers&filter=" + currentFilter : '' ;
2024-02-24 01:50:45 +00:00
document . title = "Jackett" ;
2021-04-25 01:19:13 +00:00
} ) ;
2017-06-29 05:53:25 +00:00
2021-05-08 20:24:18 +00:00
var setTrackers = function ( filterId , trackers ) {
var select = $ ( '#searchTracker' ) ;
var selected = select . val ( ) ;
var filter = availableFilters . find ( f => f . id == filterId ) ;
if ( filter )
trackers = trackers . filter ( filter . apply , filter ) ;
var options = trackers . map ( t => {
return {
label : t . name ,
value : t . id
}
} ) ;
select . multiselect ( 'dataprovider' , options ) ;
select . val ( selected ) . multiselect ( "refresh" ) ;
} ;
$ ( '#searchFilter' ) . change ( jQuery . proxy ( function ( ) {
var filterId = $ ( '#searchFilter' ) . val ( ) ;
setTrackers ( filterId , this . items ) ;
} , {
items : configuredIndexers
} ) ) ;
2017-08-30 15:40:32 +00:00
var setCategories = function ( trackers , items ) {
2017-06-29 05:53:25 +00:00
var cats = { } ;
for ( var i = 0 ; i < items . length ; i ++ ) {
2017-08-30 15:40:32 +00:00
if ( trackers . length == 0 || $ . inArray ( items [ i ] . id , trackers ) !== - 1 ) {
for ( var j in items [ i ] . caps ) {
var cat = items [ i ] . caps [ j ]
if ( cat . ID < 100000 || trackers . length == 1 )
cats [ cat . ID ] = cat . Name ;
2017-06-29 05:53:25 +00:00
}
}
}
var select = $ ( '#searchCategory' ) ;
2017-08-30 15:40:32 +00:00
var selected = select . val ( ) ;
var options = [ ]
$ . each ( cats , function ( ID , Name ) {
2021-04-25 01:19:13 +00:00
options . push ( {
label : ID + ' (' + Name + ')' ,
value : ID
} ) ;
2017-06-29 05:53:25 +00:00
} ) ;
2017-08-30 15:40:32 +00:00
select . multiselect ( 'dataprovider' , options ) ;
select . val ( selected ) . multiselect ( "refresh" ) ;
2017-06-29 05:53:25 +00:00
} ;
$ ( '#searchTracker' ) . change ( jQuery . proxy ( function ( ) {
2017-08-30 15:40:32 +00:00
var trackerIds = $ ( '#searchTracker' ) . val ( ) ;
setCategories ( trackerIds , this . items ) ;
2021-04-25 01:19:13 +00:00
} , {
items : configuredIndexers
} ) ) ;
2017-06-29 05:53:25 +00:00
2017-07-23 00:08:19 +00:00
var queryField = document . getElementById ( "searchquery" ) ;
queryField . addEventListener ( "keyup" , function ( event ) {
2017-06-29 05:53:25 +00:00
event . preventDefault ( ) ;
if ( event . keyCode == 13 ) {
document . getElementById ( "jackett-search-perform" ) . click ( ) ;
}
} ) ;
2017-07-23 00:08:19 +00:00
var searchButton = $ ( '#jackett-search-perform' ) ;
searchButton . click ( function ( ) {
2017-06-29 05:53:25 +00:00
if ( $ ( '#jackett-search-perform span' ) . hasClass ( "spinner" ) ) {
// We are searchin already
return ;
}
2017-08-08 15:02:16 +00:00
var searchString = releaseDialog . find ( '#searchquery' ) . val ( ) ;
2021-05-08 20:24:18 +00:00
var filterId = releaseDialog . find ( '#searchFilter' ) . val ( ) ;
2017-06-29 05:53:25 +00:00
var queryObj = {
2017-08-08 15:02:16 +00:00
Query : searchString ,
2017-06-29 05:53:25 +00:00
Category : releaseDialog . find ( '#searchCategory' ) . val ( ) ,
2017-08-30 15:40:32 +00:00
Tracker : releaseDialog . find ( '#searchTracker' ) . val ( )
2017-06-29 05:53:25 +00:00
} ;
2020-02-23 03:30:57 +00:00
window . location . hash = Object . entries ( {
2021-04-25 01:19:13 +00:00
search : encodeURIComponent ( queryObj . Query ) . replace ( /%20/g , '+' ) ,
tracker : queryObj . Tracker . join ( "," ) ,
2021-05-08 20:24:18 +00:00
category : queryObj . Category . join ( "," ) ,
filter : filterId ? encodeURIComponent ( filterId ) : ""
} ) . filter ( ( [ k , v ] ) => v ) . map ( ( [ k , v ] , i ) => k + '=' + v ) . join ( '&' ) ;
2017-08-08 15:02:16 +00:00
2017-06-29 05:53:25 +00:00
$ ( '#jackett-search-perform' ) . html ( $ ( '#spinner' ) . html ( ) ) ;
$ ( '#searchResults div.dataTables_filter input' ) . val ( "" ) ;
clearSearchResultTable ( $ ( '#searchResults' ) ) ;
2017-08-08 15:02:16 +00:00
2024-02-24 01:50:45 +00:00
document . title = "(...) " + searchString ;
2021-05-08 20:24:18 +00:00
var trackerId = filterId || "all" ;
2017-08-08 15:02:16 +00:00
api . resultsForIndexer ( trackerId , queryObj , function ( data ) {
2017-06-29 05:53:25 +00:00
$ ( '#jackett-search-perform' ) . html ( $ ( '#search-button-ready' ) . html ( ) ) ;
var searchResults = $ ( '#searchResults' ) ;
searchResults . empty ( ) ;
2020-04-05 21:12:15 +00:00
updateSearchResultTable ( searchResults , data ) . search ( '' ) . columns ( ) . search ( '' ) . draw ( ) ;
2017-06-29 05:53:25 +00:00
searchResults . find ( 'div.dataTables_filter input' ) . focusWithoutScrolling ( ) ;
2024-02-24 01:50:45 +00:00
document . title = "(" + data . Results . length + ") " + searchString ;
2017-06-29 05:53:25 +00:00
} ) . fail ( function ( ) {
$ ( '#jackett-search-perform' ) . html ( $ ( '#search-button-ready' ) . html ( ) ) ;
doNotify ( "Request to Jackett server failed" , "danger" , "glyphicon glyphicon-alert" ) ;
2024-02-24 01:50:45 +00:00
document . title = "(err) " + searchString ;
2017-06-29 05:53:25 +00:00
} ) ;
} ) ;
var searchTracker = releaseDialog . find ( "#searchTracker" ) ;
2020-04-05 21:12:15 +00:00
var searchCategory = releaseDialog . find ( '#searchCategory' ) ;
2021-05-08 20:24:18 +00:00
var searchFilter = releaseDialog . find ( '#searchFilter' ) ;
2021-10-20 11:16:18 +00:00
2021-05-08 20:24:18 +00:00
searchFilter . multiselect ( {
2017-08-30 15:40:32 +00:00
maxHeight : 400 ,
enableFiltering : true ,
enableCaseInsensitiveFiltering : true ,
2021-05-08 20:24:18 +00:00
nonSelectedText : 'All'
2017-08-30 15:40:32 +00:00
} ) ;
2017-06-29 05:53:25 +00:00
updateSearchResultTable ( $ ( '#searchResults' ) , [ ] ) ;
clearSearchResultTable ( $ ( '#searchResults' ) ) ;
2017-08-30 15:40:32 +00:00
searchTracker . multiselect ( {
maxHeight : 400 ,
enableFiltering : true ,
includeSelectAllOption : true ,
enableCaseInsensitiveFiltering : true ,
nonSelectedText : 'All'
} ) ;
2020-02-19 20:23:55 +00:00
2021-05-08 20:24:18 +00:00
searchCategory . multiselect ( {
maxHeight : 400 ,
enableFiltering : true ,
includeSelectAllOption : true ,
enableCaseInsensitiveFiltering : true ,
nonSelectedText : 'Any'
} ) ;
if ( availableFilters . length > 0 ) {
if ( selectedFilter ) {
searchFilter . val ( selectedFilter ) ;
searchFilter . multiselect ( "refresh" ) ;
}
searchFilter . trigger ( "change" ) ;
}
else
setTrackers ( selectedFilter , configuredIndexers ) ;
if ( selectedIndexers ) {
searchTracker . val ( selectedIndexers ) ;
searchTracker . multiselect ( "refresh" ) ;
}
searchTracker . trigger ( "change" ) ;
2017-07-23 00:08:19 +00:00
2017-08-28 16:54:57 +00:00
if ( category !== undefined ) {
2017-08-30 15:40:32 +00:00
searchCategory . val ( category . split ( "," ) ) ;
searchCategory . multiselect ( "refresh" ) ;
2017-08-28 16:54:57 +00:00
}
2017-08-30 15:40:32 +00:00
releaseDialog . modal ( "show" ) ;
2017-07-23 00:08:19 +00:00
if ( query !== undefined ) {
2017-08-28 16:54:57 +00:00
queryField . value = query ;
2017-07-23 00:08:19 +00:00
searchButton . click ( ) ;
}
2017-06-29 05:53:25 +00:00
}
function clearSearchResultTable ( element ) {
element . find ( "#jackett-search-results-datatable > tbody" ) . empty ( ) ;
element . find ( "#jackett-search-results-datatable > tfoot" ) . empty ( ) ;
element . find ( "#jackett-search-results-datatable_info" ) . empty ( ) ;
element . find ( "#jackett-search-results-datatable_paginate" ) . empty ( ) ;
}
2022-10-03 19:36:39 +00:00
function getSavedPresets ( ) {
var lsKey = "jackett_saved_presets" ;
if ( JSON !== undefined && localStorage !== undefined ) {
var lsSavedPresets = localStorage . getItem ( lsKey ) ;
var presets = lsSavedPresets !== null ? JSON . parse ( lsSavedPresets ) : [ ] ;
return presets ;
} else {
return [ ] ;
}
}
function setSavedPresets ( presets ) {
var lsKey = "jackett_saved_presets" ;
if ( JSON !== undefined && localStorage !== undefined ) {
localStorage . setItem ( lsKey , JSON . stringify ( presets ) ) ;
}
}
function setSavePresetsButtonState ( table , element , state = false ) {
2023-01-07 18:19:02 +00:00
var button = element . find ( "button[id=jackett-search-results-datatable_savepreset_button]" )
2022-10-03 19:36:39 +00:00
if ( state ) {
button . attr ( "class" , "btn btn-danger btn-sm" ) ;
button . on ( "click" , function ( ) {
var inputSearch = element . find ( "input[type=search]" ) ;
var preset = inputSearch . val ( ) . trim ( ) ;
if ( preset !== "" ) {
var presets = getSavedPresets ( ) ;
if ( presets . includes ( preset ) ) {
presets = presets . filter ( item => item != preset ) ;
setSavedPresets ( presets ) ;
var datalist = element . find ( "datalist[id=jackett-search-saved-presets]" )
datalist . empty ( ) ;
table . api ( ) . draw ( ) ;
}
}
} ) ;
} else {
button . attr ( "class" , "btn btn-success btn-sm" ) ;
button . on ( "click" , function ( ) {
var inputSearch = element . find ( "input[type=search]" ) ;
var preset = inputSearch . val ( ) . trim ( ) ;
if ( preset !== "" ) {
var presets = getSavedPresets ( ) ;
if ( ! presets . includes ( preset ) ) {
presets . push ( preset ) ;
setSavedPresets ( presets ) ;
table . api ( ) . draw ( ) ;
}
}
} ) ;
}
}
2017-06-29 05:53:25 +00:00
// dataTable dead torrent filter
$ . fn . dataTable . ext . search = [
function ( settings , data , dataIndex ) {
if ( settings . sInstance != "jackett-search-results-datatable" )
return true ;
2020-04-05 21:12:15 +00:00
var deadfiltercheckbox = $ ( settings . nTableWrapper ) . find ( ".dataTables_deadfilter input" ) ;
2017-06-29 05:53:25 +00:00
if ( ! deadfiltercheckbox . length ) {
return true ;
}
var seeders = data [ 9 ] ;
if ( ! deadfiltercheckbox . get ( 0 ) . checked && seeders == 0 )
return false ;
return true ;
}
2020-04-05 21:12:15 +00:00
] ;
2017-06-29 05:53:25 +00:00
function updateSearchResultTable ( element , results ) {
2023-04-18 22:22:24 +00:00
var resultsTemplate = Handlebars . compile ( $ ( "#jackett-search-results" ) . text ( ) ) ;
2017-06-29 05:53:25 +00:00
element . html ( $ ( resultsTemplate ( results ) ) ) ;
2021-04-25 01:19:13 +00:00
element . find ( 'tr.jackett-search-results-row' ) . each ( function ( ) {
updateReleasesRow ( this ) ;
} ) ;
var settings = {
"deadfilter" : true
} ;
var datatable = element . find ( 'table' ) . DataTable ( {
"fnStateSaveParams" : function ( oSettings , sValue ) {
sValue . search . search = "" ; // don't save the search filter content
sValue . deadfilter = settings . deadfilter ;
return sValue ;
} ,
"fnStateLoadParams" : function ( oSettings , sValue ) {
if ( "deadfilter" in sValue )
settings . deadfilter = sValue . deadfilter ;
} ,
"dom" : "lfr<\"dataTables_deadfilter\">tip" ,
"stateSave" : true ,
"stateDuration" : 0 ,
"bAutoWidth" : false ,
"pageLength" : 20 ,
"lengthMenu" : [
[ 10 , 20 , 50 , 100 , 250 , 500 , - 1 ] ,
[ 10 , 20 , 50 , 100 , 250 , 500 , "All" ]
] ,
"order" : [
[ 0 , "desc" ]
] ,
"columnDefs" : [ {
"targets" : 0 ,
"visible" : false ,
"searchable" : false ,
"type" : 'date'
2017-06-29 05:53:25 +00:00
} ,
2021-04-25 01:19:13 +00:00
{
"targets" : 1 ,
"visible" : true ,
"searchable" : false ,
"iDataSort" : 0
2017-06-29 05:53:25 +00:00
} ,
2021-04-25 01:19:13 +00:00
{
"targets" : 4 ,
"visible" : false ,
"searchable" : false ,
"type" : 'num'
} ,
{
"targets" : 5 ,
"visible" : true ,
"searchable" : false ,
"iDataSort" : 4
}
] ,
fnPreDrawCallback : function ( ) {
var table = this ;
2022-10-03 19:36:39 +00:00
var datalist = element . find ( "datalist[id=jackett-search-saved-presets]" )
var presets = getSavedPresets ( ) ;
if ( presets . length > 0 ) {
datalist . empty ( ) ;
presets . forEach ( preset => {
var option = $ ( '<option></option>' ) ;
option . attr ( "value" , preset ) ;
datalist . append ( option ) ;
} )
}
2021-04-25 01:19:13 +00:00
var inputSearch = element . find ( "input[type=search]" ) ;
2022-10-03 19:36:39 +00:00
setSavePresetsButtonState ( table , element , presets . includes ( inputSearch . val ( ) . trim ( ) ) ) ;
2021-04-25 01:19:13 +00:00
if ( ! inputSearch . attr ( "custom" ) ) {
var newInputSearch = inputSearch . clone ( ) ;
newInputSearch . attr ( "custom" , "true" ) ;
newInputSearch . attr ( "data-toggle" , "tooltip" ) ;
2022-10-02 17:05:22 +00:00
newInputSearch . attr ( "title" , "Search query consists of several keywords.\nKeyword starting with \"-\" is considered a negative match.\nKeywords separated by \"|\" are considered as OR filters." ) ;
2022-10-03 19:36:39 +00:00
newInputSearch . attr ( "list" , "jackett-search-saved-presets" ) ;
2021-04-25 01:19:13 +00:00
newInputSearch . on ( "input" , function ( ) {
2020-04-05 21:12:15 +00:00
var newKeywords = [ ] ;
2022-10-03 19:36:39 +00:00
var filterText = $ ( this ) . val ( ) . trim ( ) ;
var presets = getSavedPresets ( ) ;
setSavePresetsButtonState ( table , element , presets . includes ( filterText ) ) ;
var filterTextKeywords = filterText . split ( " " ) ;
2021-04-25 01:19:13 +00:00
$ . each ( filterTextKeywords , function ( index , keyword ) {
if ( keyword === "" || keyword === "+" || keyword === "-" )
return ;
var newKeyword ;
if ( keyword . startsWith ( "+" ) )
newKeyword = $ . fn . dataTable . util . escapeRegex ( keyword . substring ( 1 ) ) ;
else if ( keyword . startsWith ( "-" ) )
newKeyword = "^((?!" + $ . fn . dataTable . util . escapeRegex ( keyword . substring ( 1 ) ) + ").)*$" ;
else
2022-10-02 17:05:22 +00:00
newKeyword = '(' + keyword . split ( '|' ) . map ( k => $ . fn . dataTable . util . escapeRegex ( k ) ) . join ( '|' ) + ')' ;
2023-01-07 18:19:02 +00:00
// fix search filters with "-", "." or "_" characters in the middle of the word => #13628
newKeyword = newKeyword . replace ( "\\-" , "\\-\u200B?" ) . replace ( "\\." , "\\.\u200B?" ) . replace ( "_" , "_\u200B?" ) ;
2021-04-25 01:19:13 +00:00
newKeywords . push ( newKeyword ) ;
2020-04-05 21:12:15 +00:00
} ) ;
var filterText = newKeywords . join ( " " ) ;
table . api ( ) . search ( filterText , true , true ) . draw ( ) ;
2021-04-25 01:19:13 +00:00
} ) ;
inputSearch . replaceWith ( newInputSearch ) ;
}
2017-06-29 05:53:25 +00:00
2021-04-25 01:19:13 +00:00
var deadfilterdiv = element . find ( ".dataTables_deadfilter" ) ;
var deadfiltercheckbox = deadfilterdiv . find ( "input" ) ;
if ( ! deadfiltercheckbox . length ) {
deadfilterlabel = $ ( '<label><input type="checkbox" id="jackett-search-results-datatable_deadfilter_checkbox" value="1"> Show dead torrents</label>' ) ;
deadfilterdiv . append ( deadfilterlabel ) ;
deadfiltercheckbox = deadfilterlabel . find ( "input" ) ;
deadfiltercheckbox . on ( "change" , function ( ) {
settings . deadfilter = this . checked ;
table . api ( ) . draw ( ) ;
2017-06-29 05:53:25 +00:00
} ) ;
2021-04-25 01:19:13 +00:00
deadfiltercheckbox . prop ( 'checked' , settings . deadfilter ) ;
2022-10-03 19:36:39 +00:00
savepresetlabel = $ ( '<button id="jackett-search-results-datatable_savepreset_button" title="Save Search Preset" class="btn btn-success btn-sm" style="margin-left: 10px;"><span class="fa fa-save"></span></button>' ) ;
var searchfilterdiv = element . find ( "#jackett-search-results-datatable_filter" ) ;
searchfilterdiv . append ( savepresetlabel ) ;
2017-06-29 05:53:25 +00:00
}
2021-04-25 01:19:13 +00:00
} ,
initComplete : function ( ) {
var count = 0 ;
this . api ( ) . columns ( ) . every ( function ( ) {
count ++ ;
if ( count === 3 || count === 8 ) {
var column = this ;
var select = $ ( '<select><option value=""></option></select>' )
. appendTo ( $ ( column . footer ( ) ) . empty ( ) )
. on ( 'change' , function ( ) {
var val = $ . fn . dataTable . util . escapeRegex (
$ ( this ) . val ( )
) ;
column
. search ( val ? '^' + val + '$' : '' , true , false )
. draw ( ) ;
} ) ;
column . data ( ) . unique ( ) . sort ( ) . each ( function ( d , j ) {
select . append ( '<option value="' + d + '">' + d + '</option>' )
} ) ;
}
} ) ;
}
} ) ;
2017-06-29 05:53:25 +00:00
return datatable ;
}
function bindUIButtons ( ) {
$ ( 'body' ) . on ( 'click' , '.downloadlink' , function ( e , b ) {
$ ( e . target ) . addClass ( 'jackettdownloaded' ) ;
} ) ;
$ ( 'body' ) . on ( 'click' , '.jacketdownloadserver' , function ( event ) {
var href = $ ( event . target ) . parent ( ) . attr ( 'href' ) ;
var jqxhr = $ . get ( href , function ( data ) {
if ( data . result == "error" ) {
doNotify ( "Error: " + data . error , "danger" , "glyphicon glyphicon-alert" ) ;
return ;
} else {
doNotify ( "Downloaded sent to the blackhole successfully." , "success" , "glyphicon glyphicon-ok" ) ;
}
} ) . fail ( function ( ) {
doNotify ( "Request to Jackett server failed" , "danger" , "glyphicon glyphicon-alert" ) ;
} ) ;
event . preventDefault ( ) ;
return false ;
} ) ;
2022-01-26 20:03:00 +00:00
$ ( '#api-key-copy-button' ) . click ( function ( ) {
var apiKey = api . key ;
if ( apiKey !== null || apiKey !== undefined ) {
copyToClipboard ( apiKey ) ;
}
} ) ;
2017-06-29 05:53:25 +00:00
$ ( '#jackett-add-indexer' ) . click ( function ( ) {
$ ( "#modals" ) . empty ( ) ;
displayUnconfiguredIndexersList ( ) ;
2021-05-17 01:13:35 +00:00
addCheckOnCellClick ( ) ;
2021-04-24 06:45:33 +00:00
$ ( '#unconfigured-indexer-datatable tfoot tr' ) . insertAfter ( $ ( '#unconfigured-indexer-datatable thead tr' ) ) ;
2021-04-25 01:19:13 +00:00
$ ( '#unconfigured-indexer-datatable' ) . DataTable ( ) . search ( '' ) . columns ( ) . search ( '' ) . draw ( ) ;
2017-06-29 05:53:25 +00:00
} ) ;
$ ( "#jackett-test-all" ) . click ( function ( ) {
$ ( ".indexer-button-test" ) . each ( function ( i , btn ) {
var $btn = $ ( btn ) ;
var id = $btn . data ( "id" ) ;
testIndexer ( id , false ) ;
} ) ;
} ) ;
$ ( "#jackett-show-releases" ) . click ( function ( ) {
2017-08-08 15:02:16 +00:00
api . getServerCache ( function ( data ) {
2017-06-29 05:53:25 +00:00
var releaseTemplate = Handlebars . compile ( $ ( "#jackett-releases" ) . html ( ) ) ;
2021-04-25 01:19:13 +00:00
var item = {
releases : data ,
Title : 'Releases'
} ;
2017-06-29 05:53:25 +00:00
var releaseDialog = $ ( releaseTemplate ( item ) ) ;
var table = releaseDialog . find ( 'table' ) ;
2021-04-25 01:19:13 +00:00
releaseDialog . find ( 'tr.jackett-releases-row' ) . each ( function ( ) {
updateReleasesRow ( this ) ;
} ) ;
2017-06-29 05:53:25 +00:00
releaseDialog . on ( 'hidden.bs.modal' , function ( e ) {
$ ( '#indexers div.dataTables_filter input' ) . focusWithoutScrolling ( ) ;
} ) ;
2017-08-08 15:02:16 +00:00
2021-04-25 01:19:13 +00:00
table . DataTable ( {
"stateSave" : true ,
"stateDuration" : 0 ,
"bAutoWidth" : false ,
"pageLength" : 20 ,
"lengthMenu" : [
[ 10 , 20 , 50 , - 1 ] ,
[ 10 , 20 , 50 , "All" ]
] ,
"order" : [
[ 0 , "desc" ]
] ,
"columnDefs" : [ {
"targets" : 0 ,
"visible" : false ,
"searchable" : false ,
"type" : 'date'
} ,
{
"targets" : 1 ,
"visible" : false ,
"searchable" : false ,
"type" : 'date'
} ,
{
"targets" : 2 ,
"visible" : true ,
"searchable" : false ,
"iDataSort" : 0
} ,
{
"targets" : 3 ,
"visible" : true ,
"searchable" : false ,
"iDataSort" : 1
} ,
{
"targets" : 6 ,
"visible" : false ,
"searchable" : false ,
"type" : 'num'
} ,
{
"targets" : 7 ,
"visible" : true ,
"searchable" : false ,
"iDataSort" : 6
}
] ,
initComplete : function ( ) {
var count = 0 ;
this . api ( ) . columns ( ) . every ( function ( ) {
count ++ ;
if ( count === 5 || count === 10 ) {
var column = this ;
var select = $ ( '<select><option value=""></option></select>' )
. appendTo ( $ ( column . footer ( ) ) . empty ( ) )
. on ( 'change' , function ( ) {
var val = $ . fn . dataTable . util . escapeRegex (
$ ( this ) . val ( )
) ;
column
. search ( val ? '^' + val + '$' : '' , true , false )
. draw ( ) ;
} ) ;
column . data ( ) . unique ( ) . sort ( ) . each ( function ( d , j ) {
select . append ( '<option value="' + d + '">' + d + '</option>' )
} ) ;
2017-06-29 05:53:25 +00:00
}
2021-04-25 01:19:13 +00:00
} ) ;
}
} ) ;
2023-05-27 16:41:35 +00:00
$ ( "#modals" ) . html ( releaseDialog ) ;
2017-06-29 05:53:25 +00:00
releaseDialog . modal ( "show" ) ;
} ) . fail ( function ( ) {
doNotify ( "Request to Jackett server failed" , "danger" , "glyphicon glyphicon-alert" ) ;
} ) ;
} ) ;
$ ( "#jackett-show-search" ) . click ( function ( ) {
2021-05-13 21:41:11 +00:00
showSearch ( currentFilter ) ;
window . location . hash = "search" + ( currentFilter ? "&filter=" + currentFilter : "" ) ;
2017-06-29 05:53:25 +00:00
} ) ;
$ ( "#view-jackett-logs" ) . click ( function ( ) {
2017-08-08 15:02:16 +00:00
api . getServerLogs ( function ( data ) {
2017-06-29 05:53:25 +00:00
var releaseTemplate = Handlebars . compile ( $ ( "#jackett-logs" ) . html ( ) ) ;
2021-04-25 01:19:13 +00:00
var item = {
logs : data
} ;
2017-06-29 05:53:25 +00:00
var releaseDialog = $ ( releaseTemplate ( item ) ) ;
2023-05-27 16:41:35 +00:00
$ ( "#modals" ) . html ( releaseDialog ) ;
2017-06-29 05:53:25 +00:00
releaseDialog . modal ( "show" ) ;
} ) . fail ( function ( ) {
doNotify ( "Request to Jackett server failed" , "danger" , "glyphicon glyphicon-alert" ) ;
} ) ;
} ) ;
$ ( "#change-jackett-port" ) . click ( function ( ) {
2017-08-08 15:02:16 +00:00
var jackett _port = Number ( $ ( "#jackett-port" ) . val ( ) ) ;
2017-06-29 05:53:25 +00:00
var jackett _basepathoverride = $ ( "#jackett-basepathoverride" ) . val ( ) ;
2022-01-26 20:05:26 +00:00
var jackett _baseurloverride = $ ( "#jackett-baseurloverride" ) . val ( ) ;
2017-06-29 05:53:25 +00:00
var jackett _external = $ ( "#jackett-allowext" ) . is ( ':checked' ) ;
2023-07-14 03:37:15 +00:00
var jackett _local _bind _address = $ ( "#jackett-local-bind-address" ) . val ( ) ;
2022-04-24 22:17:35 +00:00
var jackett _cors = $ ( "#jackett-allowcors" ) . is ( ':checked' ) ;
2020-02-19 20:23:55 +00:00
var jackett _update = $ ( "#jackett-allowupdate" ) . is ( ':checked' ) ;
var jackett _prerelease = $ ( "#jackett-prerelease" ) . is ( ':checked' ) ;
2017-06-29 05:53:25 +00:00
var jackett _logging = $ ( "#jackett-logging" ) . is ( ':checked' ) ;
2020-12-11 22:14:21 +00:00
var jackett _cache _enabled = $ ( "#jackett-cache-enabled" ) . is ( ':checked' ) ;
var jackett _cache _ttl = $ ( "#jackett-cache-ttl" ) . val ( ) ;
var jackett _cache _max _results _per _indexer = $ ( "#jackett-cache-max-results-per-indexer" ) . val ( ) ;
2020-12-13 20:42:10 +00:00
var jackett _flaresolverr _url = $ ( "#jackett-flaresolverrurl" ) . val ( ) ;
2022-01-09 18:38:14 +00:00
var jackett _flaresolverr _maxtimeout = $ ( "#jackett-flaresolverr-maxtimeout" ) . val ( ) ;
2017-06-29 05:53:25 +00:00
var jackett _omdb _key = $ ( "#jackett-omdbkey" ) . val ( ) ;
2018-07-09 10:37:24 +00:00
var jackett _omdb _url = $ ( "#jackett-omdburl" ) . val ( ) ;
2017-10-31 09:45:30 +00:00
var jackett _proxy _url = $ ( "#jackett-proxy-url" ) . val ( ) ;
2017-11-06 10:51:26 +00:00
var jackett _proxy _type = $ ( "#jackett-proxy-type" ) . val ( ) ;
2017-10-31 09:45:30 +00:00
var jackett _proxy _port = $ ( "#jackett-proxy-port" ) . val ( ) ;
var jackett _proxy _username = $ ( "#jackett-proxy-username" ) . val ( ) ;
var jackett _proxy _password = $ ( "#jackett-proxy-password" ) . val ( ) ;
2017-06-29 05:53:25 +00:00
var jsonObject = {
port : jackett _port ,
external : jackett _external ,
2023-07-14 03:37:15 +00:00
local _bind _address : jackett _local _bind _address ,
2022-04-24 22:17:35 +00:00
cors : jackett _cors ,
2017-06-29 05:53:25 +00:00
updatedisabled : jackett _update ,
prerelease : jackett _prerelease ,
blackholedir : $ ( "#jackett-savedir" ) . val ( ) ,
logging : jackett _logging ,
basepathoverride : jackett _basepathoverride ,
2022-01-26 20:05:26 +00:00
baseurloverride : jackett _baseurloverride ,
2020-12-11 22:14:21 +00:00
logging : jackett _logging ,
cache _enabled : jackett _cache _enabled ,
cache _ttl : jackett _cache _ttl ,
cache _max _results _per _indexer : jackett _cache _max _results _per _indexer ,
2020-12-13 20:42:10 +00:00
flaresolverrurl : jackett _flaresolverr _url ,
2022-01-09 18:38:14 +00:00
flaresolverr _maxtimeout : jackett _flaresolverr _maxtimeout ,
2017-10-31 09:45:30 +00:00
omdbkey : jackett _omdb _key ,
2018-07-09 10:37:24 +00:00
omdburl : jackett _omdb _url ,
2017-11-06 10:51:26 +00:00
proxy _type : jackett _proxy _type ,
2017-10-31 09:45:30 +00:00
proxy _url : jackett _proxy _url ,
proxy _port : jackett _proxy _port ,
proxy _username : jackett _proxy _username ,
proxy _password : jackett _proxy _password
2017-06-29 05:53:25 +00:00
} ;
2017-08-12 01:12:56 +00:00
api . updateServerConfig ( jsonObject , function ( data ) {
2017-08-30 09:50:11 +00:00
doNotify ( "Redirecting you to complete configuration update.." , "success" , "glyphicon glyphicon-ok" ) ;
window . setTimeout ( function ( ) {
window . location . reload ( true ) ;
2020-09-26 20:28:29 +00:00
} , 5000 ) ;
2017-08-30 09:50:11 +00:00
} ) . fail ( function ( data ) {
if ( data . responseJSON !== undefined && data . responseJSON . result == "error" ) {
doNotify ( "Error: " + data . responseJSON . error , "danger" , "glyphicon glyphicon-alert" ) ;
2017-06-29 05:53:25 +00:00
return ;
} else {
2017-08-30 09:50:11 +00:00
doNotify ( "Request to Jackett server failed" , "danger" , "glyphicon glyphicon-alert" ) ;
2017-06-29 05:53:25 +00:00
}
} ) ;
} ) ;
$ ( "#trigger-updater" ) . click ( function ( ) {
2017-08-08 15:02:16 +00:00
api . updateServer ( function ( data ) {
2017-06-29 05:53:25 +00:00
if ( data . result == "error" ) {
doNotify ( "Error: " + data . error , "danger" , "glyphicon glyphicon-alert" ) ;
return ;
} else {
doNotify ( "Updater triggered see log for details.." , "success" , "glyphicon glyphicon-ok" ) ;
}
} ) . fail ( function ( ) {
doNotify ( "Request to Jackett server failed" , "danger" , "glyphicon glyphicon-alert" ) ;
} ) ;
} ) ;
$ ( "#change-jackett-password" ) . click ( function ( ) {
var password = $ ( "#jackett-adminpwd" ) . val ( ) ;
2017-08-08 15:02:16 +00:00
api . updateAdminPassword ( password , function ( data ) {
if ( data == undefined ) {
2017-06-29 05:53:25 +00:00
doNotify ( "Admin password has been set." , "success" , "glyphicon glyphicon-ok" ) ;
window . setTimeout ( function ( ) {
window . location = window . location . pathname ;
} , 1000 ) ;
2017-08-08 15:02:16 +00:00
} else if ( data . result == "error" ) {
doNotify ( "Error: " + data . error , "danger" , "glyphicon glyphicon-alert" ) ;
return ;
2017-06-29 05:53:25 +00:00
}
} ) . fail ( function ( ) {
doNotify ( "Request to Jackett server failed" , "danger" , "glyphicon glyphicon-alert" ) ;
} ) ;
} ) ;
2019-04-01 08:24:49 +00:00
2020-09-26 20:28:29 +00:00
$ ( '#jackett-proxy-type' ) . on ( 'input' , function ( ) {
2019-04-01 08:24:49 +00:00
proxyWarning ( $ ( this ) . val ( ) ) ;
} ) ;
}
function proxyWarning ( input ) {
2020-09-26 20:28:29 +00:00
if ( input != null && input . toString ( ) . trim ( ) !== "-1" ) { // disabled = -1
2019-04-01 08:24:49 +00:00
$ ( '#proxy-warning' ) . show ( ) ;
2021-04-25 01:19:13 +00:00
} else {
2019-04-01 08:24:49 +00:00
$ ( '#proxy-warning' ) . hide ( ) ;
2019-04-01 08:40:35 +00:00
}
2021-05-08 20:24:18 +00:00
}