3cx Click2Call

Ein Klick auf tel: und callto: Links soll über den 3cx Webclient einen Anruf starten.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        3cx Click2Call
// @namespace   3cx
// @match       https://*/*
// @grant       none
// @version     1.3
// @author      Jakob Schöttl
// @license MIT
// @description   Ein Klick auf tel: und callto: Links soll über den 3cx Webclient einen Anruf starten.
// ==/UserScript==

// requires jQuery

// Insert your 3cx base URL here:
const my3cxUrl = 'https://xxx.my3cx.de';

function fixTelLinks() {
  var telLinks = $('a[href^="tel:"], a[href^="callto:"]');
  console.log(telLinks);
  telLinks.each((idx, elem) => {
    var href = decodeURI(elem.href); // Fix: Wer würde denken, dass elem.href URI-encoded ist?
    href = my3cxUrl + '/webclient/#/call?phone=' + encodeURIComponent(href.replace(/[^0-9+]/g, ''));
    elem.href = href;
    elem.target = '_blank';
  });
}

$(function() {
  // Wait a short time before fixing links because some sites need
  // some time to build up the page (e.g. HTTP requests for JSON data)
  setTimeout(fixTelLinks, 1000);
});