| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- function getDaysAgo(n) {
- const timestamp = Date.now() - (n * 24 * 60 * 60 * 1000);
- const date = new Date(timestamp);
-
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const day = String(date.getDate()).padStart(2, '0');
-
- return `${year}-${month}-${day}`;
- }
- function csvToArray(csvString) {
- const lines = csvString.split('\n');
- const result = [];
-
- for (let line of lines) {
- // 跳过空行
- if (line.trim() === '') continue;
-
- // 按逗号分割,并去除每个字段的空白
- const row = line.split(',').map(field => field.trim());
- result.push(row);
- }
-
- return result;
- }
- function arrayToCSV(array) {
- return array.map(row =>
- row.map(field => String(field)).join(',')
- ).join('\n');
- }
- function creatToday(fileList) {
- for (let index = 1; index < fileList.length - 1; index++) {
- fileList[index][2] = fileList[index][5]
- fileList[index][3] = fileList[index][6]
- fileList[index][4] = fileList[index][7]
- fileList[index][5] = ""
- fileList[index][6] = ""
- fileList[index][7] = ""
- fileList[index][8] = ""
- fileList[index][9] = ""
- fileList[index][10] = ""
- }
- const fileData = {
- filename: getDaysAgo(0) + '.csv',
- content: arrayToCSV(fileList),
- encoding: "gb2312"
- };
- // 调用保存方法
- window.electronAPI.saveFile(fileData).then(result => {
- if (result.success) {
- console.log('文件保存成功:', result.path);
- } else {
- console.error('文件保存失败:', result.error);
- }
- });
- }
- function saveFile(adtaArr, next) {
- // 保存数据
- const fileData = {
- filename: getDaysAgo(0) + '.csv',
- content: arrayToCSV(adtaArr),
- encoding: "gb2312"
- };
- // 调用保存方法
- window.electronAPI.saveFile(fileData).then(result => {
- if (result.success) {
- console.log('文件保存成功:', result.path);
- setTimeout(() => {
- if (next) checkData(adtaArr, next)
- }, 1000);
- } else {
- console.error('文件保存失败:', result.error);
- }
- });
- }
- function cutString (original, before, after, index) {
- index = index || 0;
- if (typeof index === "number") {
- const P = original.indexOf(before, index);
- if (P > -1) {
- if (after) {
- const f = original.indexOf(after, P + before.length);
- return (f>-1)? original.slice(P + before.toString().length, f):console.error("Tool [在文本中找不到 参数三 "+after+"]");
- } else {
- return original.slice(P + before.toString().length);
- }
- } else {
- console.error("Tool [在文本中找不到 参数一 " + before + "]");
- return
- }
- } else {
- console.error("Tool [sizeTransition:" + index + "不是一个整数!]");
- }
- }
- function checkText () {
- if (window.noRun) return
- if (document.querySelector('.style-scope.ytd-about-channel-renderer') || document.querySelector('ytm-about-channel-renderer').innerText) {
- window.noRun = true
- let pdInfo = document.querySelector('.style-scope.ytd-about-channel-renderer').innerText
- if (!pdInfo) {
- pdInfo = document.querySelector('ytm-about-channel-renderer').innerText
- }
- let bfsl = parseInt(cutString(pdInfo,'视频\n\n\t', '次观看'))
- let spsl = parseInt(cutString(pdInfo,'订阅者\n\n\t', '个视频'))
- let dyrs = parseInt(cutString(pdInfo,'注册\n\n\t', '位订阅者'))
- if (!spsl) {
- spsl = parseInt(cutString(pdInfo,'注册\n', '个视频'))
- }
- bfsl = bfsl ? bfsl : 0
- spsl = spsl ? spsl : 0
- dyrs = dyrs ? dyrs : 0
- console.log(bfsl, spsl, dyrs)
- adtaArr[index][5] = bfsl
- adtaArr[index][6] = spsl
- adtaArr[index][7] = dyrs
- adtaArr[index][8] = bfsl - parseInt(adtaArr[index][2])
- adtaArr[index][9] = spsl - parseInt(adtaArr[index][3])
- adtaArr[index][10] = dyrs - parseInt(adtaArr[index][4])
- saveFile(adtaArr, true)
- }
- }
- function checkData (adtaArr) {
- for (let index = 0; index < adtaArr.length; index++) {
- const element = adtaArr[index];
- console.log(element)
- if (element[1].includes('https://') && element[5] === '') {
- console.log(element[1])
- if (location.href.slice(0, 40) == element[1].slice(0, 40)) {
- setTimeout(() => {
- document.querySelector('.yt-truncated-text__absolute-button').click()
- setTimeout(() => {
- checkText()
- }, 3000);
- setTimeout(() => {
- checkText()
- }, 8000);
- setTimeout(() => {
- location.reload()
- }, 14000);
- }, 2000);
- } else {
- location.href = element[1]
- }
-
- return
- }
- }
- // 汇总计算
- adtaArr[adtaArr.length - 1][2] = 0
- adtaArr[adtaArr.length - 1][3] = 0
- adtaArr[adtaArr.length - 1][4] = 0
- adtaArr[adtaArr.length - 1][5] = 0
- adtaArr[adtaArr.length - 1][6] = 0
- adtaArr[adtaArr.length - 1][7] = 0
- adtaArr[adtaArr.length - 1][8] = 0
- adtaArr[adtaArr.length - 1][9] = 0
- adtaArr[adtaArr.length - 1][10] = 0
- for (let index = 1; index < adtaArr.length - 1; index++) {
- const element = adtaArr[index];
- adtaArr[adtaArr.length - 1][2] += parseInt(element[2])
- adtaArr[adtaArr.length - 1][3] += parseInt(element[3])
- adtaArr[adtaArr.length - 1][4] += parseInt(element[4])
- adtaArr[adtaArr.length - 1][5] += parseInt(element[5])
- adtaArr[adtaArr.length - 1][6] += parseInt(element[6])
- adtaArr[adtaArr.length - 1][7] += parseInt(element[7])
- adtaArr[adtaArr.length - 1][8] += parseInt(element[8])
- adtaArr[adtaArr.length - 1][9] += parseInt(element[9])
- adtaArr[adtaArr.length - 1][10] += parseInt(element[10])
- }
- saveFile(adtaArr, false)
- alert('所有项目已经检查完!')
- }
- // 调用保存方法
- window.electronAPI.readFile({filename: getDaysAgo(0) + '.csv', encoding: "gb2312"}).then(result => {
- if (result.success) {
- console.log(result.content);
- // 如果内容是空的,则读取昨天的
- if (result.content == '') {
- window.electronAPI.readFile({filename: getDaysAgo(1) + '.csv', encoding: "gb2312"}).then(result2 => {
- if (result2.success) {
- console.log(result2.content);
- // 如果内容是空的,则读取昨天的
- if (result2.content == '') {
- alert('缺少昨天的数据!')
- } else {
- let fileData = csvToArray(result2.content)
- creatToday(fileData)
- console.log(fileData)
- checkData(fileData)
- }
- } else {
- console.error('文件读取失败:', result2.error);
- }
- });
- } else {
- // 读取加载文件
- let fileData = csvToArray(result.content)
- console.log(fileData)
- checkData(fileData)
- }
- } else {
- console.error('文件读取失败:', result.error);
- }
- });
|