Created
December 25, 2018 04:47
-
-
Save stevenhao/2eb027528ecaf0e834cbb061f048f41a to your computer and use it in GitHub Desktop.
Imports lodash (and any other npm package) via tampermonkey & requirify.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Require Lodash | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Asynchronously inject lodash into all webpages | |
// @author Steven Hao | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== | |
(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){ | |
!function(e,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?module.exports=r():e.returnExports=r()}(this,function(){function e(n,i){if("function"!=typeof i)throw new Error("Bad callback given: "+i);if(!n)throw new Error("No options given");var s=n.onResponse;if(n="string"==typeof n?{uri:n}:JSON.parse(JSON.stringify(n)),n.onResponse=s,n.verbose&&(e.log=o()),n.url&&(n.uri=n.url,delete n.url),!n.uri&&""!==n.uri)throw new Error("options.uri is a required argument");if("string"!=typeof n.uri)throw new Error("options.uri must be a string");for(var d=["proxy","_redirectsFollowed","maxRedirects","followRedirect"],u=0;u<d.length;u++)if(n[d[u]])throw new Error("options."+d[u]+" is not supported");if(n.callback=i,n.method=n.method||"GET",n.headers=n.headers||{},n.body=n.body||null,n.timeout=n.timeout||e.DEFAULT_TIMEOUT,n.headers.host)throw new Error("Options.headers.host is not supported");n.json&&(n.headers.accept=n.headers.accept||"application/json","GET"!==n.method&&(n.headers["content-type"]="application/json"),"boolean"!=typeof n.json?n.body=JSON.stringify(n.json):"string"!=typeof n.body&&(n.body=JSON.stringify(n.body)));var c=function(e){var r=[];for(var t in e)e.hasOwnProperty(t)&&r.push(encodeURIComponent(t)+"="+encodeURIComponent(e[t]));return r.join("&")};if(n.qs){var f="string"==typeof n.qs?n.qs:c(n.qs);-1!==n.uri.indexOf("?")?n.uri=n.uri+"&"+f:n.uri=n.uri+"?"+f}var p=function(e){var r={};r.boundry="-------------------------------"+Math.floor(1e9*Math.random());var t=[];for(var o in e)e.hasOwnProperty(o)&&t.push("--"+r.boundry+'\nContent-Disposition: form-data; name="'+o+'"\n\n'+e[o]+"\n");return t.push("--"+r.boundry+"--"),r.body=t.join(""),r.length=r.body.length,r.type="multipart/form-data; boundary="+r.boundry,r};if(n.form){if("string"==typeof n.form)throw"form name unsupported";if("POST"===n.method){var l=(n.encoding||"application/x-www-form-urlencoded").toLowerCase();switch(n.headers["content-type"]=l,l){case"application/x-www-form-urlencoded":n.body=c(n.form).replace(/%20/g,"+");break;case"multipart/form-data":var h=p(n.form);n.body=h.body,n.headers["content-type"]=h.type;break;default:throw new Error("unsupported encoding:"+l)}}}return n.onResponse=n.onResponse||t,n.onResponse===!0&&(n.onResponse=i,n.callback=t),!n.headers.authorization&&n.auth&&(n.headers.authorization="Basic "+a(n.auth.username+":"+n.auth.password)),r(n)}function r(r){function t(){f=!0;var t=new Error("ETIMEDOUT");return t.code="ETIMEDOUT",t.duration=r.timeout,e.log.error("Timeout",{id:c._id,milliseconds:r.timeout}),r.callback(t,c)}function o(t){if(f)return e.log.debug("Ignoring timed out state change",{state:c.readyState,id:c.id});if(e.log.debug("State change",{state:c.readyState,id:c.id,timed_out:f}),c.readyState===s.OPENED){e.log.debug("Request started",{id:c.id});for(var o in r.headers)c.setRequestHeader(o,r.headers[o])}else c.readyState===s.HEADERS_RECEIVED?n():c.readyState===s.LOADING?(n(),a()):c.readyState===s.DONE&&(n(),a(),d())}function n(){if(!y.response){if(y.response=!0,e.log.debug("Got response",{id:c.id,status:c.status}),clearTimeout(c.timeoutTimer),c.statusCode=c.status,p&&0==c.statusCode){var t=new Error("CORS request rejected: "+r.uri);return t.cors="rejected",y.loading=!0,y.end=!0,r.callback(t,c)}r.onResponse(null,c)}}function a(){y.loading||(y.loading=!0,e.log.debug("Response body loading",{id:c.id}))}function d(){if(!y.end){if(y.end=!0,e.log.debug("Request done",{id:c.id}),c.body=c.responseText,r.json)try{c.body=JSON.parse(c.responseText)}catch(t){return r.callback(t,c)}r.callback(null,c,c.body)}}var c=new s,f=!1,p=i(r.uri),l="withCredentials"in c;if(u+=1,c.seq_id=u,c.id=u+": "+r.method+" "+r.uri,c._id=c.id,p&&!l){var h=new Error("Browser does not support cross-origin request: "+r.uri);return h.cors="unsupported",r.callback(h,c)}c.timeoutTimer=setTimeout(t,r.timeout);var y={response:!1,loading:!1,end:!1};return c.onreadystatechange=o,c.open(r.method,r.uri,!0),p&&(c.withCredentials=!!r.withCredentials),c.send(r.body),c}function t(){}function o(){var e,r,o={},i=["trace","debug","info","warn","error"];for(r=0;r<i.length;r++)e=i[r],o[e]=t,"undefined"!=typeof console&&console&&console[e]&&(o[e]=n(console,e));return o}function n(e,r){function t(t,o){return"object"==typeof o&&(t+=" "+JSON.stringify(o)),e[r].call(e,t)}return t}function i(e){var r,t=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/;try{r=location.href}catch(o){r=document.createElement("a"),r.href="",r=r.href}var n=t.exec(r.toLowerCase())||[],i=t.exec(e.toLowerCase()),a=!(!i||i[1]==n[1]&&i[2]==n[2]&&(i[3]||("http:"===i[1]?80:443))==(n[3]||("http:"===n[1]?80:443)));return a}function a(e){var r,t,o,n,i,a,s,d,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c=0,f=0,p="",l=[];if(!e)return e;do r=e.charCodeAt(c++),t=e.charCodeAt(c++),o=e.charCodeAt(c++),d=r<<16|t<<8|o,n=d>>18&63,i=d>>12&63,a=d>>6&63,s=63&d,l[f++]=u.charAt(n)+u.charAt(i)+u.charAt(a)+u.charAt(s);while(c<e.length);switch(p=l.join(""),e.length%3){case 1:p=p.slice(0,-2)+"==";break;case 2:p=p.slice(0,-1)+"="}return p}var s=XMLHttpRequest;if(!s)throw new Error("missing XMLHttpRequest");e.log={trace:t,debug:t,info:t,warn:t,error:t};var d=18e4,u=0;e.withCredentials=!1,e.DEFAULT_TIMEOUT=d,e.defaults=function(r,t){var o=function(e){var t=function(t,o){t="string"==typeof t?{uri:t}:JSON.parse(JSON.stringify(t));for(var n in r)void 0===t[n]&&(t[n]=r[n]);return e(t,o)};return t},n=o(e);return n.get=o(e.get),n.post=o(e.post),n.put=o(e.put),n.head=o(e.head),n};var c=["get","put","post","head"];return c.forEach(function(r){var t=r.toUpperCase(),o=r.toLowerCase();e[o]=function(r){"string"==typeof r?r={method:t,uri:r}:(r=JSON.parse(JSON.stringify(r)),r.method=t);var o=[r].concat(Array.prototype.slice.apply(arguments,[1]));return e.apply(this,o)}}),e.couch=function(r,o){function n(e,r,t){if(e)return o(e,r,t);if((r.statusCode<200||r.statusCode>299)&&t.error){e=new Error("CouchDB error: "+(t.error.reason||t.error.error));for(var n in t)e[n]=t[n];return o(e,r,t)}return o(e,r,t)}"string"==typeof r&&(r={uri:r}),r.json=!0,r.body&&(r.json=r.body),delete r.body,o=o||t;var i=e(r,n);return i},e}); | |
},{}],2:[function(require,module,exports){ | |
var request=require("browser-request");window.require=function(name,moduleName){_require=require,moduleName||(moduleName=name),console.log("Fetching "+moduleName+"... just one second"),request("https://wzrd.in/bundle/"+moduleName+"@latest/",function(er,res,body){require=null,eval(body),window[name]=require(moduleName),require=_require,console.log("Finished getting "+moduleName)})}; | |
},{"browser-request":1}]},{},[2]); | |
(function() { | |
'use strict'; | |
if (typeof window._ === 'undefined') { | |
require('_', 'lodash'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment