// ==UserScript==
// @name AuTo Redeemer Steamkey(自动激活Steamkey)
// @namespace HCLonely
// @description 复制网页中的Steamkey后自动打开激活页面并激活
// @include *://*/*
// @version 2.2.4
// @grant none
// @run-at document-end
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
var url = window.location.href;
//选中激活功能
var iconSize = 24;
var translationTestSize = 16;
var icon = document.createElement('div');
var style = '' +
'width:16px;' +
'height:16px;' +
'margin:0px!important;' +
'';
icon.innerHTML = '' +
'' +
'激活' +
'';
icon.setAttribute('style', '' +
'width:48px!important;' +
'height:18px!important;' +
'display:none!important;' +
'background:#66ccff!important;' +
'border-radius:2px!important;' +
'box-shadow:4px 4px 8px #888!important;' +
'position:absolute!important;' +
'z-index:2147483647!important;' +
'cursor:pointer;'+
'');
// 添加激活图标到 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", function () {
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;
}
var text = window.getSelection().toString().trim();
var 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 + 'px';
icon.style.display = 'block';
} else if (!text) {
icon.style.display = 'none';
}
});
// 激活图标点击事件
icon.addEventListener('click', function (e) {
var productKey = window.getSelection().toString().trim() || e.target.value;
productKey=productKey.replace(/\r\n/g,",");
productKey=productKey.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)){//非激活页面
var activateProduct = function(e) {
var productKey = window.getSelection().toString().trim() || e.target.value;
if (/^([\w\W]*)?([\d\w]{5}(\-[\d\w]{5}){2}(\r||,||,)?){1,}/.test(productKey)) {
if (confirm("检测到神秘key,是否进入steam激活页面并激活?")) {
var productKey1=productKey.replace(/\r\n/g,",");
var productKey2=productKey1.replace(/\n/g,",");
window.open("https://store.steampowered.com/account/registerkey?key=" + productKey2, "_blank");
}
}
};
window.addEventListener("copy", activateProduct, false);
}
//激活页面自动激活
if (/^https?:\/\/store\.steampowered\.com\/account\/registerkey*/.test(url)){
var autoDivideNum = 9;
var waitingSeconds = 20;
var ajaxTimeout = 15;
var keyCount = 0;
var recvCount = 0;
var timer;
var allUnusedKeys = [];
var failureDetail = {
14: '无效激活码',
15: '重复激活',
53: '次数上限',
13: '地区限制',
9: '已拥有',
24: '缺少主游戏',
36: '需要PS3?',
50: '这是充值码',
};
var myTexts = {
fail: '失败',
success: '成功',
network: '网络错误或超时',
line: '——',
nothing: '',
others: '其他错误',
unknown: '未知错误',
redeeming: '激活中',
waiting: '等待中',
showUnusedKey: '显示未使用的Key',
hideUnusedKey: '隐藏未使用的Key',
};
var 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();
}
},
complete: function() {
},
error: function() {
tableUpdateKey(key, myTexts.fail, myTexts.network, 0, myTexts.nothing);
return;
},
success: function(data) {
//console.log(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)) {
allUnusedKeys = allUnusedKeys.filter(function(keyItem){
return keyItem != key;
});
var listObjects = jQuery('li');
for(var i = 0; i < listObjects.length; i++) {
var listElement = listObjects[i];
var listObject = jQuery(listElement);
if(listElement.innerHTML.includes(key)) {
listObject.remove();
}
}
} else if (!success && !allUnusedKeys.includes(key) &&
unusedKeyReasons.includes(reason)) {
var listObject = jQuery('
' + subId + '
' + subName) : '') +
' )');
jQuery('#unusedKeys').append(listObject);
allUnusedKeys.push(key);
}
}
function tableInsertKey(key) {
keyCount++;
var row = jQuery('' + key + '
' + key + '
' + subId + '
' + subName + '