‘);
storiesList.insertAdjacentHTML(‘beforeend’, ‘
End Page ‘ + pageNumber + ‘
‘);
window.addEventListener(“scroll”, onWindowScroll);
function onWindowScroll(e) {
var st = window.pageYOffset || document.documentElement.scrollTop;
if (!infiniteScrollRequestInProgress) {
if (st > lastScrollTop) {
direction = ‘down’;
}
else if (st = contentHeight || yOffset 1 ? min_page -1 : min_page);
if(page_to_be_fetched > 1) {
timelineLoadingDivTop.style.display = ‘block’;
}
}
if(page_to_be_fetched > max_page || page_to_be_fetched -1 ? postType : “News”;
var category = “Scroll: ” + type;
if (typeof ga_event == ‘function’ && data.trim() != ”) {
ga_event(category, action, label);
}
if (data.trim() != ”) {
pageNumber = page_to_be_fetched;
if(direction == ‘down’)
{
max_page += 1;
storiesList.insertAdjacentHTML(‘beforeend’, ‘
Start Page ‘+ pageNumber +’
‘);
storiesList.insertAdjacentHTML(‘beforeend’, data);
storiesList.insertAdjacentHTML(‘beforeend’, ‘
End Page ‘+ pageNumber +’
‘);
timelineLoadingDivBottom.style.display = ‘none’;
}
else if(direction == ‘up’)
{
if(min_page > 1)
min_page -= 1;
storiesList.insertAdjacentHTML(‘afterbegin’, ‘
End Page ‘+ pageNumber +’
‘);
storiesList.insertAdjacentHTML(‘afterbegin’, data);
storiesList.insertAdjacentHTML(‘afterbegin’, ‘
Start Page ‘+ pageNumber +’
‘);
timelineLoadingDivTop.style.display = ‘none’;
}
infiniteScrollRequestInProgress = false;
} else {
timelineLoadingDivTop.style.display = ‘none’;
timelineLoadingDivBottom.style.display = ‘none’;
}
removeDuplicateStories();
refreshScores();
// This is done so that the argument value gets corrected in case the user loads the feed by giving page as param and then switches the feed.
window.scrollTo(window.scrollX, window.scrollY + 1);
}, function (error) {
console.log(error);
infiniteScrollRequestInProgress = false;
timelineLoadingDivTop.style.display = ‘none’;
timelineLoadingDivBottom.style.display = ‘none’;
});
}
else {
infiniteScrollRequestInProgress = false;
}
}
}
}
function checkVisible(elm) {
var rect = elm.getBoundingClientRect();
var viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
return !(rect.bottom = 0);
}
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp(“([?&])” + key + “=.*?(&|#|$)”, “i”);
if( value === undefined ) {
if (uri.match(re)) {
return uri.replace(re, ‘$1$2’).replace(/[?&]$/, ”).replaceAll(/([?&])&+/g, ‘$1’).replace(/[?&]#/, ‘#’);
} else {
return uri;
}
} else {
if (uri.match(re)) {
return uri.replace(re, ‘$1’ + key + “=” + value + ‘$2’);
} else {
var hash = ”;
if( uri.indexOf(‘#’) !== -1 ){
hash = uri.replace(/.*#/, ‘#’);
uri = uri.replace(/#.*/, ”);
}
var separator = uri.indexOf(‘?’) !== -1 ? “&” : “?”;
return uri + separator + key + “=” + value + hash;
}
}
}
function updateURL(page_no) {
var querystring = window.location.search;
var hash = window.location.hash;
//remove hash (and any trailing #) from url
var url = window.location.href.replace(hash, ”).replace(/#+$/,”);
if(querystring != ”)
{
if(querystring.includes(“page=”)) {
url = updateQueryStringParameter(url, “page”, page_no)
} else {
url += ‘&page=’+page_no;
}
}
else
{
url += ‘?page=’+page_no;
}
url += hash;
if(window.location.href != url) {
window.history.replaceState(“visible_page”, “Page ” + page_no, url);
}
return url;
}
function updateLinksAndMeta(page_no) {
//update title and meta description
if(page_no == 1)
{ //remove page no
document.title = (document.title).replace(/Page [0-9]+ – /g, “”);
if(meta_description) {
meta_description.content = (meta_description.content).replace(/Page [0-9]+ – /g, “”);
}
}
else if(page_no > 1)
{
if((document.title).match(/Page [0-9]+/g) != null) {
document.title = (document.title).replace(/Page [0-9]+/g, “Page ” + page_no);
}
else {
document.title = ‘Page ‘ + page_no + ‘ – ‘ + document.title;
}
if(meta_description) {
if((meta_description.content).match(/Page [0-9]+/g) != null) {
meta_description.content = (meta_description.content).replace(/Page [0-9]+/g, “Page ” + page_no);
}
else {
meta_description.content = ‘Page ‘ + page_no + ‘ – ‘ + meta_description.content;
}
}
}
if(canonical) {
//update rel canonical
canonical.href = (canonical.href).split(‘?’)[0] + ‘?page=’ + page_no;
//update rel next
if(next_link)
{ next_link.href = (canonical.href).split(‘?’)[0] + ‘?page=’ + (page_no + 1);
}
//update rel prev
if(prev_link == null)
{
prev_link = document.createElement(‘link’);
prev_link.rel = ‘prev’;
prev_link.id = ‘prev-link’;
head.appendChild(prev_link);
}
if(page_no == 2) {
prev_link.href = (canonical.href).split(‘?’)[0];
}
else if(page_no = 0 || data.match_status.indexOf(“PEN”) >= 0) {
apostrophe = ” “;
}
story.innerHTML = data.match_status + apostrophe + data.match_localteam_name_short + ‘ ‘ + data.match_localteam_score + ‘-‘ + data.match_visitorteam_score +
‘ ‘ + data.match_visitorteam_name_short;
}
}
function updateCricketScore(story, data) {
data = JSON.parse(data);
var match = data[‘score_strip’][0][‘currently_batting’] ? data[‘score_strip’][0] : null;
if (match == null) {
match = data[‘score_strip’][1][‘currently_batting’] ? data[‘score_strip’][1] : null;
}
if (match != null) {
story.innerHTML = match[‘short_name’] + ‘ ‘ + match[‘score’];
} else {
story.innerHTML = data[‘score_strip’][0][‘short_name’] + ‘ vs ‘ + data[‘score_strip’][1][‘short_name’] + ‘ | YET TO START’;
}
}
function refreshScores() {
var stories = $all(‘[data-scoreid]’);
for (var i = 0; i