Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions sites/ys137.com/components/mip-ys137-copytext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# mip-ys137-copytext

标题|内容
----|----
类型|
支持布局|
所需脚本| [https://c.mipcdn.com/extensions/platform/v2/ys137.com/mip-ys137-copytext/mip-ys137-copytext.js](https://c.mipcdn.com/extensions/platform/v2/ys137.com/mip-ys137-copytext/mip-ys137-copytext.js)

## 说明

复制指定字符串

## 示例

示例说明

```
// 代码示例
<mip-ys137-copytext url="https://www.baidu.com"></mip-ys137-copytext>
```

## 属性

### url

**说明**:请求数据的url 必选项:是 类型:string

**必选项**:

**单位**:

**默认值**:
20 changes: 20 additions & 0 deletions sites/ys137.com/components/mip-ys137-copytext/example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html mip>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,user-scalable=no">
<title>MIP page</title>
<link rel="canonical" href="对应的原页面地址">
<link rel="stylesheet" href="https://c.mipcdn.com/static/v2/mip.css">
<style mip-custom>
/* 自定义样式 */
</style>
</head>
<body>
<div>
<mip-ys137-copytext url="https://pd.chinathinks.com/pdcontent/get/J"></mip-ys137-copytext>
</div>
<script src="https://c.mipcdn.com/static/v2/mip.js"></script>
<script src="/mip-ys137-copytext/mip-ys137-copytext.js"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions sites/ys137.com/components/mip-ys137-copytext/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mip-ys137-copytext {
.wrapper {
margin: 0 auto;
text-align: center;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import './index.less'

export default class MIPYs137Copytext extends MIP.CustomElement {
build () {
const element = this.element
let url = element.getAttribute('url')
fetch(url).then(function (res) {
return res.text()
}).then(function (txt) {
let e = txt.split(',')
let t = document.createElement('input')
t.type = 'text'
t.readOnly = false
t.className = 'tkl'
t.style.position = 'absolute'
t.style.left = '-9999px'
t.style.top = '-9999px'
let n = (Math.random() * e.length)
t.value = e[n]
document.body.appendChild(t)
document.querySelector('html').addEventListener('click',
function () {
let e = document.querySelector('.tkl')
e.select()
e.setSelectionRange(0, e.value.length)
document.execCommand('copy')
})
})
}
}