[JavaScript] 纯文本查看 复制代码
(function() {
'use strict';
let toDataURL = window.HTMLCanvasElement.prototype.toDataURL;
window.HTMLCanvasElement.prototype.toDataURL = function(type, encoderOptions) {
//return toDataURL.call(this, type, encoderOptions);
return 'data:image/png;base64,' + random_str(1024)
}
let create_element = document.createElement.bind(document);
document.createElement = function (_element) {
//console.log("create_element:",_element);
if (_element === "canvas") {
var tmp = create_element(_element);
tmp.getContext = function(arg){
return new function CanvasRenderingContext2D() {
this.canvas = create_element("canvas"),
this.direction = "ltr",
this.fillStyle = "#000000",
this.filter = "none",
this.font = "10px sans-serif",
this.fontKerning = "auto",
this.fontStretch = "normal",
this.fontVariantCaps = "normal",
this.globalAlpha = 1,
this.globalCompositeOperation = "source-over",
this.imageSmoothingEnabled = true,
this.imageSmoothingQuality = "low",
this.letterSpacing = "0px",
this.lineCap = "butt",
this.lineDashOffset = 0,
this.lineJoin = "miter",
this.lineWidth = 1,
this.miterLimit = 10,
this.shadowBlur = 0,
this.shadowColor = "rgba(0, 0, 0, 0)",
this.shadowOffsetX = 0,
this.shadowOffsetY = 0,
this.strokeStyle = "#000000",
this.textAlign = "start",
this.textBaseline = "alphabetic",
this.textRendering = "auto",
this.wordSpacing = "0px",
this.stroke = function stroke() {},
this.arc = function arc() {},
this.fillRect = function fillRect() {},
this.fillText = function fillText() {},
this.toDataURL = function toDataURL() {},
this.createBuffer = function createBuffer() {
return {
itemSize : 0,
numItems : 0
}
},
this.bindBuffer = function bindBuffer() {},
this.bufferData = function bufferData() {},
this.createProgram = function createProgram() {
return {
vertexPosAttrib : 0,
offsetUniform : new function WebGLUniformLocation(){}
}
},
this.createShader = function createShader() {},
this.shaderSource = function shaderSource() {},
this.compileShader = function compileShader() {},
this.attachShader = function attachShader() {},
this.linkProgram = function linkProgram() {},
this.useProgram = function useProgram() {},
this.getAttribLocation = function getAttribLocation() {return 0;}
this.getUniformLocation = function getUniformLocation() {return new function WebGLUniformLocation(){};},
this.enableVertexAttribArray = function enableVertexAttribArray() {},
this.vertexAttribPointer = function vertexAttribPointer() {},
this.uniform2f = function uniform2f() {},
this.drawArrays = function drawArrays() {},
this.getSupportedExtensions = function getSupportedExtensions() {return [];},
this.getParameter = function getParameter() {return new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);},
this.clearColor = function clearColor() {},
this.enable = function enable() {},
this.depthFunc = function depthFunc() {},
this.clear = function clear() {},
this.getContextAttributes = function getContextAttributes() {return true;},
this.getExtension = function getExtension() {}
}
}
return tmp;
}
return create_element(_element);
}
})();