Skip to content

Instantly share code, notes, and snippets.

@hurrifan1
Last active October 15, 2022 16:58
Show Gist options
  • Save hurrifan1/edb7eb161b1df0ef8a081bb4f7a4d997 to your computer and use it in GitHub Desktop.
Save hurrifan1/edb7eb161b1df0ef8a081bb4f7a4d997 to your computer and use it in GitHub Desktop.
JavaScript bookmarklet for opening an app in a new tab when that app is highlighted in the QMC
(async function run() {
/**
* Here we check to make sure we're on the Apps page of the QMC.
* If we aren't on the Apps page, we exit the script with an
* error message.
*/
if (window.location.pathname.includes("/qmc/apps") != true) {
let msg = "Only use this in the QMC!";
console.log("####", msg);
alert(msg);
return;
}
/**
* Here we are querying the webpage to find any rows in the
* Apps table that are currently selected/highlighted.
*/
let row = document.querySelectorAll("tr.row-selected");
/**
* Here we make sure that only one single row is selected.
* If no rows or more than one row are selected, we exit
* the script with an error message.
*/
if (row.length == 0) {
let msg = "No row selected!";
console.log("####", msg);
alert(msg);
return;
} else if (row.length > 1) {
let msg = "Make sure to only select one row.";
console.log("####", msg);
alert(msg);
return;
}
/**
* Here we get the `id` attribute of the selected App row,
* which is the AppID.
*/
let appId = row[0].id;
/**
* This uses the AppID from above to build a Qlik app URL
* that points to the Overview page for the app. To do this,
* it takes the current QMC URL, finds the `/qmc/apps` part,
* and takes everything to the left of it to get the
* `http(s)`, hostname, and virtual proxy. Then it tacks on
* the `sense/app/`, then the AppID we got from the selected
* App row in the QMC, and finally the `/overview` part.
*/
let appUrl = window.location.href.replace("/qmc/apps", `/sense/app/${appId}/overview`);
/** Here we tell the browser to open our new URL in a new tab. */
window.open(appUrl, "_blank");
/** Output a log message indicating success! */
console.log(`#### Successfully opened app ${appId} to have in a new tab!`);
})();
!async function e(){if(!0!=window.location.pathname.includes("/qmc/apps")){let l="Only use this in the QMC!";console.log("####",l),alert(l);return}let t=document.querySelectorAll("tr.row-selected");if(0==t.length){let n="No row selected!";console.log("####",n),alert(n);return}if(t.length>1){let o="Make sure to only select one row.";console.log("####",o),alert(o);return}let r=t[0].id,a=window.location.href.replace("/qmc/apps",`/sense/app/${r}/overview`);window.open(a,"_blank"),console.log(`#### Successfully opened app ${r} to have in a new tab!`)}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment