// ==UserScript== // @name CS UI Widgets Information // @namespace mailto:fprantl@opentext.com // @version 0.3 // @description Shows information about a CS UI Widgets authenticated session. // It makes a call to the CS REST API using the CS UI Widgets to find // out the name of the Personal Volume of the authenticated user which // usually includes the user name. Before you execute it, authenticate // the CS UI Widgets on your page, otherwise you get the login dialog. // @match *://*/* // @copyright (c) 2013-2014 Ferdinand Prantl, OpenText GmbH // @downloadURL https://update.greasyfork.icu/scripts/2642/CS%20UI%20Widgets%20Information.user.js // @updateURL https://update.greasyfork.icu/scripts/2642/CS%20UI%20Widgets%20Information.meta.js // ==/UserScript== if (typeof csui !== "undefined") { var modules = csui.require.defined("lib/jquery") && ["lib/jquery", "util/connector", "model/volume"] || ["csui/lib/jquery", "csui/util/connector", "csui/model/volume"]; csui.require(modules, function($, Connector, VolumeModel) { // Declare the place with all CS UI Widgets information, the definition list // with entries for every stored authenticated session and a progress indicator. var place, list, progress; // Adds information about a CS UI Widgets session identified by the CS // REST API URL to the definition list function addSessionInformation(url, last) { // Create a connector object for the REST API URL; the supportPath // will not be used in this scenario; just not leave it undefined var connector = new Connector({ connection: { url: url, supportPath: "/img" } }), // Declare an object referring to the personal volume of the current user personalVolume = new VolumeModel( { type: 142 }, { connector: connector } ); // Fetch the personal volume information; authentication will be performed // on demand and if there is already an authenticated session in the session // storage of the web browser, there will be no login prompt. personalVolume.fetch({ success: function() { console.log("Personal volume on " + url + ":"); console.log(personalVolume); // Append a new entry to the definition list with the session information // containing just the name of the personal volume for now; this name // usually contains the user name and serves as a trick how to learn it // until there is a REST API request available which provides information // about the authenticated user. $("
").text("URL: " + url).appendTo(list); $("
").text("Personal Volume: " + personalVolume.get("name")).appendTo(list); if (last) { progress.hide(); } }, error: function(error) { // Append the message to the definition list with the session information $("
").text("URL: " + url).appendTo(list); $("
").text(error.toString()).appendTo(list); if (last) { progress.hide(); } } }); } // Divide the information from the page content above $("
").appendTo(document.body); // Encapsulate the CS UI Widgets information in a jQuery UI styled element place = $("
", { "class": "ui-widget" }).appendTo(document.body); $("

").text("CS UI Widgets").appendTo(place); // Add a button tu refresh the information displayed below $("