diff --git a/servicenow-toc.user.js b/servicenow-toc.user.js index 3b83587..93c0f60 100644 --- a/servicenow-toc.user.js +++ b/servicenow-toc.user.js @@ -1,427 +1,427 @@ // ==UserScript== // @name ServiceNow Table of Contents -// @downloadURL todo +// @downloadURL https://c4science.ch/diffusion/743/browse/master/servicenow-toc.user.js // @namespace EPFL // @version 0.1 // @description Runs when a knowledge article is edited. Add a button in the Wysiwyg editor (TinyMCE) "Create or update table of contents". When pressed, creates unique ids on titles contained in the text editor and then insert a table of content with anchor links. // @author Laurent Indermühle, Julien Grondier, Frederik Künstner // @match https://it.epfl.ch/backoffice/kb_knowledge.do* // @grant none // ==/UserScript== /** * COMPATIBILITY * * V0.1 : ServiceNow Fuji */ /** * LOG * * 2016.08.09 L.Indermühle: Published on C4Science.ch * 2016.08.08 L.Indermühle: Initial version */ (function() { 'use strict'; /** * Window = kb_knowledge.do (because of the @match in head of this script) * * The wysiwyg editor's iframe container has the id #kb_knowledge.text_ifr * ServiceNow Fuji (early 2016) : window.frames[1] * This script is in the scope of a parent iframe called "gsft_main". */ function getDocument() { var frame_id = 'kb_knowledge.text_ifr'; for (var i in window.frames) { if (window.frames[i].frameElement.id == frame_id) { return window.frames[i].document; } } } /** * @return string 'fr' or 'en' */ function getLang() { return document.getElementById('kb_knowledge.language').value; } /** * tocTitle prints the header of the navigation bloc * @return {string} [description] */ function tocTitle() { if (getLang() == 'fr') { return 'Sommaire'; } else if (getLang() == 'en') { return 'Table of contents'; } } /** * Generate a unique hash */ function generateUID() { return ( "0000" + (Math.random()*Math.pow(36,4) << 0).toString(36)).slice(-4); } /** * Count