写一个油猴脚本,功能是在网页中插入一个宽为100,高为100的按钮 按钮绑定一个方法 方法输出123
时间: 2024-02-26 20:54:02 浏览: 23
好的,以下是一个能够在网页中插入一个宽为100,高为100的按钮,并且点击按钮时会输出123的油猴脚本:
```javascript
// ==UserScript==
// @name Add button with function to page
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Add button to page with width 100 and height 100, and bind a function to it that logs '123'
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Create a button element
const button = document.createElement('button');
button.style.width = '100px';
button.style.height = '100px';
button.innerText = 'Click me!';
// Bind a function that logs '123' to the button's click event
button.onclick = function() {
console.log('123');
}
// Append the button to the body of the page
document.body.appendChild(button);
})();
```
你可以将这段代码复制到一个新建的油猴脚本中,然后保存并安装它。在你想要添加按钮的网页中,你应该能够看到一个宽为100,高为100的按钮。当你点击这个按钮时,控制台应该会输出'123'。