Skip to content

Instantly share code, notes, and snippets.

@alfredwesterveld
Created May 4, 2017 16:48
Show Gist options
  • Save alfredwesterveld/d8b25979ff1a54613f3a760707918897 to your computer and use it in GitHub Desktop.
Save alfredwesterveld/d8b25979ff1a54613f3a760707918897 to your computer and use it in GitHub Desktop.
requirebin sketch
const browser = require('detect-browser');
if (browser) {
console.log(browser.name);
console.log(browser.version);
}
setTimeout(function(){require=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){module.exports=function detectBrowser(userAgentString){if(!userAgentString)return null;var browsers=[["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+)\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/]];return browsers.map(function(rule){if(rule[1].test(userAgentString)){var match=rule[1].exec(userAgentString);var version=match&&match[1].split(/[._]/).slice(0,3);if(version&&version.length<3){Array.prototype.push.apply(version,version.length==1?[0,0]:[0])}return{name:rule[0],version:version.join(".")}}}).filter(Boolean).shift()}},{}],"detect-browser":[function(require,module,exports){var detectBrowser=require("./lib/detectBrowser");var agent;if(typeof navigator!=="undefined"&&navigator){agent=navigator.userAgent}module.exports=detectBrowser(agent)},{"./lib/detectBrowser":1}]},{},[]);const browser=require("detect-browser");if(browser){console.log(browser.name);console.log(browser.version)}},0);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"detect-browser": "1.7.0"
}
}
<!-- contents of this file will be placed inside the <body> -->
<canvas id="c1" width="100" height="100" style="border: black 3px solid;"></canvas>
<button id="get-data">get Data</button>
<div id="data"></div>
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment