// ==UserScript== // @name Groupees Backup // @namespace https://greasyfork.org/users/34380 // @version 20220624 // @description // @match https://groupees.com/purchases // @grant none // @description 备份 Groupees 数据。 // @downloadURL none // ==/UserScript== (function () { 'use strict'; // Your code here... var id, page, generator, all, text; var plats = ["Steam", "Itch.io", "Desura"]; var kws = ["PC", "OS X", "Linux", "Android", "Mp3", "Flac"]; var user_id = document.querySelector('.fayepub').getAttribute('data-user'); function getNextPageBundle() { fetch('https://groupees.com/users/451393/more_entries?page=' + page + '&kind=bundles').then(res => res.json()).then(res => { if (res.length > 0) { generator = getBundleHTML(res); generator.next(); } else { toExcel(); } }) } function* getBundleHTML(bundles) { for (var bundle of bundles) { var bun = JSON.parse(bundle); if (id) { if (id == bun.id) { id = false; } else { console.log(generator.done); } } else { yield fetch('https://groupees.com/orders/' + bun.id + '?user_id=' + user_id).then(res => res.text()).then(res => { // var html = res.match(/(?<=html = )[\s\S]+(?=;[\s\S]+var groupeesRe)/); var html = res.match(/(?<=html = \$\(')[\s\S]+(?='\);[\s\S]+var groupeesRe)/); var div = document.createElement('DIV'); html = html[0].replace(/\\n/g, "").replace(/\\'/g, "'").replace(/\\"/g, '"').replace(/\\\//g, "/"); div.innerHTML = html; var [json, note] = getMainData(div); all.push([bun, json, note]); document.querySelector('#output-textarea').value += '已加载包 id ' + bun.id + ' ' + bun.bundle_name + '\n'; setTimeout(() => { if (generator.next().done == true) { page++; getNextPageBundle(); } }, 3000); }); } } if (id && bundles.length) { page++; getNextPageBundle(); } } function getMainData(div) { var jsons = []; var items = div.querySelectorAll('.product'); var note = div.querySelector('.announcements'); note = note ? note.innerText.replace(/\n/g, ' ') : ''; for (var item of items) { var obj = {}; obj['name'] = item.querySelector('.product-name').innerText; var action = item.querySelector('.product-meta'); if (action) { if (action.querySelector('.icon-givenaway-arrow')) { obj['Steam'] = { "key": "", "status": "Givenaway" }; } else { obj['Steam'] = { "key": "", "status": "Reveal this product" }; } } else { var keys_rows = item.querySelectorAll('.col-sm-6.key'); for (var row of keys_rows) { var type = row.querySelector('strong').innerText; var key = row.querySelector('.form-control.code'); // if (!key) {document.querySelector('.key-meta').innerText;} var value = key.value; var status = key.disabled; if (row.querySelector('.key-meta .green')) { status = 'Givenaway'; } if (obj[type]) { note += type + ' ' + obj['name'] + ': ' + value + ' ' + status + '. '; } if (!plats.includes(type)) { note += type + ' ' + obj['name'] + ': ' + value + ' ' + status + '. '; } obj[type] = { "key": value, "status": status }; } var link_row = item.querySelectorAll('.dropdown-header'); for (var row of link_row) { var type = row.innerText; var link = row.nextElementSibling.children[0].href; if (obj[type]) { note += type + ' ' + obj['name'] + ': ' + link + ' . '; } if (!kws.includes(type)) { note += type + ' ' + obj['name'] + ': ' + link + ' . '; } obj[type] = link; } } jsons.push(obj); } return [jsons, note]; } function toExcel() { text = '包名 价格 日期 名字 Steam 状态 Itch 状态 Desura 状态 PC OS X Linux Android Mp3 Flac\n'; for (var one of all) { var text_bun = one[0].bundle_name + ' ' + one[0].total_amount + ' ' + one[0].completed_at + ' '; for (var item of one[1]) { var text_item = item.name + ' '; for (var plat of plats) { if (item[plat]) { text_item += item[plat].key + ' ' + item[plat].status + ' '; } else { text_item += ' ' + ' '; } } for (var kw of kws) { text_item += (item[kw] || '') + ' '; } text += text_bun + text_item + '\n'; } if (one[2] != '') { text += one[2] + '\n'; } } document.querySelector('#output-textarea').value = text; } document.querySelector('.pre-nav').insertAdjacentHTML('afterend', `