@@ -144,13 +144,15 @@ function parseURL() {
144144 }
145145
146146 // Skip URL parsing for specific pages we want to preserve
147- const specialPages = [ '/popular-repos/' , '/popular-repos ', '/popular-repos.html' ] ;
147+ const specialPages = [ '/popular-repos' , '/popular-repos.html' ] ;
148148 if ( specialPages . includes ( window . location . pathname ) ) {
149149 // Special page identified, ensure visibility of container if needed
150150 if ( window . location . pathname . includes ( 'popular-repos' ) ) {
151151 const popularRepoContainer = document . getElementById ( 'popular-repos-container' ) ;
152152 if ( popularRepoContainer ) {
153153 popularRepoContainer . style . display = 'block' ;
154+ // Initialize popular repos pagination if needed
155+ initializePopularRepos ( ) ;
154156 }
155157 }
156158 return ; // Don't process URLs for special pages
@@ -861,3 +863,96 @@ themeToggle.addEventListener('click', () => {
861863 trackEvent ( 'UI' , 'ThemeToggle' , isDarkMode ? 'dark' : 'light' ) ;
862864 }
863865} ) ;
866+
867+ // --- Popular Repos Page Functions ---
868+ function initializePopularRepos ( ) {
869+ const categoryButtons = document . querySelectorAll ( '.category-btn' ) ;
870+ const categoryOptions = document . querySelectorAll ( '.category-option' ) ;
871+ const repoEntries = document . querySelectorAll ( '.repo-entry' ) ;
872+ const loadMoreBtn = document . getElementById ( 'load-more-btn' ) ;
873+
874+ // Skip if elements aren't found (not on popular repos page)
875+ if ( ! categoryButtons . length || ! repoEntries . length || ! loadMoreBtn ) return ;
876+
877+ let visibleCount = 0 ;
878+ const PAGE_SIZE = 15 ;
879+ let currentCategory = 'all' ;
880+
881+ function showReposByCategory ( category ) {
882+ let shown = 0 ;
883+ repoEntries . forEach ( entry => {
884+ if ( category === 'all' || entry . classList . contains ( category ) ) {
885+ if ( shown < PAGE_SIZE ) {
886+ entry . style . display = '' ;
887+ shown ++ ;
888+ } else {
889+ entry . style . display = 'none' ;
890+ }
891+ } else {
892+ entry . style . display = 'none' ;
893+ }
894+ } ) ;
895+ visibleCount = shown ;
896+ // Show load more button if there are more to show
897+ let totalInCategory = Array . from ( repoEntries ) . filter ( entry =>
898+ category === 'all' || entry . classList . contains ( category ) ) . length ;
899+ loadMoreBtn . style . display = ( visibleCount < totalInCategory ) ? '' : 'none' ;
900+ }
901+
902+ function loadMoreRepos ( ) {
903+ let shown = 0 ;
904+ let loaded = 0 ;
905+ repoEntries . forEach ( entry => {
906+ if ( ( currentCategory === 'all' || entry . classList . contains ( currentCategory ) ) ) {
907+ if ( entry . style . display !== 'none' ) {
908+ shown ++ ;
909+ }
910+ }
911+ } ) ;
912+ repoEntries . forEach ( entry => {
913+ if ( ( currentCategory === 'all' || entry . classList . contains ( currentCategory ) ) ) {
914+ if ( entry . style . display === 'none' && loaded < PAGE_SIZE ) {
915+ entry . style . display = '' ;
916+ loaded ++ ;
917+ }
918+ }
919+ } ) ;
920+ visibleCount += loaded ;
921+ let totalInCategory = Array . from ( repoEntries ) . filter ( entry =>
922+ currentCategory === 'all' || entry . classList . contains ( currentCategory ) ) . length ;
923+ loadMoreBtn . style . display = ( visibleCount < totalInCategory ) ? '' : 'none' ;
924+ }
925+
926+ // Initial show
927+ showReposByCategory ( 'all' ) ;
928+
929+ // Category button click
930+ categoryButtons . forEach ( button => {
931+ button . addEventListener ( 'click' , function ( ) {
932+ categoryButtons . forEach ( btn => btn . classList . remove ( 'active' ) ) ;
933+ this . classList . add ( 'active' ) ;
934+ currentCategory = this . getAttribute ( 'data-category' ) ;
935+ showReposByCategory ( currentCategory ) ;
936+ } ) ;
937+ } ) ;
938+
939+ categoryOptions . forEach ( option => {
940+ option . addEventListener ( 'click' , function ( e ) {
941+ e . preventDefault ( ) ;
942+ categoryButtons . forEach ( btn => btn . classList . remove ( 'active' ) ) ;
943+ document . querySelector ( `[data-category="${ this . getAttribute ( 'data-category' ) } "]` ) . classList . add ( 'active' ) ;
944+ currentCategory = this . getAttribute ( 'data-category' ) ;
945+ showReposByCategory ( currentCategory ) ;
946+ } ) ;
947+ } ) ;
948+
949+ loadMoreBtn . addEventListener ( 'click' , loadMoreRepos ) ;
950+ }
951+
952+ // Call initialize on DOMContentLoaded (in case we navigate directly to the page)
953+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
954+ // If we're on the popular repos page, initialize it
955+ if ( window . location . pathname . includes ( 'popular-repos' ) ) {
956+ initializePopularRepos ( ) ;
957+ }
958+ } ) ;
0 commit comments