Greasy Fork镜像 还支持 简体中文。

zendesk sidebar toggle

toggles the ticket left panel in zendesk

  1. // ==UserScript==
  2. // @name zendesk sidebar toggle
  3. // @namespace http://kah.pw
  4. // @description toggles the ticket left panel in zendesk
  5. // @include https://*.zendesk.com/agent/*
  6. // @version 2
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. // original inspiration from
  13. // https://gf.qytechs.cn/en/scripts/7307-reddit-hide-sidebar/code
  14.  
  15.  
  16. // wait for jquery, then wait for the nav on the left
  17. // how to wait:
  18. // - http://joanpiedra.com/jquery/greasemonkey/
  19. // - https://gist.github.com/BrockA/2625891
  20. (function GM_wait() {
  21. if (typeof unsafeWindow.jQuery == 'undefined') {
  22. window.setTimeout(GM_wait, 100);
  23. } else {
  24. $ = unsafeWindow.jQuery.noConflict(true);
  25. waitForKeyElements('#main_navigation', insertButton);
  26. }
  27. }) ();
  28.  
  29. // add button to the left nav
  30. function insertButton() {
  31. $('#main_navigation') .append($('<div/>', {
  32. html: 'Sidebar',
  33. id: 'sbToggle'
  34. }));
  35. $('#sbToggle')
  36. .height(24)
  37. .width(24)
  38. .css('margin', '20px 0px 10px 8px')
  39. .wrap('<a/>')
  40. .click(function () {
  41. doToggle()
  42. });
  43. }
  44.  
  45. // toggle visibility of left pane and position of ticket pane and footer
  46. function doToggle() {
  47. $('.ember-view.pane.left.section') .toggle();
  48. if ($('.ember-view.pane.left.section') .is(':visible')) {
  49. $('.ember-view.pane.right.section') .css('left', '390px');
  50. $('footer') .css('left', '390px');
  51. }
  52. else {
  53. $('.ember-view.pane.right.section') .css('left', '60px');
  54. $('footer') .css('left', '60px');
  55. }
  56. }
  57.  
  58. // via https://github.com/bdotdub/forrst-keyboard-navigation-greasemonkey
  59. var sbkeyNav = function() {
  60. document.addEventListener("keydown", function(e) {
  61. // pressed ctrl-alt-b
  62. if (e.keyCode == 66 && ! e.shiftKey && e.ctrlKey && e.altKey && ! e.metaKey) {
  63. //console.debug(e.keyCode);
  64. $('#sbToggle').click()
  65. }
  66. }, false);
  67. };
  68.  
  69.  
  70. function addJQuery(callback) {
  71. var script = document.createElement("script");
  72. var loadCallback = function() {
  73. var script = document.createElement("script");
  74. script.textContent = "(" + callback.toString() + ")();";
  75. document.body.appendChild(script);
  76. };
  77.  
  78. if (typeof($) !== undefined) {
  79. loadCallback();
  80. }
  81. else {
  82. script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js");
  83. script.addEventListener('load', function() {
  84. loadCallback();
  85. }, false);
  86.  
  87. document.body.appendChild(script);
  88. }
  89. }
  90.  
  91. addJQuery(sbkeyNav);
  92.  
  93.  
  94. /*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
  95. that detects and handles AJAXed content.
  96. Usage example:
  97. waitForKeyElements (
  98. "div.comments"
  99. , commentCallbackFunction
  100. );
  101. //--- Page-specific function to do what we want when the node is found.
  102. function commentCallbackFunction (jNode) {
  103. jNode.text ("This comment changed by waitForKeyElements().");
  104. }
  105. IMPORTANT: This function requires your script to have loaded jQuery.
  106. */
  107. function waitForKeyElements (
  108. selectorTxt, /* Required: The jQuery selector string that
  109. specifies the desired element(s).
  110. */
  111. actionFunction, /* Required: The code to run when elements are
  112. found. It is passed a jNode to the matched
  113. element.
  114. */
  115. bWaitOnce, /* Optional: If false, will continue to scan for
  116. new elements even after the first match is
  117. found.
  118. */
  119. iframeSelector /* Optional: If set, identifies the iframe to
  120. search.
  121. */
  122. ) {
  123. var targetNodes, btargetsFound;
  124. if (typeof iframeSelector == "undefined")
  125. targetNodes = $(selectorTxt);
  126. else
  127. targetNodes = $(iframeSelector).contents ()
  128. .find (selectorTxt);
  129. if (targetNodes && targetNodes.length > 0) {
  130. btargetsFound = true;
  131. /*--- Found target node(s). Go through each and act if they
  132. are new.
  133. */
  134. targetNodes.each ( function () {
  135. var jThis = $(this);
  136. var alreadyFound = jThis.data ('alreadyFound') || false;
  137. if (!alreadyFound) {
  138. //--- Call the payload function.
  139. var cancelFound = actionFunction (jThis);
  140. if (cancelFound)
  141. btargetsFound = false;
  142. else
  143. jThis.data ('alreadyFound', true);
  144. }
  145. } );
  146. }
  147. else {
  148. btargetsFound = false;
  149. }
  150. //--- Get the timer-control variable for this selector.
  151. var controlObj = waitForKeyElements.controlObj || {};
  152. var controlKey = selectorTxt.replace (/[^\w]/g, "_");
  153. var timeControl = controlObj [controlKey];
  154. //--- Now set or clear the timer as appropriate.
  155. if (btargetsFound && bWaitOnce && timeControl) {
  156. //--- The only condition where we need to clear the timer.
  157. clearInterval (timeControl);
  158. delete controlObj [controlKey]
  159. }
  160. else {
  161. //--- Set a timer, if needed.
  162. if ( ! timeControl) {
  163. timeControl = setInterval ( function () {
  164. waitForKeyElements ( selectorTxt,
  165. actionFunction,
  166. bWaitOnce,
  167. iframeSelector
  168. );
  169. },
  170. 300
  171. );
  172. controlObj [controlKey] = timeControl;
  173. }
  174. }
  175. waitForKeyElements.controlObj = controlObj;
  176. }
  177.  
  178.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址