123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- function sleep(time) {
- return new Promise((resolve) => setTimeout(resolve, time));
- }
- async function getDom(sel) {
- for (let i = 0; i < 100; i++) {
- let dom = document.querySelector(sel);
- console.log(dom);
- if (dom) {
- return dom;
- } else {
- await sleep(100);
- }
- }
- }
- async function getDomAll(sel) {
- for (let i = 0; i < 100; i++) {
- let dom = document.querySelectorAll(sel);
- console.log(dom);
- if (dom) {
- return dom;
- } else {
- await sleep(100);
- }
- }
- }
- function addNewStyle(newStyle) {
- let styleElement = document.getElementById('styles_js');
- if (!styleElement) {
- styleElement = document.createElement('style');
- styleElement.type = 'text/css';
- styleElement.id = 'styles_js';
- document.getElementsByTagName('head')[0].appendChild(styleElement);
- }
- styleElement.appendChild(document.createTextNode(newStyle));
- }
- //直接读取浏览器url
- function GetQueryString(name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
- var r = location.href.substring(location.href.indexOf('?') + 1).match(reg); //获取url中"?"符后的字符串并正则匹配
- var context = "";
- if (r != null)
- context = r[2];
- reg = null;
- r = null;
- return context == null || context === "" || context === "undefined" ? "" : decodeURI(context);
- }
- function getRandomInt(min, max) {
- min = Math.ceil(min);
- max = Math.floor(max);
- return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
- }
- function myCopy(inner_html) {
- let tmpId = "tmpId123123" + getRandomInt(1, 10000);
- let a = document.createElement('div');
- a.id = tmpId;
- a.innerHTML = inner_html
- document.querySelector('body').appendChild(a)
- let range = document.createRange();
- range.selectNode(document.querySelector("#" + tmpId));
- // 清除选择
- window.getSelection().removeAllRanges();
- window.getSelection().addRange(range);
- console.log('复制成功');
- document.execCommand('copy');
- // 清除选择
- window.getSelection().removeAllRanges();
- document.querySelector("#" + tmpId).remove();
- }
- function log(obj) {
- console.table(JSON.parse(JSON.stringify(obj)));
- }
|