Skip to content

Commit

Permalink
fix: 修复新增 shadowroot 后,复制粘贴脚本失效的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed May 16, 2022
1 parent 4e8ea1c commit 081a99e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
9 changes: 0 additions & 9 deletions packages/core/src/assets/less/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,6 @@ panel style
left: -8px;
}

html * {
// 解除复制粘贴
-webkit-user-select: text !important;
-khtml-user-select: text !important;
-moz-user-select: text !important;
-ms-user-select: text !important;
user-select: text !important;
}

.pointer {
cursor: pointer;
}
18 changes: 15 additions & 3 deletions packages/core/src/script/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,31 @@ export const CommonScript = defineScript({
}
},
{
name: '开启页面右键复制粘贴功能',
name: '开启页面复制粘贴功能',
url: supports,
start() {
function enableCopy() {
console.log('开启页面右键复制粘贴功能');
console.log('开启页面复制粘贴功能');
try {
const d = document;
const b = document.body;
d.onselectstart = d.oncopy = d.onpaste = d.onkeydown = d.oncontextmenu = () => true;
b.onselectstart = b.oncopy = b.onpaste = b.onkeydown = b.oncontextmenu = () => true;
} catch (err) {
console.error('页面右键复制粘贴功能开启失败', err);
console.error('页面复制粘贴功能开启失败', err);
}

const style = document.createElement('style');
style.innerHTML = `
html * {
-webkit-user-select: text !important;
-khtml-user-select: text !important;
-moz-user-select: text !important;
-ms-user-select: text !important;
user-select: text !important;
}`;

document.body.appendChild(style);
}
onInteractive(() => enableCopy());
onComplete(() => {
Expand Down

0 comments on commit 081a99e

Please sign in to comment.