Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*NOTE! won't account for hubs or small loops, tries to account for game-overs and other knowable turn-arounds*/
- ( function() {
- ignoreList = ["VersionHistoryOld", "Version History", "Start", "CharGenMain", "StoryMenu"];
- function crumb(title, pathText) {
- this.title = title;
- this.pathText = pathText;
- this.getPrviousCrumb = function() {
- var filterOutTitles = new Array(new RegExp("DD$"), new RegExp("Scrap"));
- var filterOutText = new Array(new RegExp("\\[\\[.*Game Over.*\\]\\]"));
- var linkRegex = new RegExp("\\[\\[.*" + this.title + "(?![0-9]).*\\]\\]", "g");
- var linkTextEndRegex = new RegExp(this.title + "(?![0-9]).*\\]\\]", "g");
- var previous = null;
- for (const property in tale.passages) {
- var p = tale.passages[property];
- /* filter out random update and aggregation pages - no judgement */
- var flotsam = false;
- for(var i = 0; i < filterOutTitles.length; i++) {
- if (p.title.search(filterOutTitles[i]) >= 0) flotsam = true;
- }
- if (flotsam) continue;
- /* filter out certain identifiable loop-backs */
- for(var i = 0; i < filterOutText.length; i++) {
- if (p.text.search(filterOutText[i]) >= 0) flotsam = true;
- }
- if (flotsam) continue;
- if (ignoreList.includes(p.title)) continue;
- var linkStart = p.text.search(linkRegex);
- if (linkStart != -1) {
- var linkTextEnd = p.text.search(linkTextEndRegex);
- var pathText = p.text.substr(linkStart + 2, linkTextEnd-linkStart - 3);
- previous = new crumb(p.title, pathText);
- break;
- }
- }
- return previous;
- };
- this.clone = function() {
- return new crumb(this.title, this.pathText);
- };
- }
- function trail(){
- this.crumbs = null;
- this.doTheThing = function() {
- var irony = document.querySelector("#breadcrumbs");
- if (irony) return;
- this.findPassages();
- this.addCrumbsToPage();
- }
- this.findPassages = function() {
- this.crumbs = new Array();
- var title = document.querySelector(".passage").id.substr(7);
- /* he's so hot right now */
- var hansel = new crumb(title, "<You Are Here>");
- var previous = hansel.getPrviousCrumb();
- while(previous) {
- var exists = this.crumbs.filter(function(c) { return c.title == previous.title; }).length;
- if (exists) break;
- this.crumbs.push(previous.clone());
- previous = previous.getPrviousCrumb(); /*previous-er, if you will*/
- }
- };
- this.addCrumbsToPage = function() {
- var header = document.querySelector(".passage .header");
- var container = document.createElement("div");
- container.style.cssText = "padding: 0 0 10px 0; font-size:10pt;";
- container.id = "breadcrumbs";
- header.append(container);
- var length = this.crumbs.length;
- for (var i = length - 1; i >= 0; i--)
- {
- var link = document.createElement("a");
- link.style.cssText = "cursor: pointer;";
- link.dataset.index = i;
- link.appendChild(document.createTextNode(this.crumbs[i].pathText));
- container.appendChild(link);
- container.appendChild(document.createElement("br"));
- var trail = this;
- link.onclick = function() {
- var title = trail.crumbs[this.dataset.index].title;
- state.display(title);
- setTimeout(function(){
- trail.doTheThing();
- }, 10);
- };
- }
- }
- this.addNavigationToPage = function() {
- var menu = document.querySelector("#storyMenu");
- var after = Array.prototype.slice.call(document.querySelectorAll("#storyMenu a"))
- .filter(function (el) {
- return el.textContent === "Patreon";
- })[0];
- var crumbGenerator = document.createElement("a");
- menu.insertBefore(crumbGenerator, after);
- menu.insertBefore(document.createElement("br"), after);
- menu.insertBefore(document.createElement("br"), after);
- crumbGenerator.style.cssText = "cursor: pointer;";
- crumbGenerator.appendChild(document.createTextNode("Breadcrumbs"));
- var trail = this;
- crumbGenerator.onclick = function() {
- trail.doTheThing();
- };
- }
- this.overrideHistoryDisplay = function() {
- var proxied_display = state.display;
- var trail = this;
- state.display = function(title, link, render) {
- proxied_display.apply(this, arguments);
- setTimeout(function(){
- trail.addNavigationToPage();
- }, 10);
- }
- }
- }
- var t = new trail();
- t.overrideHistoryDisplay();
- t.addNavigationToPage();
- window._dowhatnow = function() { debugger; } /* identify browser vm for investigatin */
- }());
Advertisement
Add Comment
Please, Sign In to add comment