Guest User

Untitled

a guest
May 20th, 2021
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*NOTE! won't account for hubs or small loops, tries to account for game-overs and other knowable turn-arounds*/
  2. ( function() {
  3. ignoreList = ["VersionHistoryOld", "Version History", "Start", "CharGenMain", "StoryMenu"];
  4. function crumb(title, pathText) {
  5.   this.title = title;
  6.   this.pathText = pathText;
  7.  
  8.   this.getPrviousCrumb = function() {  
  9.     var filterOutTitles = new Array(new RegExp("DD$"), new RegExp("Scrap"));
  10.     var filterOutText = new Array(new RegExp("\\[\\[.*Game Over.*\\]\\]"));
  11.     var linkRegex = new RegExp("\\[\\[.*" + this.title + "(?![0-9]).*\\]\\]", "g");
  12.     var linkTextEndRegex = new RegExp(this.title + "(?![0-9]).*\\]\\]", "g");
  13.     var previous = null;
  14.     for (const property in tale.passages) {
  15.       var p = tale.passages[property];   
  16.      
  17.       /* filter out random update and aggregation pages - no judgement */
  18.       var flotsam = false;
  19.       for(var i = 0; i < filterOutTitles.length; i++) {
  20.         if (p.title.search(filterOutTitles[i]) >= 0) flotsam = true;
  21.       }
  22.       if (flotsam) continue;
  23.      
  24.       /* filter out certain identifiable loop-backs */
  25.       for(var i = 0; i < filterOutText.length; i++) {
  26.         if (p.text.search(filterOutText[i]) >= 0) flotsam = true;
  27.       }
  28.       if (flotsam) continue;           
  29.      
  30.       if (ignoreList.includes(p.title)) continue;
  31.      
  32.       var linkStart = p.text.search(linkRegex);
  33.       if (linkStart != -1) {
  34.         var linkTextEnd = p.text.search(linkTextEndRegex);
  35.         var pathText = p.text.substr(linkStart + 2, linkTextEnd-linkStart - 3);
  36.         previous = new crumb(p.title, pathText);
  37.         break;
  38.       }
  39.     }    
  40.     return previous;
  41.   };
  42.  
  43.   this.clone = function() {
  44.       return new crumb(this.title, this.pathText);
  45.   };
  46. }
  47. function trail(){
  48.   this.crumbs = null;    
  49.   this.doTheThing = function() {
  50.     var irony = document.querySelector("#breadcrumbs");
  51.     if (irony) return;
  52.    
  53.     this.findPassages();
  54.     this.addCrumbsToPage();
  55.   }
  56.   this.findPassages = function() {
  57.     this.crumbs = new Array();
  58.     var title = document.querySelector(".passage").id.substr(7);
  59.     /* he's so hot right now */
  60.     var hansel = new crumb(title, "<You Are Here>");    
  61.     var previous = hansel.getPrviousCrumb();
  62.     while(previous) {
  63.       var exists = this.crumbs.filter(function(c) { return c.title == previous.title; }).length;
  64.       if (exists) break;
  65.      
  66.       this.crumbs.push(previous.clone());
  67.       previous = previous.getPrviousCrumb(); /*previous-er, if you will*/
  68.     }
  69.   };
  70.   this.addCrumbsToPage = function() {
  71.     var header = document.querySelector(".passage .header");
  72.     var container = document.createElement("div");
  73.     container.style.cssText = "padding: 0 0 10px 0; font-size:10pt;";
  74.     container.id = "breadcrumbs";
  75.     header.append(container);
  76.     var length = this.crumbs.length;
  77.     for (var i = length - 1; i >= 0; i--)
  78.     {
  79.       var link = document.createElement("a");
  80.       link.style.cssText = "cursor: pointer;";
  81.       link.dataset.index = i;
  82.       link.appendChild(document.createTextNode(this.crumbs[i].pathText));
  83.       container.appendChild(link);
  84.       container.appendChild(document.createElement("br"));
  85.          
  86.       var trail = this;
  87.       link.onclick = function() {
  88.         var title = trail.crumbs[this.dataset.index].title;
  89.         state.display(title);
  90.         setTimeout(function(){
  91.             trail.doTheThing();
  92.         }, 10);    
  93.       };
  94.     }
  95.   }
  96.   this.addNavigationToPage = function() {
  97.     var menu = document.querySelector("#storyMenu");
  98.     var after = Array.prototype.slice.call(document.querySelectorAll("#storyMenu a"))
  99.       .filter(function (el) {
  100.         return el.textContent === "Patreon";
  101.       })[0];
  102.     var crumbGenerator = document.createElement("a");
  103.  
  104.     menu.insertBefore(crumbGenerator, after);
  105.     menu.insertBefore(document.createElement("br"), after);
  106.     menu.insertBefore(document.createElement("br"), after);
  107.  
  108.     crumbGenerator.style.cssText = "cursor: pointer;";
  109.     crumbGenerator.appendChild(document.createTextNode("Breadcrumbs"));
  110.     var trail = this;
  111.     crumbGenerator.onclick = function() {  
  112.       trail.doTheThing();
  113.     };
  114.   }
  115.   this.overrideHistoryDisplay = function() {
  116.     var proxied_display = state.display;
  117.     var trail = this;
  118.     state.display = function(title, link, render) {
  119.       proxied_display.apply(this, arguments);
  120.       setTimeout(function(){
  121.         trail.addNavigationToPage();
  122.       }, 10);        
  123.     }
  124.   }
  125. }
  126.  
  127. var t = new trail();
  128. t.overrideHistoryDisplay();
  129. t.addNavigationToPage();
  130. window._dowhatnow = function() { debugger; } /* identify browser vm for investigatin */
  131. }());
Advertisement
Add Comment
Please, Sign In to add comment