Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greasyfork.org/scripts/464425/1178359/MyContextMenu.js
原生js右键弹出菜单
修改自:https://github.com/electerious/basicContext/
在线预览:
https://jsrun.net/k5dKp/embedded/all/light
截图:
![](https://greasyfork.org/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBOUtnQVE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--09a86771ea7ed1b7a96fe03f6215637b62d041f5/8888.png?locale=zh-CN)
使用示例:
const clicked = function(e) {
console.log(e.target.innerHTML);
}
document.querySelector('.my-context-menu-btn').addEventListener('contextmenu', function(e){
const items = [
{ title: '新标签打开链接', extAttr: "data-name='new-blank'", fn: clicked },
{ },
{ title: '复制链接地址', extAttr: "data-name='copy-link'", fn: clicked },
{ title: '复制选中的文本', extAttr: "data-name='copy-text'", fn: clicked, disabled: true },
{ title: '复制响应数据', extAttr: "data-name='copy-response'", fn: clicked},
{ },
{ title: '复制为cURL格式', extAttr: "data-name='copy-curl'", fn: clicked},
{ title: '复制为fetch格式', extAttr: "data-name='copy-fetch'", fn: clicked},
{ title: '复制为await格式', extAttr: "data-name='copy-await'", fn: clicked},
{ title: '复制为xhr格式', extAttr: "data-name='copy-xhr'", fn: clicked},
{ title: '复制为分享链接', extAttr: "data-name='copy-share'", fn: clicked},
{ },
{ title: '删除该请求', extAttr: "data-name='del-request'", fn: clicked},
{ title: '删除所有请求', extAttr: "data-name='del-all-request'", fn: clicked }
]
basicContext.show(items, e);
});