Intercom Unassign & Close

Button that allows you to unassign & then close a conversation

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

Advertisement:

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

Advertisement:

// ==UserScript==
// https://stackoverflow.com/questions/6480082/add-a-javascript-button-using-greasemonkey-or-tampermonkey
// @name         Intercom Unassign & Close
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Button that allows you to unassign & then close a conversation
// @author       Waclock
// @match        https://app.intercom.com/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://greasyfork.org/scripts/6250-waitforkeyelements/code/waitForKeyElements.js?version=23756
// @grant    GM_addStyle
// ==/UserScript==

waitForKeyElements (".conversation__card__actions-wrapper.u__ml__10.u__cf", setCAUButton);
waitForKeyElements (".inbox__card__header__actions:not([data-intercom-target='close-conversaton']) button", disableCAUButton);
waitForKeyElements ("[data-intercom-target='close-conversaton'] button", enableCAUButton);

function enableCAUButton(){
  if($("[data-intercom-target='close-conversaton'] button").length > 0){
      $('#cau-button').removeClass('o__disabled');
  }
}

function disableCAUButton(){
 if($(".inbox__card__header__actions button").length > 0){
     $('#cau-button').addClass('o__disabled');
 }
}

function setCAUButton(){
    var $ = unsafeWindow.jQuery;
    var zNode = document.createElement ('div');
    zNode.innerHTML = '<button class="btn o__primary" id="cau-button" type="button">'
        + 'Close & Unassign</button>';
    zNode.setAttribute ('id', 'close-and-unassign-container');

    var userOptionsDiv = document.getElementsByClassName("conversation__card__actions-wrapper u__ml__10 u__cf")[0];
    userOptionsDiv.appendChild(zNode);

    $('#cau-button').on('click', ButtonClickAction);


    function ButtonClickAction (zEvent) {
        $("button [data-assignee]").click();
        $('body').addClass('cau-hide');
        setTimeout(() => {
            $("[data-dropdown-item='Unassigned']").click();
            $("[data-intercom-target='close-conversaton'] button").click();
            $('body').removeClass('cau-hide');
        }, 100)
    }
}

//--- Style our newly added elements using CSS.
GM_addStyle ( `
    .cau-hide .popover__content-container {
       opacity: 0.01 !important;
       cursor: default !important;
    }

    #close-and-unassign-container {
        display:               inline-block;
    }
    #cau-button {
        cursor:                 pointer;
    }
` );