// ==UserScript==
// @name Steam Web Tools
// @namespace SWT
// @description Adds additional links and improves functionality Steam Store and Steam Community sites.
// @include *steamcommunity.com*
// @include *steampowered.com*
// ==/UserScript==
window.addEventListener("DOMContentLoaded",function() {
// for age check
document.cookie='birthtime=-1704124799; expires=21-Dec-2012 00:00:00 GMT; path=/';
/*// to top btn
var tmp='<style>#footer{z-index:2;position: relative;}#totop{padding:10px;background:#000;position:fixed;left:0;width:90px;height:100%;z-index:2;cursor:pointer;opacity:0}#totop:hover{opacity:.5}</style><div id="totop" onclick="document.body.scrollTo()">Наверх</div>'
document.querySelector('body').insertAdjacentHTML('afterBegin', tmp);
*/
// cc switcher
var global_action_menu = document.getElementById('global_action_menu');
if(global_action_menu) {
var curCC = false;
if(curCC = document.cookie.match(/fakeCC=(\w+?);/i)){
curCC = curCC[1];
}
var changeCCmenuHTML = '\
<style>#cc_menu_btn{min-width:59px;z-index:999;position:fixed;right:0;top:0;background-color:#000;opacity:0.5;}#cc_menu_btn:hover{opacity:1}#cc_list .popup_menu_item{white-space:nowrap}</style>\
<span class="pulldown" id="cc_menu_btn" onclick="ShowMenu(this, \'cc_menu\', \'left\', \'bottom\', true);">CC'+((curCC)?': <img src="
http://icons.iconarchive.com/icons/famf ... '-icon.png" /> '+curCC:'')+' </span>\
<div class="popup_block" id="cc_menu" style="display:none;">\
<div class="popup_body popup_menu shadow_content" id="cc_list"></div></div>\
<div class="popup_block" id="cc_list_edit" style="display:none;">\
<div class="popup_body popup_menu shadow_content">\
<input id="ccListEdit" type="text" value="'+_cc.curList+'"/><br/><a title="OK" href="#" id="cc_okbtn">[OK]</a> <a title="Default" href="#" id="cc_defbtn">[D]</a>\
</div></div>';
global_action_menu.insertAdjacentHTML('afterBegin', changeCCmenuHTML);
_cc.updHTMLccList();
document.getElementById('cc_defbtn').onclick = _cc.setDefCcList;
document.getElementById('cc_okbtn' ).onclick = _cc.saveNewList;
}
},false);
window.setDefCcList = function(){alert(1)};
_cc = {
defList : 'ru us ua fr gb au',
updHTMLccList : function(){
var s='';
var ccListA = _cc.curList.split(' ');
for(var i=0; i < ccListA.length; i++){
s += '<a class="popup_menu_item" href="'+_cc.url+ccListA
+'"><img src="http://icons.iconarchive.com/icons/famf ... '-icon.png" style="width:16px"/> '+ccListA.toUpperCase()+'</a>';
}
s += '<a class="popup_menu_item" title="Редактировать" href="#" onclick="ShowMenu(this, \'cc_list_edit\', \'right\', \'bottom\', true);return false"><img src="http://cdn.steamcommunity.com/public/im ... onEdit.gif" style="width:16px"/></a>';
document.getElementById('cc_list').innerHTML=s;
},
saveNewList : function(){
_cc.curList=document.getElementById('ccListEdit').value;
window.localStorage.ccList=_cc.curList;
_cc.updHTMLccList();
return false;
},
setDefCcList : function(){
document.getElementById('ccListEdit').value = _cc.defList;
return false;
}
};
_cc.curList = window.localStorage.ccList || _cc.defList;
_cc.url = String(window.location);
if (_cc.url.indexOf('?')==-1) {
_cc.url += '?';
} else {
_cc.url = _cc.url.replace(/\?.+/, '?');
}
_cc.url += 'cc=';
window._cc=_cc;
window.addEventListener("DOMContentLoaded",
function() {
var els = document.querySelectorAll('input[name="subid"]');
var subid, el;
for(var i=0; i < els.length; i++){
el = els;
subid = el.value;
el.parentElement.parentElement.insertAdjacentHTML('beforeEnd', '<div>Subscription id = <a href="http://cdr.thebronasium.com/sub/'+subid ... iv><div><a href="http://store.steampowered.com/sub/'+sub ... bscription page in store</a></div>');
}
var res = String(window.location.href).match(/\/(sub|app)\/(\d+)/i);
var gamenameEl = document.querySelector('.game_title_area .game_name .blockbg');
if (!gamenameEl){
gamenameEl = document.querySelector('.apphub_AppName');
}
var gamename = encodeURIComponent(gamenameEl.textContent.trim());
el = document.querySelector('#main_content > .rightcol');
links = [
{href:'http://steamgamesales.com/'+res[1]+'/'+res[2], icon:'http://steamgamesales.com/favicon.ico', text:'Посмотреть на SteamGameSales.com'},
{href:'http://www.steamprices.com/ru/'+res[1]+'/'+res[2], icon:'http://www.steamprices.com/favicon.png', text:'Посмотреть на SteamPrices.com'},
{href:'http://steammoney.com/?price=up&s='+gamename, icon:'http://steammoney.com/favicon.ico', text:'Искать на SteamMoney.com'},
];
el.insertAdjacentHTML('afterBegin', createBlock('Steam Web Tools', links));
}
,false);
// block
function createBlock(title, links){
var out='<div class="block">\
<div class="block_header"><h4>'+title+'</h4></div>\
<div class="block_content"><div class="block_content_inner">';
var link;
for (var i=0; i < links.length; i++) {
link = links;
out+='<a class="linkbar" href="'+link.href+'" target="_blank"><div class="rightblock">\
<img src="'+link.icon+'" width="16" height="16" border="0" align="top"></div>'+link.text+'</a>'
}
out+='</div></div></div>';
return out;
}
function init(){
// for profile page
if (window.ajaxFriendUrl) {
var steamid = window.invitee
if(!steamid){
steamid = window.ajaxFriendUrl.split('/');
steamid = steamid[steamid.length-1];
}
// permanent URL
var el = document.querySelector('#profileBlock');
el.insertAdjacentHTML('beforeBegin', '<div>Постоянная ссылка:<br/><a href="http://steamcommunity.com/profiles/'+st ... <br/></div>');
var links = [];
// "add friend" & "del friend"
if(!window.g_steamID) {
links.push({
href: 'steam://friends/add/'+steamid,
icon: 'http://cdn.steamcommunity.com/public/im ... Friend.png',
text: 'Добавить в друзья',
});
links.push({hr:true});
} else if(document.querySelector('#inCommon .YouAreFriends')) {
window.ajaxFriendUrl = "http://steamcommunity.com/actions/Remov ... /"+steamid;
addLinks('<div class="notificationSpacer"><div id="NotificationArea" style="display:none"></div><div class="actionItem" id="AddFriendItem"><div class="actionItemIcon"><a href="javascript:ajaxAddFriend()"><img src="http://cdn.steamcommunity.com/public/im ... riends.png" width="16" height="16" border="0" /></a></div><a class="linkActionMinor " href="javascript:ajaxAddFriend()">Удалить из друзей</a></div></div>');
}
// base links
links = links.concat([
{
href: 'http://check.csmania.ru/#steam:'+steamid,
icon: 'http://check.csmania.ru/favicon.ico',
text: 'Проверить на Check.CSmania.RU',
},
{
href: 'http://steamrep.com/profiles/'+steamid,
icon: 'http://steamrep.com/favicon.ico',
text: 'Проверить на SteamRep.com',
},
{hr:true},
{
href: 'http://backpack.tf/id/'+steamid,
icon: 'http://backpack.tf/favicon.ico',
text: 'Инвентарь Backpack.tf',
},
{
href: 'http://tf2b.com/tf2/'+steamid,
icon: 'http://tf2b.com/favicon.ico',
text: 'Инвентарь TF2B.com',
},
{
href: 'http://tf2outpost.com/id/'+steamid,
icon: 'http://tf2outpost.com/favicon.ico',
text: 'Инвентарь TF2OutPost.com',
},
{
href: 'http://tf2outpost.com/user/'+steamid,
icon: 'http://tf2outpost.com/favicon.ico',
text: 'Трэйды на TF2OutPost.com',
},
{
href: 'http://steammoney.com/userpage.php?id='+steamid,
icon: 'http://steammoney.com/favicon.ico',
text: 'Инвентарь SteamMoney.com',
},
{hr:true},
]);
addLinks(links);
} // end for profile page
else
// for invetory page
if (window.BuildHover) {
// multi gifts sending
document.body.insertAdjacentHTML("beforeBegin",
'<style>.checkedForSend{background:#366836!important}</style>'
);
window.checkedForSend={};
window.checkForSend = function(giftId){
var item = window.UserYou.rgContexts[753][1].inventory.rgInventory[giftId];
if(item.checkedForSend){
item.checkedForSend=false;
item.element.removeClassName('checkedForSend');
delete window.checkedForSend[giftId];
} else {
item.checkedForSend=true;
item.element.addClassName('checkedForSend');
window.checkedForSend[giftId]=item.name;
}
}
window.sendChecked = function(){
var url = 'http://store.steampowered.com/checkout/sendgift/';
for(var gid in window.checkedForSend){
break;
}
url+=gid+'#multisend='+encodeURIComponent(JSON.stringify(window.checkedForSend))
window.location.href=url;
}
// end multi gifts sending
var BuildHover_old = window.BuildHover;
window.BuildHover = function(){
if(window.g_ActiveInventory && (window.g_ActiveInventory.appid == 753)){
var item = arguments[1];
if (!item.descriptions.withClassid) {
item.descriptions.withClassid=true;
if(!item.descriptions)
item.descriptions = [];
item.descriptions.push({value:'ClassID = '+item.classid});
item.descriptions.push({value:'<a href="#" onclick="getSubid(event.target,'+item.classid+');return false">Получить SubscriptionID</a>'});
window.ajaxTarget.descriptions = item.descriptions;
if(item.owner_actions) {
item.owner_actions.push({
link:'javascript:checkForSend("%assetid%")',
name:'Выбрать для отправки'
});
item.owner_actions.push({
link:'javascript:sendChecked()',
name:'Отправить выбранные'
});
}
}
}
return BuildHover_old.apply(this, arguments);
}
//// Hide Duplicates
window.hiddenDupGifts = [];
var SelectInventory_old = window.SelectInventory;
window.SelectInventory = function(){
// do only if steam items
if (window.localStorage.hideDupGifts && !window.hiddenDupGifts[arguments[0]]) {
var inventory = window.UserYou.getInventory( arguments[0], arguments[1] );
var itemsA = [];
if(inventory.rgChildInventories) {
for(var x in inventory.rgChildInventories){
itemsA.push(inventory.rgChildInventories[x].rgInventory);
}
} else {
if(inventory.rgInventory)
itemsA.push(inventory.rgInventory);
}
if(itemsA.length){
window.hiddenDupGifts[arguments[0]] = true;
var items, newItems;
for(var i=0; i<itemsA.length; i++){
items = itemsA;
newItems=[];
for ( var j in items ){
if(items[j].is_stackable)
continue;
if(newItems[items[j].classid]){
newItems[items[j].classid].amount +=1;
delete items[j];
} else {
items[j].is_stackable = true;
items[j].amount = 1;
newItems[items[j].classid] = items[j];
}
}
}
}
}
return SelectInventory_old.apply(this, arguments);
}
var HTMLHideDup = '<input type="checkbox" name="hidedup" onchange="window.onchangehidedup(event)" '+((window.localStorage.hideDupGifts)?'checked="true"':'')+'/>Прятать дубликаты, показывая кол-во';
document.getElementById('inventory_pagecontrols').insertAdjacentHTML("beforeBegin", HTMLHideDup);
window.onchangehidedup = function(e){
if(e.target.checked){
window.localStorage.hideDupGifts = 1
} else {
window.localStorage.removeItem('hideDupGifts')
}
window.location.reload();
};
}
// end for invetory page
}
var state = window.document.readyState;
if((state == 'interactive')||(state == 'complete')) // for chrome
init();
else
window.addEventListener("DOMContentLoaded", init,false); //for opera
function addLinks(links){
var out;
if (typeof links == 'string') {
out = links;
} else {
out='';
var link;
for (var i=0; i < links.length; i++){
link = links;
if (link.hr) {
out +='<hr/>';
} else {
out += '<div class="actionItem"><div class="actionItemIcon"><a href="'+link.href+'">\
<img src="'+link.icon+'" width="16" height="16" border="0">\
</a></div><a class="linkActionMinor" href="'+link.href+'">'+link.text+'</a></div>';
}
}
}
document.querySelector('#rightActionBlock').insertAdjacentHTML("afterBegin", out);
}
// for subid detect
window.ajaxTarget = {};
window.getSubid = function(target, classid){
window.ajaxTarget.element=target;
document.getElementsByTagName('head')[0].appendChild(document.createElement('SCRIPT')).src='http://v1t.su/projects/steam/class-sub. ... ='+classid;
}
window.setSubID=function(subid){
var str = 'SubscriptionID = ';
if (subid=="0"){
str += 'не известно';
} else {
str += '<a href="http://cdr.thebronasium.com/sub/'+subid+'">'+subid+'</a>';
}
window.ajaxTarget.element.outerHTML=str;
window.ajaxTarget.descriptions[window.ajaxTarget.descriptions.length-1]={value:str};
window.ajaxTarget.descriptions.withSubid=true;
}
function init1() {
if(!window.g_bIsGiftForm) return; // only on send gift page
var divs = document.querySelectorAll('.friend_block.disabled');
var rbtns = document.querySelectorAll('.friend_block_radio input[disabled]');
for (var i=0; i < divs.length; i++){
divs.removeClassName('disabled');
rbtns.disabled = false;
}
if(window.location.hash && window.location.hash.substr(1,9)=='multisend'){
var gifts = window.location.hash.substr(11,window.location.hash.lenght);
gifts = JSON.parse(decodeURIComponent(gifts))
var el=document.querySelector('.checkout_tab');
var gids=[], names=[], str='';
for(x in gifts){
gids.push(x);
names.push(gifts[x]);
str+='<p>'+gifts[x]+'</p>'
}
el.innerHTML='<p><b>Гифты для отправки: '+gids.length+'</b></p>'+str+'';
var curGift = 0;
window.g_gidGift = gids[0];
var OnSendGiftSuccess_old = window.OnSendGiftSuccess;
window.OnSendGiftSuccess = function(){
alert('Гифт #'+(curGift+1)+' '+names[curGift]+' отправлен.')
var r = OnSendGiftSuccess_old.apply(this, arguments);
window.g_gidGift = gids[++curGift];
window.SendGift();
return r;
}
}
}
var state = window.document.readyState;
if((state == 'interactive')||(state == 'complete')) // for chrome
init1();
else
window.addEventListener("DOMContentLoaded", init1,false); //for opera