Skip to content

Instantly share code, notes, and snippets.

@Transfusion
Created August 3, 2018 08:27
Show Gist options
  • Select an option

  • Save Transfusion/2f29daf2e611069232c850a2e384df29 to your computer and use it in GitHub Desktop.

Select an option

Save Transfusion/2f29daf2e611069232c850a2e384df29 to your computer and use it in GitHub Desktop.
InfoViz Display Nav Injected JS
// ==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