2018-05-17 00:05:47 +03:00
function Portal ( sites )
{
2018-06-03 01:11:00 +03:00
this . el = document . createElement ( "div" ) ;
2018-05-17 00:05:47 +03:00
this . sites = sites ;
this . install = function ( )
{
2018-05-17 00:41:09 +03:00
document . body . appendChild ( this . el ) ;
2018-05-17 00:05:47 +03:00
}
this . start = function ( )
{
2018-05-17 00:41:09 +03:00
this . install ( ) ;
2018-05-19 04:44:44 +03:00
this . el . innerHTML = window . location . hash && window . location . hash . length > 4 ? this . redirect ( ) : this . directory ( ) ;
2018-05-17 00:22:20 +03:00
}
2018-06-03 01:11:00 +03:00
this . readme = function ( )
{
2018-07-04 04:23:41 +03:00
return ` <p class='readme'>This webring is an attempt to inspire artists & developers to build their own website and share traffic among each other. The ring welcomes personalized websites such as <b>diaries, wikis & portfolios</b>.</p><p>To add yourself to the ring, submit a <a href='https://github.com/XXIIVV/webring/edit/master/index.html' target='_blank'>Pull Request</a>.<br />If you found a broken link, please <a href='https://github.com/XXIIVV/webring/issues/new' target='_blank'>report it</a>.</p> `
2018-06-03 01:11:00 +03:00
}
this . buttons = function ( )
{
return ` <p class='buttons'><a href='#random' onClick="portal.reload('random')">Random</a> | <a href='https://github.com/XXIIVV/webring'>Information</a> <a id='icon' href='#random' onClick="portal.reload('random')"></a></p> `
}
2018-05-17 00:22:20 +03:00
this . directory = function ( )
{
2018-05-17 00:41:09 +03:00
var html = ""
2018-05-18 23:31:05 +03:00
for ( var id in this . sites ) {
2018-05-17 00:41:09 +03:00
var site = this . sites [ id ]
2018-05-18 23:20:34 +03:00
html += ` <ln> ${ id } ) <a href=' ${ site } '> ${ site . split ( "//" ) [ 1 ] } </a></ln> `
2018-05-17 00:41:09 +03:00
}
2018-06-03 01:11:00 +03:00
return ` <list> ${ html } </list> \n ${ this . readme ( ) } ${ this . buttons ( ) } `
2018-05-17 00:22:20 +03:00
}
2018-05-17 02:36:32 +03:00
this . reload = function ( )
{
setTimeout ( ( ) => { window . location . reload ( ) } , 500 )
}
2018-05-18 01:39:57 +03:00
this . navigate = function ( target )
{
setTimeout ( ( ) => {
window . location . href = target
} , 3000 )
}
2018-05-17 00:22:20 +03:00
this . location = function ( )
{
2018-05-17 00:41:09 +03:00
return window . location . hash . replace ( "#" , "" ) . trim ( ) ;
2018-05-17 00:22:20 +03:00
}
this . locate = function ( )
{
2018-05-17 00:41:09 +03:00
var hash = this . location ( ) ;
if ( hash == "random" ) {
return Math . floor ( Math . random ( ) * this . sites . length )
}
2018-05-17 00:22:20 +03:00
for ( var id in this . sites ) {
var site = this . sites [ id ] ;
if ( site . indexOf ( hash ) > - 1 ) {
return parseInt ( id )
}
}
return - 1
}
this . next = function ( loc )
{
return loc == this . sites . length - 1 ? this . sites [ 0 ] : this . sites [ loc + 1 ] ;
}
this . redirect = function ( )
{
var location = this . locate ( ) ;
var target = this . next ( location ) ;
2018-05-18 01:39:57 +03:00
this . navigate ( target )
2018-06-03 01:11:00 +03:00
return ` <p>Redirecting to <b> ${ target } </b></p><meta http-equiv="refresh" content="3; url= ${ target } ">
< p class = 'buttons' > < a href = '#' onClick = "portal.reload('')" > Directory < / a > | < a h r e f = ' # $ { t a r g e t } ' o n C l i c k = " p o r t a l . r e l o a d ( ' r a n d o m ' ) " > S k i p < / a > | < a h r e f = ' # r a n d o m ' o n C l i c k = " p o r t a l . r e l o a d ( ' r a n d o m ' ) " > R a n d o m < / a > | < a h r e f = ' h t t p s : / / g i t h u b . c o m / X X I I V V / w e b r i n g ' > I n f o r m a t i o n < / a > < a i d = ' i c o n ' h r e f = ' # r a n d o m ' o n C l i c k = " p o r t a l . r e l o a d ( ' r a n d o m ' ) " > < / a > < / p > `
2018-05-17 00:05:47 +03:00
}
2018-05-18 01:39:57 +03:00
}