// ==UserScript==
// @name AuTo Redeemer Steamkey(自动激活Steamkey)
// @namespace HCLonely
// @author HCLonely
// @description 复制网页中的Steamkey后自动打开激活页面并激活
// @include *://*/*
// @version 2.3.4
// @grant GM_setClipboard
// @grant GM_addStyle
// @run-at document-end
// @require https://greasyfork.org/scripts/376437-hclonely-function/code/HCLonely_function.js?version=660229
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
try{
let url = window.location.href;
//选中激活功能
const iconSize = 24;
const translationTestSize = 16;
let icon = document.createElement('div');
const style = '' +
'width:32px;' +
'height:32px;' +
'margin:0px!important;' +
'';
icon.innerHTML = '' +
''
'';
icon.setAttribute('style', '' +
'width:32px!important;' +
'height:32px!important;' +
'display:none!important;' +
'background:#fff!important;' +
'border-radius:16px!important;' +
'box-shadow:4px 4px 8px #888!important;' +
'position:absolute!important;' +
'z-index:2147483647!important;' +
'cursor:pointer;'+
'');
icon.setAttribute("title","激活");
// 添加激活图标到 DOM
document.documentElement.appendChild(icon);
// 鼠标事件:防止选中的文本消失
document.addEventListener('mousedown', function (e) {
if (e.target == icon || (e.target.parentNode && e.target.parentNode == icon) || (e.target.parentNode.parentNode && e.target.parentNode.parentNode == icon)) {// 点击了激活图标
e.preventDefault();
}
});
// 选中变化事件:当点击已经选中的文本的时候,隐藏激活图标和激活面板(此时浏览器动作是:选中的文本已经取消选中了)
document.addEventListener("selectionchange", ()=> {
if (!window.getSelection().toString().trim()) {
icon.style.display = 'none';
}
});
// 鼠标事件:防止选中的文本消失;显示、隐藏激活图标
document.addEventListener('mouseup', function (e) {
if (e.target == icon || (e.target.parentNode && e.target.parentNode == icon) || (e.target.parentNode.parentNode && e.target.parentNode.parentNode == icon)) {// 点击了激活图标
e.preventDefault();
return;
}
let text = window.getSelection().toString().trim();
let productKey = window.getSelection().toString().trim() || e.target.value;
if (/^([\w\W]*)?([\d\w]{5}(\-[\d\w]{5}){2}(\r||,||,)?){1,}/.test(productKey) && text && icon.style.display == 'none') {
icon.style.top = e.pageY + 12 + 'px';
icon.style.left = e.pageX + 18 + 'px';
icon.style.display = 'block';
} else if (!text) {
icon.style.display = 'none';
}
});
// 激活图标点击事件
icon.addEventListener('click', function (e) {
let productKey = window.getSelection().toString().trim() || e.target.value;
productKey=productKey.replace(/\r\n/g,",").replace(/\n/g,",");
window.open("https://store.steampowered.com/account/registerkey?key=" + productKey, "_blank");
});
//复制激活功能
if (!/https?:\/\/store\.steampowered\.com\/account\/registerkey[\w\W]{0,}/.test(url)){//非激活页面
let activateProduct = function(e) {
let productKey = window.getSelection().toString().trim() || e.target.value;
if (/^([\w\W]*)?([\d\w]{5}(\-[\d\w]{5}){2}(\r||,||,)?){1,}/.test(productKey)&&(confirm("检测到神秘key,是否进入steam激活页面并激活?"))) {
productKey=productKey.replace(/\r\n/g,",").replace(/\n/g,",");
window.open("https://store.steampowered.com/account/registerkey?key=" + productKey, "_blank");
}
};
window.addEventListener("copy", activateProduct, false);
}
//激活页面自动激活
if (/^https?:\/\/store\.steampowered\.com\/account\/registerkey*/.test(url)){
const autoDivideNum = 9;
const waitingSeconds = 20;
const ajaxTimeout = 15;
let keyCount = 0;
let recvCount = 0;
let timer;
let allUnusedKeys = [];
const failureDetail = {
14: '无效激活码',
15: '重复激活',
53: '次数上限',
13: '地区限制',
9: '已拥有',
24: '缺少主游戏',
36: '需要PS3?',
50: '这是充值码',
};
const myTexts = {
fail: '失败',
success: '成功',
network: '网络错误或超时',
line: '——',
nothing: '',
others: '其他错误',
unknown: '未知错误',
redeeming: '激活中',
waiting: '等待中',
showUnusedKey: '显示未使用的Key',
hideUnusedKey: '隐藏未使用的Key',
};
const unusedKeyReasons = [
'次数上限',
'地区限制',
'已拥有',
'缺少主游戏',
'其他错误',
'未知错误',
'网络错误或超时',
];
function redeemKey(key) {
jQuery.ajax({
url: 'https://store.steampowered.com/account/ajaxregisterkey/',
data: {
product_key: key,
sessionid: g_sessionID
},
type: 'post',
dataType: 'json',
timeout: 1000 * ajaxTimeout,
beforeSend: function(){
if (jQuery('table').is(':hidden')) {
jQuery('table').fadeIn();
}
},
error: function() {
tableUpdateKey(key, myTexts.fail, myTexts.network, 0, myTexts.nothing);
return;
},
success: function(data) {
if (data.success == 1) {
tableUpdateKey(key, myTexts.success, myTexts.line,
data.purchase_receipt_info.line_items[0].packageid,
data.purchase_receipt_info.line_items[0].line_item_description);
return;
} else if (data.purchase_result_details !== undefined && data.purchase_receipt_info) {
if (!data.purchase_receipt_info.line_items[0]) {
tableUpdateKey(key, myTexts.fail,
failureDetail[data.purchase_result_details] ? failureDetail[data.purchase_result_details] : myTexts.others,
0, myTexts.nothing);
} else {
tableUpdateKey(key, myTexts.fail,
failureDetail[data.purchase_result_details] ? failureDetail[data.purchase_result_details] : myTexts.others,
data.purchase_receipt_info.line_items[0].packageid,
data.purchase_receipt_info.line_items[0].line_item_description);
}
return;
}
tableUpdateKey(key, myTexts.fail, myTexts.nothing, 0, myTexts.nothing);
}
});
}
function setUnusedKeys(key, success, reason, subId, subName) {
if (success && allUnusedKeys.includes(key)) {
var listObject;
allUnusedKeys = allUnusedKeys.filter(function(keyItem){
return keyItem != key;
});
jQuery('li').map((i,e)=>{
if(jQuery(e).innerHTML.includes(key)) {
listObject.remove();
}
});
} else if (!success && !allUnusedKeys.includes(key) && unusedKeyReasons.includes(reason)) {
listObject = jQuery('
' + subId + '
' + subName) : '') +
' )');
jQuery('#unusedKeys').append(listObject);
allUnusedKeys.push(key);
}
}
function tableInsertKey(key) {
keyCount++;
let row = jQuery('' + key + '
' + key + '
' + subId + '
' + subName + '