Created
August 3, 2018 08:27
-
-
Save Transfusion/2f29daf2e611069232c850a2e384df29 to your computer and use it in GitHub Desktop.
InfoViz Display Nav Injected JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Petronas InfoViz navigation script | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.1 | |
| // @description Demonstration of adding unique URL to a dynamic javascript page | |
| // @author bryan.wyern1@gmail.com | |
| // @match http://10.14.160.41/viz* | |
| // @grant none | |
| // ==/UserScript== | |
| const defaultTopNavURL = ''; | |
| const defaultNavURL = ''; | |
| function getQueryVariable(variable) { | |
| var query = window.location.search.substring(1); | |
| var vars = query.split('&'); | |
| for (var i = 0; i < vars.length; i++) { | |
| var pair = vars[i].split('='); | |
| if (decodeURIComponent(pair[0]) == variable) { | |
| return decodeURIComponent(pair[1]); | |
| } | |
| } | |
| console.log('Query variable %s not found', variable); | |
| } | |
| function sleep(ms) { | |
| return new Promise(resolve => setTimeout(resolve, ms)); | |
| } | |
| function getBaseUrl() { | |
| var getUrl = window.location; | |
| var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1]; | |
| return baseUrl; | |
| } | |
| (function() { | |
| 'use strict'; | |
| var navURL = getQueryVariable('navPage'); | |
| navURL = navURL ? navURL : defaultNavURL; | |
| var topNavURL = getQueryVariable('topNavPage'); | |
| topNavURL = topNavURL ? topNavURL : defaultTopNavURL; | |
| var tabTitle = getQueryVariable('windowName'); | |
| tabTitle = tabTitle ? tabTitle : document.title; | |
| var refreshOnce = getQueryVariable('refreshOnce'); | |
| refreshOnce = (refreshOnce == 'true') ? true : false; | |
| document.title = tabTitle; | |
| $().selectTopNav(topNavURL); | |
| setTimeout(function(){ | |
| if (refreshOnce) { | |
| location.href = getBaseUrl() + "?" + $.param({navPage:navURL, topNavPage: topNavURL, windowName: tabTitle, refreshOnce: false }); | |
| } | |
| else { | |
| $().selectSubNav(navURL); | |
| console.log('inside settimeout'); | |
| } | |
| }, 6000); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment