2017-06-04 07:43:41 +02:00
// @source https://github.com/NyaaPantsu/nyaa/tree/dev/public/js
// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat
2017-05-26 13:13:06 +02:00
2017-05-27 19:08:47 +02:00
// Switches between themes when a new one is selected
2017-07-22 23:27:02 +02:00
2017-05-27 19:08:47 +02:00
function switchThemes ( ) {
2017-07-16 17:36:17 +02:00
themeName = document . getElementById ( "theme-selector" ) . value
2017-07-21 01:47:36 +02:00
var head = document . getElementsByTagName ( "head" ) [ 0 ]
2017-07-16 17:36:17 +02:00
// Remove the theme in place, it fails if one isn't set
try {
2017-07-21 01:47:36 +02:00
head . removeChild ( document . getElementById ( "theme" ) )
2017-07-16 17:36:17 +02:00
} catch ( err ) { }
// Don't add a node if we don't want extra styling
if ( themeName === "" ) {
2017-07-21 01:47:36 +02:00
return
2017-07-16 17:36:17 +02:00
}
// Create the new one and put it back
2017-07-21 01:47:36 +02:00
var newTheme = document . createElement ( "link" )
newTheme . setAttribute ( "rel" , "stylesheet" )
newTheme . setAttribute ( "href" , "/css/" + themeName + ".css" )
newTheme . setAttribute ( "id" , "theme" )
head . appendChild ( newTheme )
2017-05-27 19:08:47 +02:00
}
2017-05-05 12:59:56 +02:00
// Used by spoiler tags
function toggleLayer ( elem ) {
2017-07-16 17:36:17 +02:00
if ( elem . classList . contains ( "hide" ) ) {
2017-07-21 01:47:36 +02:00
elem . classList . remove ( "hide" )
2017-07-16 17:36:17 +02:00
} else {
2017-07-21 01:47:36 +02:00
elem . classList . add ( "hide" )
2017-07-16 17:36:17 +02:00
}
2017-05-05 12:59:56 +02:00
}
2017-05-30 00:28:21 +02:00
function parseAllDates ( ) {
2017-07-16 17:36:17 +02:00
// Date formatting
2017-07-21 01:47:36 +02:00
var lang = document . getElementsByTagName ( "html" ) [ 0 ] . getAttribute ( "lang" )
var ymdOpt = { year : "numeric" , month : "short" , day : "numeric" }
var hmOpt = { hour : "numeric" , minute : "numeric" }
2017-05-05 15:55:25 +02:00
2017-07-21 01:47:36 +02:00
var list = document . getElementsByClassName ( "date-short" )
2017-07-16 17:36:17 +02:00
for ( var i in list ) {
2017-07-21 01:47:36 +02:00
var e = list [ i ]
e . title = e . innerText
e . innerText = new Date ( e . innerText ) . toLocaleString ( lang , ymdOpt )
2017-07-16 17:36:17 +02:00
}
2017-05-05 15:55:25 +02:00
2017-07-21 01:47:36 +02:00
var list = document . getElementsByClassName ( "date-full" )
2017-07-16 17:36:17 +02:00
for ( var i in list ) {
2017-07-21 01:47:36 +02:00
var e = list [ i ]
e . title = e . innerText
e . innerText = new Date ( e . innerText ) . toLocaleString ( lang )
2017-07-16 17:36:17 +02:00
}
2017-05-05 15:55:25 +02:00
}
2017-05-31 04:21:35 +02:00
2017-07-21 01:47:36 +02:00
parseAllDates ( )
2017-05-31 04:21:35 +02:00
2017-07-22 23:27:02 +02:00
//if no version cookie set or non-equal version
if ( ! document . cookie . includes ( "version" ) || ( document . cookie . substring ( document . cookie . indexOf ( "version" ) + 8 ) . substring ( 0 , document . cookie . substring ( document . cookie . indexOf ( "version" ) + 8 ) . indexOf ( ";" ) == "-1" ? document . cookie . substring ( document . cookie . indexOf ( "version" ) + 8 ) . length : document . cookie . substring ( document . cookie . indexOf ( "version" ) + 8 ) . indexOf ( ";" ) ) ) != Version ) {
//Remove all cookies
var cookies = document . cookie . split ( ";" ) ;
for ( var i = 0 ; i < cookies . length ; i ++ )
document . cookie = cookies [ i ] . split ( "=" ) [ 0 ] + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;" ;
//set new version in cookie
document . cookie = "version=" + Version ;
}
2017-05-13 00:37:37 +02:00
/*Fixed-Navbar offset fix*/
2017-05-29 13:12:05 +02:00
document . addEventListener ( "DOMContentLoaded" , function ( event ) {
2017-07-21 01:47:36 +02:00
var shiftWindow = function ( ) { scrollBy ( 0 , - 70 ) }
if ( location . hash ) shiftWindow ( )
window . addEventListener ( "hashchange" , shiftWindow )
2017-07-16 17:36:17 +02:00
document . getElementsByClassName ( "search-box" ) [ 0 ] . addEventListener ( "focus" , function ( e ) {
2017-07-21 01:47:36 +02:00
var w = document . getElementsByClassName ( "h-user" ) [ 0 ] . offsetWidth
document . getElementsByClassName ( "h-user" ) [ 0 ] . style . display = "none"
document . getElementsByClassName ( "search-box" ) [ 0 ] . style . width = document . getElementsByClassName ( "search-box" ) [ 0 ] . offsetWidth + w + "px"
} )
2017-07-16 17:36:17 +02:00
document . getElementsByClassName ( "search-box" ) [ 0 ] . addEventListener ( "blur" , function ( e ) {
2017-07-21 01:47:36 +02:00
document . getElementsByClassName ( "search-box" ) [ 0 ] . style . width = ""
document . getElementsByClassName ( "h-user" ) [ 0 ] . style . display = "inline-block"
} )
2017-07-10 15:24:52 +02:00
2017-07-21 01:47:36 +02:00
} )
2017-05-26 13:13:06 +02:00
function playVoice ( ) {
2017-07-21 01:47:36 +02:00
var mascotAudio = document . getElementById ( "explosion" ) || document . getElementById ( "nyanpassu" ) || document . getElementById ( "nyanpassu2" ) || document . getElementById ( "kawaii" )
2017-07-16 17:36:17 +02:00
if ( mascotAudio !== undefined ) {
2017-07-21 01:47:36 +02:00
mascotAudio . volume = 0.2
mascotAudio . play ( )
2017-07-16 17:36:17 +02:00
} else {
console . log ( "Your mascot doesn't support yet audio files!" )
}
2017-05-29 13:12:05 +02:00
}
2017-07-10 05:57:59 +02:00
2017-07-10 15:24:52 +02:00
document . getElementsByClassName ( "form-input refine" ) [ 0 ] . addEventListener ( "click" , function ( e ) {
2017-07-21 01:47:36 +02:00
document . getElementsByClassName ( "box refine" ) [ 0 ] . style . display = document . getElementsByClassName ( "box refine" ) [ 0 ] . style . display == "none" ? "block" : "none"
2017-07-16 17:36:17 +02:00
if ( document . getElementsByClassName ( "form-input refine-searchbox" ) [ 0 ] . value != document . getElementsByClassName ( "form-input search-box" ) [ 0 ] . value )
2017-07-21 01:47:36 +02:00
document . getElementsByClassName ( "form-input refine-searchbox" ) [ 0 ] . value = document . getElementsByClassName ( "form-input search-box" ) [ 0 ] . value
2017-07-16 17:36:17 +02:00
if ( document . getElementsByClassName ( "form-input refine-category" ) [ 0 ] . selectedIndex != document . getElementsByClassName ( "form-input form-category" ) [ 0 ] . selectedIndex )
2017-07-21 01:47:36 +02:00
document . getElementsByClassName ( "form-input refine-category" ) [ 0 ] . selectedIndex = document . getElementsByClassName ( "form-input form-category" ) [ 0 ] . selectedIndex
e . preventDefault ( )
2017-07-16 17:36:17 +02:00
if ( document . getElementsByClassName ( "box refine" ) [ 0 ] . style . display == "block" )
2017-07-21 01:47:36 +02:00
scrollTo ( 0 , 0 )
} )
function humanFileSize ( bytes , si ) {
var k = si ? 1000 : 1024
var i = ~ ~ ( Math . log ( bytes ) / Math . log ( k ) )
return i == 0 ? bytes + " B" : ( bytes / Math . pow ( k , i ) ) . toFixed ( 1 ) + " " + "KMGTPEZY" [ i - 1 ] + ( si ? "" : "i" ) + "B"
}
2017-06-04 07:43:41 +02:00
// @license-end