Соединить два скрипта.
Есть два скрипта. Один из них вытащен из Chrome плагина. Его роль добавлять в меню (при клике ПКМ) строку "позвонить" если выделен мобильный номер. Там уже как бы идет отсылка в софтфон. Второй же скрипт просто делает номера кликабельными и при клике отправляет их на сайт сипнета в строку номера абонента.
Из первого скрипта мне нравится оформление и структура. Из второго мне важна система работы скрипта(при клике отправляет номер на страницу сипнета). Можно ли как-нибудь совместить и получить идеальный вариант? Первый скрипт: chrome.extension.onRequest.addListener(OnRequestListener); function OnRequestListener(request, sender, callback) { if (request.action == "oktell_menu_cliked"){ var phone_number = ""; if (request.source == "link"){ var loc_abs_part = document.location.protocol + "//" + document.location.host + "/"; var href = request.data.replace(loc_abs_part.toLowerCase(), ""); var xpath = "//a[contains(@href, '" + href + "') and @class='oktell_call']"; var oktell_links = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if (oktell_links.snapshotLength > 0){ phone_number = href; } } else if (request.source == "text"){ phone_number = request.data; } if (phone_number != ""){ var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "http://127.0.0.1:4059/callto?number=" + phone_number, true); xmlhttp.onreadystatechange = function(data) { if (xmlhttp.readyState == 4) { } } xmlhttp.send(null); } } }; И соответственно второй скрипт: var hash = location.hash.split('#')[1]; (function () { const numberRegex = /(?!:\A|\s)(?!(\d{1,6}\s+\D)|((\d{1,2}\s+){2,2}))(((\+\d{1,3})|(\(\+\d{1,3}\)))\s*)?((\d{1,6})|(\(\d{1,6}\)))\/?(([ -]?)\d{1,5}){1,5}((\s*(#|x|(ext))\.?\s*)\d{1,5})?(?!:(\Z|\w|\b\s))/ig location.hash=''; if(location.href=='https://customer.sipnet.ru/cabinet/#') { var search = document.getElementById('search'); search.value = hash; } // tags we will scan looking for un-hyperlinked urls var allowedParents = [ "abbr", "acronym", "address", "applet", "b", "bdo", "big", "blockquote", "body", "caption", "center", "cite", "code", "dd", "del", "div", "dfn", "dt", "em", "fieldset", "font", "form", "h1", "h2", "h3", "h4", "h5", "h6", "i", "iframe", "ins", "kdb", "li", "nobr", "object", "pre", "p", "q", "samp", "small", "span", "strike", "s", "strong", "sub", "sup", "td", "th", "tt", "u", "var" ]; var xpath = "//text()[(parent::" + allowedParents.join(" or parent::") + ")" + //" and contains(translate(., 'HTTP', 'http'), 'http')" + "]"; var candidates = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for (var cand = null, i = 0; (cand = candidates.snapshotItem(i)); i++) { if (numberRegex.test(cand.nodeValue)) { var span = document.createElement("span"); var source = cand.nodeValue; cand.parentNode.replaceChild(span, cand); numberRegex.lastIndex = 0; for (var match = null, lastLastIndex = 0; (match = numberRegex.exec(source)); ) { span.appendChild(document.createTextNode(source.substring(lastLastIndex, match.index))); var a = document.createElement("a"); a.setAttribute("href", "https://customer.sipnet.ru/cabinet/#"+match[0]); //a.setAttribute("arg", match[0]); //a.addEventListener("click", function(eve){doCallBack(this.getAttribute("arg"),eve);} , true) a.appendChild(document.createTextNode(match[0])); span.appendChild(a); lastLastIndex = numberRegex.lastIndex; } span.appendChild(document.createTextNode(source.substring(lastLastIndex))); span.normalize(); } } })(); |
ответ: можно.
|
Готов уже оплатить помощь.
|
Часовой пояс GMT +3, время: 22:38. |