我制作了一个 firefox 扩展来获取所有请求 url 并显示它们。但只有当我将代码粘贴到控制台中时,该代码才有效。
当扩展加载时,它没有显示任何错误,看起来它只是无法运行
这是完整的代码
xhrScript.js
(function(){
const proxiedOpen = XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function ( _, url) {
this.__URL = url;
return proxiedOpen.apply(this, arguments);
};
const proxiedSend = window.XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.send = function () {
const { protocol, host } = window.location;
// showing only when it paste in console
console.log("full request url ", `${protocol}//${host}${this.__URL}`);
return proxiedSend.apply(this, [].slice.call(arguments));
};
})();
// this works all times
document.body.style.border = "7px solid blue";
Run Code Online (Sandbox Code Playgroud)
清单.json
{
"manifest_version": 2,
"name": "XHR request urls",
"version": …
Run Code Online (Sandbox Code Playgroud) javascript firefox xmlhttprequest firefox-addon firefox-addon-webextensions
在fabricjs中,画布中的所有对象都有自己的顶部和左侧属性,但是当我进行选择(使用shift+单击或拖动)时,选择范围内所有对象的顶部和左侧值都会丢失其原始值。
有一个简单的代码片段解释了我的问题https://jsfiddle.net/kj7qy6a8/
我想知道或计算选择范围内所有对象的实际顶部和左侧,而不是相对值。
如果您想直接在这里尝试,我会将代码粘贴到此处。
const canvasElmt = document.getElementById('myCanvas');
const canvas = new fabric.Canvas(canvasElmt, {
width: 500,
height: 500
});
let text1 = new fabric.Textbox('text1', { top: 20, left: 40 });
let text2 = new fabric.Textbox('text2', { top: 100, left: 60 });
canvas.add(text1);
canvas.add(text2);
canvas.renderAll();
// button onclick
document.getElementById('btn').onclick = () => {
const infoElmt = document.getElementById('info');
infoElmt.textContent = '';
canvas.getObjects().forEach(({text, top, left}) => {
infoElmt.innerText += `${text} TOP: ${top} LEFT: ${left}\n`;
});
}
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html lang="en">
<head>
<meta …
Run Code Online (Sandbox Code Playgroud)javascript ×2
canvas ×1
coordinates ×1
fabricjs ×1
firefox ×1
firefox-addon-webextensions ×1
selection ×1