Help fix a broken JS script to keep dropdown menu open on new page

Here is the read-only link for the current site I’m working on: https://preview.webflow.com/preview/fictiv-doc-2?utm_source=fictiv-doc-2&preview=3ca6674fceec3a673df755172198eb04

Live link: http://fictiv-doc-2.webflow.io/

There was a custom script for this site that allowed the dropdown menu in the sidebar to remain open even after the user clicked to a new page. We recently rearranged the hierarchy of the menu items to what you see in the read only link above and now the custom script is broken. I’m not a JS gal and have no idea how to update this.

This is the script that used to work.

<script>
$(document).ready(function(){
var main_category=$('.doc-title')[0].dataset.category;
var current_category=$('.doc-title')[0].dataset.title;
if(main_category !== "")
{
 $('.sub-menu-item').each(function(index,item){
   if($(item).text() == current_category)
   {
   	$(item).addClass('current');
   }
 });
  $('.sub-menu-item-indented').each(function(index,item){
   if($(item).text() == current_category)
   {
   	$(item).addClass('current');
   }
 });
}

if(main_category !== ""){
$('.menu-item').each(function(index,item){
	var menu_item = $(item).children('.menu-item-title').text().toLowerCase();
	if( menu_item == main_category)
  {
   	 $('.w-dropdown-toggle').removeClass('w--open');
     $('.w-dropdown-list').removeClass('w--open');
     $(this).addClass('w--open');
     $(this).siblings().addClass('w--open');
  }
});}

$('.menu-item').click(function(){
	 $('.w-dropdown-toggle').removeClass('w--open');
   $('.w-dropdown-list').removeClass('w--open');
   $(this).children('.w-dropdown-toggle').addClass('w--open');
   $(this).children('.w-dropdown-list').addClass('w--open');
})
});
</script>

You can actually see it working in an old project that still exists in our webflow account. This is how the menu on the main site used to be organized before being updated. Read only link: https://preview.webflow.com/preview/fictiv-doc?utm_source=fictiv-doc&preview=d177c08b40ea8983278448c0bf2dfd01

Live link: http://fictiv-doc.webflow.io

For the updated site, we just want the relevant dropdown to remain open. Can anyone help with updating this script?