Protocol Check

Custom Protocol Detection in Browser

لا ينبغي أن لا يتم تثبيت هذا السكريت مباشرة. هو مكتبة لسكبتات لتشمل مع التوجيه الفوقية // @require https://update.greasyfork.org/scripts/373130/635816/Protocol%20Check.js

  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.protocolCheck = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. function _registerEvent(target, eventType, cb) {
  3. if (target.addEventListener) {
  4. target.addEventListener(eventType, cb);
  5. return {
  6. remove: function () {
  7. target.removeEventListener(eventType, cb);
  8. }
  9. };
  10. } else {
  11. target.attachEvent(eventType, cb);
  12. return {
  13. remove: function () {
  14. target.detachEvent(eventType, cb);
  15. }
  16. };
  17. }
  18. }
  19.  
  20. function _createHiddenIframe(target, uri) {
  21. var iframe = document.createElement("iframe");
  22. iframe.src = uri;
  23. iframe.id = "hiddenIframe";
  24. iframe.style.display = "none";
  25. target.appendChild(iframe);
  26.  
  27. return iframe;
  28. }
  29.  
  30. function openUriWithHiddenFrame(uri, failCb, successCb) {
  31.  
  32. var timeout = setTimeout(function () {
  33. failCb();
  34. handler.remove();
  35. }, 1000);
  36.  
  37. var iframe = document.querySelector("#hiddenIframe");
  38. if (!iframe) {
  39. iframe = _createHiddenIframe(document.body, "about:blank");
  40. }
  41.  
  42. var handler = _registerEvent(window, "blur", onBlur);
  43.  
  44. function onBlur() {
  45. clearTimeout(timeout);
  46. handler.remove();
  47. successCb();
  48. }
  49.  
  50. iframe.contentWindow.location.href = uri;
  51. }
  52.  
  53. function openUriWithTimeoutHack(uri, failCb, successCb) {
  54. var timeout = setTimeout(function () {
  55. failCb();
  56. handler.remove();
  57. }, 1000);
  58.  
  59. //handle page running in an iframe (blur must be registered with top level window)
  60. var target = window;
  61. while (target != target.parent) {
  62. target = target.parent;
  63. }
  64.  
  65. var handler = _registerEvent(target, "blur", onBlur);
  66.  
  67. function onBlur() {
  68. clearTimeout(timeout);
  69. handler.remove();
  70. successCb();
  71. }
  72.  
  73. window.location = uri;
  74. }
  75.  
  76. function openUriUsingFirefox(uri, failCb, successCb) {
  77. var iframe = document.querySelector("#hiddenIframe");
  78.  
  79. if (!iframe) {
  80. iframe = _createHiddenIframe(document.body, "about:blank");
  81. }
  82.  
  83. try {
  84. iframe.contentWindow.location.href = uri;
  85. successCb();
  86. } catch (e) {
  87. if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
  88. failCb();
  89. }
  90. }
  91. }
  92.  
  93. function openUriUsingIEInOlderWindows(uri, failCb, successCb) {
  94. if (getInternetExplorerVersion() === 10) {
  95. openUriUsingIE10InWindows7(uri, failCb, successCb);
  96. } else if (getInternetExplorerVersion() === 9 || getInternetExplorerVersion() === 11) {
  97. openUriWithHiddenFrame(uri, failCb, successCb);
  98. } else {
  99. openUriInNewWindowHack(uri, failCb, successCb);
  100. }
  101. }
  102.  
  103. function openUriUsingIE10InWindows7(uri, failCb, successCb) {
  104. var timeout = setTimeout(failCb, 1000);
  105. window.addEventListener("blur", function () {
  106. clearTimeout(timeout);
  107. successCb();
  108. });
  109.  
  110. var iframe = document.querySelector("#hiddenIframe");
  111. if (!iframe) {
  112. iframe = _createHiddenIframe(document.body, "about:blank");
  113. }
  114. try {
  115. iframe.contentWindow.location.href = uri;
  116. } catch (e) {
  117. failCb();
  118. clearTimeout(timeout);
  119. }
  120. }
  121.  
  122. function openUriInNewWindowHack(uri, failCb, successCb) {
  123. var myWindow = window.open('', '', 'width=0,height=0');
  124.  
  125. myWindow.document.write("<iframe src='" + uri + "'></iframe>");
  126.  
  127. setTimeout(function () {
  128. try {
  129. myWindow.location.href;
  130. myWindow.setTimeout("window.close()", 1000);
  131. successCb();
  132. } catch (e) {
  133. myWindow.close();
  134. failCb();
  135. }
  136. }, 1000);
  137. }
  138.  
  139. function openUriWithMsLaunchUri(uri, failCb, successCb) {
  140. navigator.msLaunchUri(uri,
  141. successCb,
  142. failCb
  143. );
  144. }
  145.  
  146. function checkBrowser() {
  147. var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
  148. var ua = navigator.userAgent.toLowerCase();
  149. return {
  150. isOpera : isOpera,
  151. isFirefox : typeof InstallTrigger !== 'undefined',
  152. isSafari : (~ua.indexOf('safari') && !~ua.indexOf('chrome')) || Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0,
  153. isIOS : /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream,
  154. isChrome : !!window.chrome && !isOpera,
  155. isIE : /*@cc_on!@*/false || !!document.documentMode // At least IE6
  156. }
  157. }
  158.  
  159. function getInternetExplorerVersion() {
  160. var rv = -1;
  161. if (navigator.appName === "Microsoft Internet Explorer") {
  162. var ua = navigator.userAgent;
  163. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  164. if (re.exec(ua) != null)
  165. rv = parseFloat(RegExp.$1);
  166. }
  167. else if (navigator.appName === "Netscape") {
  168. var ua = navigator.userAgent;
  169. var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
  170. if (re.exec(ua) != null) {
  171. rv = parseFloat(RegExp.$1);
  172. }
  173. }
  174. return rv;
  175. }
  176.  
  177. module.exports = function(uri, failCb, successCb, unsupportedCb) {
  178. function failCallback() {
  179. failCb && failCb();
  180. }
  181.  
  182. function successCallback() {
  183. successCb && successCb();
  184. }
  185.  
  186. if (navigator.msLaunchUri) { //for IE and Edge in Win 8 and Win 10
  187. openUriWithMsLaunchUri(uri, failCb, successCb);
  188. } else {
  189. var browser = checkBrowser();
  190.  
  191. if (browser.isFirefox) {
  192. openUriUsingFirefox(uri, failCallback, successCallback);
  193. } else if (browser.isChrome || browser.isIOS) {
  194. openUriWithTimeoutHack(uri, failCallback, successCallback);
  195. } else if (browser.isIE) {
  196. openUriUsingIEInOlderWindows(uri, failCallback, successCallback);
  197. } else if (browser.isSafari) {
  198. openUriWithHiddenFrame(uri, failCallback, successCallback);
  199. } else {
  200. unsupportedCb();
  201. //not supported, implement please
  202. }
  203. }
  204. }
  205.  
  206. },{}]},{},[1])(1)
  207. });