Skip to content

Instantly share code, notes, and snippets.

@Oschangkai
Created January 3, 2022 15:13
Show Gist options
  • Save Oschangkai/2f1c4eb8bd96684267e6ed65e146dfb8 to your computer and use it in GitHub Desktop.
Save Oschangkai/2f1c4eb8bd96684267e6ed65e146dfb8 to your computer and use it in GitHub Desktop.
One click to copy price, time and host level into plain text
// https://www.cocservice.top/update/
var pricePos = 7; // 王 = 7
var timePos = 8; // 王 = 8
var hostLevelPos = 9; // 王 = 9
var table = document.getElementsByClassName('mdui-table mdui-table-hoverable less-padding-table table-text-center update-data')[0];
var head = Array.from(table.children[0].children[0].children);
var data = Array.from(table.children[1].children);
// 價格
var priceText = data.map(val => {
var rawPrice = val.children[pricePos].innerText.trim().replace(' ', '');
if (rawPrice.includes("万")) {
return parseInt(rawPrice.replace("万", "")) * 10000;
}
return parseInt(rawPrice);
}).join('\n');
var priceCopyButton = document.createElement('button');
priceCopyButton.innerHTML = '📋 複製';
priceCopyButton.onclick = function () {
navigator.clipboard.writeText(priceText);
alert('📋 複製價格成功');
};
head[pricePos].appendChild(priceCopyButton);
// 時間
var timeText = data.map(val => {
var rawTime = val.children[timePos].innerText.trim().replace(' ', '');
if (rawTime === '瞬间完成') return '00:00:00.000';
var d = rawTime.split('天');
var h = d.pop();
h = h.split('小时');
var m = h.pop();
m = m.split('分钟');
var s = m.pop();
s = s.split('秒');
var ms = s.pop();
if (parseInt(d[0]) > 0) {
var dd = parseInt(d[0]) + (parseInt(h[0] ?? 0) / 24);
return dd.toFixed(1) + '天';
} else {
return (h[0] ? h[0].padStart(2, '0') : '00') + ':'
+ (m[0] ? m[0].padStart(2, '0') : '00') + ':'
+ (s[0] ? s[0].padStart(2, '0') : '00') + '.000';
}
}).join('\n');
var timeCopyButton = document.createElement('button');
timeCopyButton.innerHTML = '📋 複製';
timeCopyButton.onclick = function () {
navigator.clipboard.writeText(timeText);
alert('📋 複製時間成功');
};
head[timePos].appendChild(timeCopyButton);
// 大本營等級
var hostLevelText = data.map(val => {
var rawHostLevel = val.children[hostLevelPos].innerText.trim().replace(' ', '');
return parseInt(rawHostLevel);
}).join('\n');
var hostLevelCopyButton = document.createElement('button');
hostLevelCopyButton.innerHTML = '📋 複製';
hostLevelCopyButton.onclick = function () {
navigator.clipboard.writeText(hostLevelText);
alert('📋 複製大本營等級成功');
};
head[hostLevelPos].appendChild(hostLevelCopyButton);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment