diff --git a/tcf_website/static/common/recently_viewed.js b/tcf_website/static/common/recently_viewed.js index a4926d152..3c53df3c9 100644 --- a/tcf_website/static/common/recently_viewed.js +++ b/tcf_website/static/common/recently_viewed.js @@ -67,11 +67,25 @@ function saveCourseInfoIfPresent() { previousPaths.unshift(currentUrl); previousPathsTitles.unshift(title); - // Keep only the top 10 items + // Only display last 10 items if (previousPaths.length > 10) { - previousPaths = previousPaths.slice(0, 10); + // previousPaths = previousPaths.slice(0, 10); previousPathsTitles = previousPathsTitles.slice(0, 10); } + // Prevent too many courses from being stored, max 20 + if (previousPaths.length > 20) { + previousPaths = previousPaths.slice(0, 20); + previousPathsTitles = previousPathsTitles.slice(0, 20); + } + + + if (previousPaths.length % 5 === 0 && previousPaths.length >= 10) { + // Check if URL matches .../course/[letters]/[numbers] and ends there + const courseRegex = /course\/[a-zA-Z]+\/\d+\/?$/; + if (courseRegex.test(currentUrl)) { + $('#viewLimitModal').modal('show'); + } + } // Save back to localStorage localStorage.setItem("previous_paths", JSON.stringify(previousPaths)); diff --git a/tcf_website/templates/base/index.html b/tcf_website/templates/base/index.html index 73d53549c..d87e5959b 100644 --- a/tcf_website/templates/base/index.html +++ b/tcf_website/templates/base/index.html @@ -73,6 +73,9 @@ {% include "common/adblock_modal.html" %} + + {% include "common/view_limit_modal.html" %} + diff --git a/tcf_website/templates/common/view_limit_modal.html b/tcf_website/templates/common/view_limit_modal.html new file mode 100644 index 000000000..1237bb50b --- /dev/null +++ b/tcf_website/templates/common/view_limit_modal.html @@ -0,0 +1,15 @@ + +{% load static %} +