1"use strict"; 2var is_fullscreen = false; 3function open_fullscreen() { 4 let game = document.getElementById("game-area"); 5 if(is_fullscreen){ 6 // Exit fullscreen 7 is_fullscreen = false; 8 if(is_mobile_device()){ 9 game.style.position = "absolute"; 10 document.getElementById("mobile-back-button").style.display = "none"; 11 document.getElementById("game-player").style.display = "none"; 12 } else { 13 if (game.requestFullscreen) { 14 game.requestFullscreen(); 15 } else if (game.mozRequestFullScreen) { /* Firefox */ 16 game.mozRequestFullScreen(); 17 } else if (game.webkitRequestFullscreen) { /* Chrome, Safari and Opera */ 18 game.webkitRequestFullscreen(); 19 } else if (game.msRequestFullscreen) { /* IE/Edge */ 20 game.msRequestFullscreen(); 21 } 22 } 23 } else { 24 // Enter fullscreen 25 is_fullscreen = true; 26 if(is_mobile_device()){ 27 document.getElementById("game-player").style.display = "block"; 28 game.style.position = "fixed"; 29 document.getElementById("mobile-back-button").style.display = "flex"; 30 } else { 31 if (game.requestFullscreen) { 32 game.requestFullscreen(); 33 } else if (game.mozRequestFullScreen) { /* Firefox */ 34 game.mozRequestFullScreen(); 35 } else if (game.webkitRequestFullscreen) { /* Chrome, Safari and Opera */ 36 game.webkitRequestFullscreen(); 37 } else if (game.msRequestFullscreen) { /* IE/Edge */ 38 game.msRequestFullscreen(); 39 } 40 } 41 } 42}; 43function is_mobile_device(){ 44 if (navigator.userAgent.match(/Android/i) 45 || navigator.userAgent.match(/webOS/i) 46 || navigator.userAgent.match(/iPhone/i) 47 || navigator.userAgent.match(/iPad/i) 48 || navigator.userAgent.match(/iPod/i) 49 || navigator.userAgent.match(/BlackBerry/i) 50 || navigator.userAgent.match(/Windows Phone/i)) { 51 return true; 52 } else { 53 return false; 54 } 55} 56if($('iframe#game-area').length){ 57 load_leaderboard({type: 'top', amount: 10}); 58 drag_back_btn(document.getElementById("mobile-back-button")); 59 if(is_mobile_device()){ 60 if($('#allow_mobile_version').length){ 61 document.getElementById('mobile-play').style.display = 'block'; 62 document.getElementById('game-player').style.display = 'none'; 63 } 64 } 65} 66function drag_back_btn(elem) { 67 let is_drag = false; 68 let pos_1 = 0, pos_2 = 0; 69 let last_y = elem.style.top; 70 let touchstart_y = 0; 71 elem.addEventListener("touchend", function(e) { 72 if(is_drag){ 73 is_drag = false; 74 } 75 }, false); 76 elem.addEventListener("touchmove", function(e) { 77 e.preventDefault(); 78 let touch = e.changedTouches[0]; 79 if(!is_drag){ 80 if(touchstart_y < touch.clientY+5 || touchstart_y > touch.clientY-5){ 81 // Trigger "dragstart" 82 pos_2 = e.clientY; 83 is_drag = true; 84 } 85 } 86 if(is_drag){ 87 pos_1 = pos_2 - touch.clientY; 88 pos_2 = touch.clientY; 89 elem.style.top = (pos_2) + "px"; 90 } 91 }, false); 92 elem.addEventListener("touchstart", function(e) { 93 let touch = e.changedTouches[0]; 94 last_y = elem.style.top; 95 touchstart_y = touch.clientY; 96 }, false); 97 elem.addEventListener("click", function(e) { 98 e.preventDefault(); 99 if(last_y == elem.style.top){ 100 open_fullscreen(); 101 } 102 }, false); 103} 104function load_leaderboard(conf){ 105 if($('#content-leaderboard').length){ 106 let g_id = $('#content-leaderboard').data('id'); 107 $.ajax({ 108 url: '/includes/api.php', 109 type: 'POST', 110 dataType: 'json', 111 data: {'action': 'get_scoreboard', 'game-id': g_id, 'conf': JSON.stringify(conf)}, 112 complete: function (data) { 113 if(data.responseText){ 114 if(JSON.parse(data.responseText).length){ 115 show_leaderboard(JSON.parse(data.responseText)); 116 } 117 } 118 } 119 }); 120 } 121} 122function show_leaderboard(data){ 123 let html = '<table class="table table-striped table-dark"><thead class="thead-dark"><tr><th scope="col">#</th><th scope="col">Username</th><th scope="col">Score</th><th scope="col">Date</th></tr></thead><tbody>'; 124 let index = 1; 125 data.forEach((item)=>{ 126 html += '<tr><th scope="row">'+index+'</th><td>'+item.username+'</td><td>'+item.score+'</td><td>'+item.created_date.substr(0, 10)+'</td></tr>'; 127 index++; 128 }); 129 html += '</tbody></table>'; 130 $('#content-leaderboard').html(html); 131} 132(function(){ 133 let last_offset = $("#new-games-section").children().length; 134 let load_amount = 12; 135 $('#load-more1').click((e)=>{ 136 e.preventDefault(); 137 $(this).addClass('disabled'); 138 fetch_games(load_amount, 'new'); 139 }); 140 function fetch_games(amount, sort_by) { 141 $.ajax({ 142 url: "/includes/fetch.php", 143 type: 'POST', 144 dataType: 'json', 145 data: {amount: amount, offset: last_offset, sort_by: sort_by}, 146 complete: function (data) { 147 append_content(JSON.parse(data.responseText)); 148 } 149 }); 150 } 151 function append_content(data){ 152 last_offset += data.length; 153 data.forEach((game)=>{ 154 let rating = 0; 155 game['upvote'] = Number(game['upvote']); 156 game['downvote'] = Number(game['downvote']); 157 let total_revs = game['upvote']+game['downvote']; 158 if(total_revs > 0){ 159 rating = (Math.round((game['upvote']/(game['upvote']+game['downvote'])) * 5) / 10); 160 } 161 let html = '<div class="col-md-2 col-sm-3 col-4 grid-1">'; 162 html += '<a href="/game/'+game['slug']+'/">'; 163 html += '<div class="game-item">' 164 html += '<div class="list-game">'; 165 html += '<div class="list-thumbnail"><img src="'+game['thumb_2']+'" class="small-thumb img-rounded" alt="'+game['title']+'"></div>'; 166 html += '<div class="list-info">'; 167 html += '<div class="list-title">'+game['title']+'</div>'; 168 html += '</div></div></div></a></div>'; 169 $("#new-games-section").append(html); 170 $("#new-games-section .column:hidden").slice(0, load_amount).slideDown(); 171 }); 172 if(data.length < load_amount){ 173 $("#load-more1").text("No More Games").addClass("noContent disabled"); 174 } else { 175 $("#load-more1").removeClass('disabled'); 176 } 177 } 178 $('#mobile-play-btn').on('click', function(e) { 179 open_fullscreen(); 180 }); 181 $('.b-action #favorite').on('click', function(e) { 182 e.preventDefault(); 183 let data_id = $('.game-content').attr('data-id'); 184 let btn = $(this); 185 $.ajax({ 186 url: '/includes/vote.php', 187 type: 'POST', 188 dataType: 'json', 189 data: {'favorite': true, 'action': 'favorite', 'id': data_id}, 190 success: function (data) { 191 //console.log(data.responseText); 192 }, 193 error: function (data) { 194 //console.log(data.responseText); 195 },
196 complete: function (data) { 197 console.log(data.responseText); 198 btn.addClass('active'); 199 btn.addClass('disabled'); 200 } 201 }); 202 }); 203 $('.b-action #upvote').on('click', function(e) { 204 e.preventDefault(); 205 let data_id = $('.game-content').attr('data-id'); 206 let btn = $(this); 207 $.ajax({ 208 url: '/includes/vote.php', 209 type: 'POST', 210 dataType: 'json', 211 data: {'vote': true, 'action': 'upvote', 'id': data_id}, 212 success: function (data) { 213 //console.log(data.responseText); 214 }, 215 error: function (data) { 216 //console.log(data.responseText); 217 }, 218 complete: function (data) { 219 console.log(data.responseText); 220 btn.addClass('active'); 221 btn.addClass('disabled'); 222 } 223 }); 224 }); 225 $('.b-action #downvote').on('click', function(e) { 226 e.preventDefault(); 227 let data_id = $('.game-content').attr('data-id'); 228 let btn = $(this); 229 $.ajax({ 230 url: '/includes/vote.php', 231 type: 'POST', 232 dataType: 'json', 233 data: {'vote': true, 'action': 'downvote', 'id': data_id}, 234 success: function (data) { 235 //console.log(data.responseText); 236 }, 237 error: function (data) { 238 //console.log(data.responseText); 239 }, 240 complete: function (data) { 241 console.log(data.responseText); 242 btn.addClass('active'); 243 btn.addClass('disabled'); 244 } 245 }); 246 }); 247 $('.user-avatar').on('click', function(){ 248 249 let element = $(this).next(); 250 if (element.is(":hidden")) { 251 element.removeClass('hidden'); 252 } else element.addClass('hidden'); 253 }); 254 $('#btn_prev').on('click', function() { 255 $('.profile-gamelist ul').animate({ 256 scrollLeft: '-=150' 257 }, 300, 'swing'); 258 }); 259 $('#btn_next').on('click', function() { 260 $('.profile-gamelist ul').animate({ 261 scrollLeft: '+=150' 262 }, 300, 'swing'); 263 }); 264 $('#f_prev').on('click', function() { 265 $('.favorite-gamelist ul').animate({ 266 scrollLeft: '-=150' 267 }, 300, 'swing'); 268 }); 269 $('#f_next').on('click', function() { 270 $('.favorite-gamelist ul').animate({ 271 scrollLeft: '+=150' 272 }, 300, 'swing'); 273 }); 274 $('#t-prev').on('click', function() { 275 $('.list-1-wrapper').animate({ 276 scrollLeft: '-=150' 277 }, 300, 'swing'); 278 }); 279 280 $('#t-next').on('click', function() { 281 $('.list-1-wrapper').animate({ 282 scrollLeft: '+=150' 283 }, 300, 'swing'); 284 }); 285 $('.delete-comment').on('click', function() { 286 let id = $(this).attr('data-id'); 287 $.ajax({ 288 url: '/includes/comment.php', 289 type: 'POST', 290 dataType: 'json', 291 data: {'delete': true, 'id': id}, 292 success: function (data) { 293 //console.log(data.responseText); 294 }, 295 error: function (data) { 296 //console.log(data.responseText); 297 }, 298 complete: function (data) { 299 if(data.responseText === 'deleted'){ 300 $('.id-'+id).remove(); 301 } 302 } 303 }, this); 304 }); 305 let game_id; 306 if($('#comments').length){ 307 game_id = $('.game-content').attr('data-id'); 308 $.ajax({ 309 url: '/includes/comment.php', 310 type: 'POST', 311 dataType: 'json', 312 data: {'load': true, 'game_id': game_id}, 313 success: function (data) { 314 //console.log(data.responseText); 315 }, 316 error: function (data) { 317 //console.log(data.responseText); 318 }, 319 complete: function (data) { 320 let comments = JSON.parse(data.responseText); 321 load_comments(convert_comments(comments)); 322 } 323 }); 324 } 325 function convert_comments(array){ 326 let data = []; 327 array.forEach((item)=>{ 328 let arr = { 329 id: Number(item.id), 330 created: item.created_date, 331 content: item.comment, 332 fullname: item.sender_username, 333 profile_picture_url: item.avatar, 334 }; 335 if(Number(item.parent_id)){ 336 arr.parent = Number(item.parent_id); 337 } 338 if(!arr.fullname){ 339 arr.fullname = 'Anonymous'; 340 } 341 data.push(arr); 342 }); 343 return data; 344 } 345 function load_comments(array){ 346 let read_only = false; 347 let avatar = $('.user-avatar img').attr('src'); 348 if(!avatar){ 349 avatar = '/images/default_profile.png'; 350 read_only = true; 351 } 352 $('#comments').comments({ 353 enableUpvoting:false,
354 roundProfilePictures: true, 355 popularText: '', 356 profilePictureURL: avatar, 357 readOnly: read_only, 358 getComments: function(success, error) { 359 success(array); 360 }, 361 postComment: function(commentJSON, success, error) { 362 commentJSON.source = 'jquery-comments'; 363 commentJSON.send = true; 364 commentJSON.game_id = game_id; 365 $.ajax({ 366 type: 'post', 367 url: '/includes/comment.php', 368 data: commentJSON, 369 success: function(comment) { 370 console.log(comment); 371 success(commentJSON) 372 }, 373 error: error 374 }); 375 } 376 }); 377 } 378})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.